I am using TC237 and the board does not provide I2C communication, so I implement it as GPIO. Reads and writes through registers, but no master-slave communication.
According to the I2C communication protocol, the start-stop ACK NACK function code was created. I also create a 1-byte write and read code, and based on it I create code to read and write to the registers of the slave.
I do not know how to upload a picture, but when I check the SDA and SCL with the oscilloscope, when I read it, it seems that there are two bytes to read and the rest is OK. The first byte reads 0x00 and the next byte reads 0xEF.
I2C_Start();
waitTime(1*TimeConst_100us);
I2C_WriteByte((uint8)(Slave_addr|0x01));//LIDAR : 0xC5/BH1750 : 0x27
I2C_ACK();//I2C_GetACK();
I2C_ReadData_H = I2C_ReadByte();
I2C_ACK();
waitTime(1*TimeConst_100us);
I2C_ReadData_L = I2C_ReadByte();
waitTime(1*TimeConst_100us);
if(I2C_NACK() == BUSY)
{
return RESET;
}
I2C_Stop();
return SET;
The result should be received by the internal IC, but it receives a strange value. The suspicious part seems to not receive an ACK from the device after reading the first byte, what should I do?