0

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?

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Best thing to do is get an USB to i2c evaluation board. It shows up as a tty usb device. Use this first, get your I2C lib working. then do specific devices – Owl Jun 04 '19 at 14:09
  • 3
    If you're bit-banging the I2C comms (which is what I assume you mean by "I implement it as GPIO") then you should show us how you've implemented your `I2C_xxx` functions. – brhans Jun 04 '19 at 14:23
  • usually, when accessing a device via I2C, the command to read a value from the device is Then input the ACK/NAK then if ACK received then output a similar set of data to transfer the actual data via then And since your 'bit banging' the I/O, also need to be appropriately setting/resetting the port used for the clock signal. – user3629249 Jun 04 '19 at 21:22
  • strongly suggest reading the web page: and the resulting documents on I2C like: ` – user3629249 Jun 04 '19 at 21:29

0 Answers0