- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
We are using UDB I2C master component to talk to some slave devices. I try to create some code that will result in error status when I2C slave device detached.
Below code snippet(I2C_PSOC is the I2C component name), status is always 0 after running line 2, after halt for 1.9 seconds. status is always I2C_PSOC_MSTAT_WR_CMPLT in line 6. I can see from logical analizer that there is no I2C slave response and it does translate to a NAK. the I2C data line stay low after I2C master send the I2C slave address for 1.9 seconds.
Should I expect a I2C_PSOC_MSTAT_ERR_ADDR_NAK for status?
1 int i2c_write(uint8_t address, uint8_t *data, uint8_t size) {
2 uint8 status = I2C_PSOC_MasterWriteBuf(address, data, size, I2C_PSOC_MODE_COMPLETE_XFER);
3 do {
4 status = I2C_PSOC_MasterStatus();
5 } while(!(status & (I2C_PSOC_MSTAT_WR_CMPLT|I2C_PSOC_MSTAT_ERR_MASK)));
6 if(status & I2C_PSOC_MSTAT_ERR_MASK) {
7 return status;
8 }
9 return 0;
10}
Solved! Go to Solution.
- Labels:
-
PSOC5 LP MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Below pseudo code works - it returns error when there is not slave device, returns success when the slave device exists:
do {
status = I2C_PSOC_MasterSendStart(I2C_PSOC_WRITE_XFER_MODE);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
status = I2C_PSOC_MasterWriteByte(message);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
status = I2C_PSOC_MasterWriteByte(data1);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
status = I2C_PSOC_MasterWriteByte(data2);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
} while(0)
status = bus->stop();
return status;
Regards,
Winston
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Below pseudo code works - it returns error when there is not slave device, returns success when the slave device exists:
do {
status = I2C_PSOC_MasterSendStart(I2C_PSOC_WRITE_XFER_MODE);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
status = I2C_PSOC_MasterWriteByte(message);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
status = I2C_PSOC_MasterWriteByte(data1);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
status = I2C_PSOC_MasterWriteByte(data2);
if (status != I2C_PSOC_MSTR_NO_ERROR)
{
// error
break;
}
} while(0)
status = bus->stop();
return status;
Regards,
Winston