We are using MC60 module, with firmware Revision: MC60CAR01A15 and are using RI (pin no 35) and DCD (pin no 36) I2C pins to connect with MC3479 accelerometer. I2C lines have 4.7kΩ pullup resistors.
const u8 I2CAddress = 0x4C << 1; // I2C address
void init_iic()
{
//IMU Vars
ret = Ql_IIC_Uninit(1);
ret = Ql_IIC_Init(1,PINNAME_RI,PINNAME_DCD,1); //Start I2C Communication
if(ret < 0)
{
APP_DEBUG("\r\n<–Failed !! IIC controller Ql_IIC_Init channel 1 fail ret=%d–>\r\n",ret);
}
APP_DEBUG("\r\n<–IIC controller Ql_IIC_Init ret=%d addr=%x–>\r\n",ret,addr);
ret = Ql_IIC_Config(1,TRUE, I2CAddress , 300); // just for the IIC controller
if(ret < 0)
{
APP_DEBUG("\r\n<--Failed !! IIC controller Ql_IIC_Config channel 1 fail ret=%d-->\r\n",ret);
}
APP_DEBUG("\r\n<--IIC controller Ql_IIC_Config ret=%d-->\r\n",ret);
Ql_Sleep(50);
APP_DEBUG("\r\n<--Before Ql_IIC_Read\r\n");
ret = Ql_IIC_Read(1, I2CAddress , read_buffer, 1); //Read IMU Chip ID
APP_DEBUG("\r\n<--After Ql_IIC_Read\r\n");
APP_DEBUG("\r\n<--IMU ID %x %d read_buffer=%d-->\r\n",ret,ret, read_buffer[0]);
}
The problem is the program does not return after Ql_IIC_Read call, it just hangs there forever and the next line never gets printed.
What could be the reasons and how to identify the rootcause?
Hello, have you confirmed the normal connection between the IIC device and the module?Can use oscilloscope or logic analyzer grab the corresponding data to see.
Thanks for your response, we are able to make the IIC device work. But the problem is the device works for 10-15 seconds after module ON, but then Ql_IIC_Write_Read fail with error QL_RET_ERR_I2CHWFAILED, and after that all the read/write to device fails.
First, please confirm whether the PIN of IIC you use is correct. Then verify that the slave device is properly connected to the module. And whether the device address of the slave device is correct.
If the communication is still not normal after the above confirmation, please use oscilloscope to capture the communication waveform of IIC and confirm that the module will receive ACK response signal from the device after sending data.
I can confirm that IIC PIN, slave address, etc are correct because module is able to send/receive messages from the MC3479 accelerometer, the module is able to poll the sensor values even second for 10-15 seconds, and then suddenly Ql_IIC_Write_Read fail with QL_RET_ERR_I2CHWFAILED error, when module tries to read 6 bytes from register 13-18 one byte at a time, after which no values can be read. What can be the reason for sudden fail with QL_RET_ERR_I2CHWFAILED?
@WizIO The accelerometer is supplied power from VDD_EXT (2.8v) and we are not using any level shifter.