基于home1.2版本的门锁例程
测试对E2PROM的读操作
初始化如下:
bspI2cInit();
引脚分配为:
/* I2C */
#define Board_I2C0_SDA0 IOID_7
#define Board_I2C0_SCL0 IOID_27
读操作如下,测量没有任何波形,是不是哪里配置不正确?
bspI2cSelect(0,0×50);//7位地址为0x50
sensorReadReg(0, &buf, 1);//读一个字节
bspI2cDeselect();
YiKai Chen:
API 應該是用I2C_open和I2C_transfer,你的bspI2cInit,bspI2cSelect,sensorReadReg,以及bspI2cDeselect是哪來的?
user5367314:
回复 YiKai Chen:
SensorTag里面的
void bspI2cInit(void) {Semaphore_Params semParamsMutex;// Create protection semaphoreSemaphore_Params_init(&semParamsMutex);semParamsMutex.mode = Semaphore_Mode_BINARY;Semaphore_construct(&mutex, 1, &semParamsMutex);// Reset the I2C controllerHapiResetPeripheral(PRCM_PERIPH_I2C0);I2C_init();I2C_Params_init(&i2cParams);i2cParams.bitRate = I2C_100kHz;i2cHandle = I2C_open(Board_I2C, &i2cParams);// Initialise local variablesslaveAddr = 0xFF;interface = BSP_I2C_INTERFACE_0;if (i2cHandle == NULL){Task_exit();} }bool bspI2cWriteRead(uint8_t *wdata, uint8_t wlen, uint8_t *rdata, uint8_t rlen){ I2C_Transaction masterTransaction;
masterTransaction.writeCount = wlen; masterTransaction.writeBuf = wdata; masterTransaction.readCount = rlen; masterTransaction.readBuf = rdata; masterTransaction.slaveAddress = slaveAddr;
return I2C_transfer(i2cHandle, &masterTransaction) == TRUE;}
如果用你说的I2C_open和I2C_transfer,参数怎么写?
YiKai Chen:
回复 user5367314:
你的bspI2cInit和bspI2cWriteRead就有用到I2C_open和I2C_transfer,你應該先檢查看看I2C_open後的i2cHandle是不是NULL
Viki Shi:
有个I2C控制TMP007的例程,可以参考下: dev.ti.com/…/