Hi Sir,
We are developing a product based on CC2541 with multiple sensor connected over I2C bus(like sensorTag reference design). CC2541 I2C acts as master while sensors acts as I2C slave. The BLE Stack version is BLE-CC254x-1.4.1.43908 and we use the hal_sensor driver code. The issue is one of the peripheral sensor's register read required an I2C RESTART signal but the HalI2CWrite called in HalSensorReadReg generate an I2C stop in the end which totally clear the state of the sensor soc. We have try to comment the I2C_STOP in the end of HalI2CWrite. But this cause the next state(I2C_Start) wrong in HalI2CRead.
Try to make a low level debug, after HalI2CWrite (without I2C_STOP ), I2C (I2CSTAT)is under state 0x28(mstDataAckW) . According to Table 20-3 of CC254X User guide, under 0x28 state, next state can be repeated start. But we send I2C_START can not drive state machine to go to 0x10(mstRepStart) state. It remains under 0x28 state. If we capture the signal on the bus, another slave device address with read flag is sent out instead of start Signal.
So can you help to explain about this ?
Add i2c message format and signal on I2C from logic analyzer:
Above is the required I2C message format for register read according to the device's spec. We can find the I2C RESTART signal is required.
Above is the I2C signal from another cortex-M3 based MCU i2c to read the device. The device slave address is 0x4c and the register address is 0x18 . The result value is 0x71.
Above is the signal with HalSensorReadReg which will generate a STOP after register address ACK and then another START with I2C address for read. The STOP cause the register value to be read out as 0x00.
Above is the signal with HalSensorReadReg but the I2C_Stop() in HalI2CWrite() is disabled . After the register address is acknowledged , The next START is not generated . Instead a slave write address and read address is sent out.