Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
yaga_3967241
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

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? I2C no slave deviceI2C no slave device

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}

 

0 Likes
1 Solution
yaga_3967241
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

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

 

View solution in original post

0 Likes
1 Reply
yaga_3967241
Level 3
Level 3
50 sign-ins 25 sign-ins 10 replies posted

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

 

0 Likes