实际使用中,我们对I2C时序要求更高更灵活,需要用到源文件的方式,本文介绍源文件添加方法,我们以6621Cxc的工程为例 1.找到SDK下\lib\keil\cc2 (1)armlink.via (2)armlink_allroles.via (3)armlink_sc.via (4)armlink6.via (5)armlink6_allroles.via (6)armlink6_sc.via 2.找到\hardware\peripheral\i2c.c添加到项目文件中 3.I2C初始化函数接口 pinmux_config(PIN_I2C1_SDA, PINMUX_I2C1_MST_SDA_CFG); pinmux_config(PIN_I2C1_SCL, PINMUX_I2C1_MST_SCK_CFG); pmu_pin_mode_set((1<<PIN_I2C1_SCL)|(1<<PIN_I2C1_SDA), PMU_PIN_MODE_OD);
i2c_open(HS_I2C1,I2C_MODE_MASTER, I2C1_SPEED); 4.写函数接口 ic_addr = 设备地址 Reg_Addr = 寄存器地址 bool I2C1_write_mult(uint8_t ic_addr, uint8_t reg_start,uint8_t * pData, uint8_t len){ uint32_t Reg_Addr = (uint32_t)reg_start; return(i2c_master_write_mem(HS_I2C1, ic_addr/*addr*/, Reg_Addr/*offset*/, 1/*offset_size*/, pData, len, NULL)); } 5.写读函数接口 bool I2C1_read_mult(uint8_t ic_addr, uint8_t reg_start,uint8_t * pData, uint8_t len){ uint32_t Reg_Addr = (uint32_t)reg_start; return(i2c_master_read_mem(HS_I2C1, ic_addr/*addr*/, Reg_Addr/*offset*/, 1/*offset_size*/, pData, len, NULL )); } |