mirror of https://github.com/ARMmbed/mbed-os.git
MCUXpresso I2C: Handle 0 byte write
Signed-off-by: Mahadevan Mahesh <Mahesh.Mahadevan@nxp.com>pull/3502/head
parent
6e7ee0e51e
commit
1280dfcca5
|
@ -81,8 +81,8 @@ int i2c_start(i2c_t *obj)
|
||||||
|
|
||||||
int i2c_stop(i2c_t *obj)
|
int i2c_stop(i2c_t *obj)
|
||||||
{
|
{
|
||||||
if (I2C_MasterStop(i2c_addrs[obj->instance]) != kStatus_Success) {
|
|
||||||
obj->next_repeated_start = 0;
|
obj->next_repeated_start = 0;
|
||||||
|
if (I2C_MasterStop(i2c_addrs[obj->instance]) != kStatus_Success) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,6 +131,25 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
|
||||||
I2C_Type *base = i2c_addrs[obj->instance];
|
I2C_Type *base = i2c_addrs[obj->instance];
|
||||||
i2c_master_transfer_t master_xfer;
|
i2c_master_transfer_t master_xfer;
|
||||||
|
|
||||||
|
if (length == 0) {
|
||||||
|
if (I2C_MasterStart(base, address >> 1, kI2C_Write) != kStatus_Success) {
|
||||||
|
return I2C_ERROR_NO_SLAVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!(base->S & kI2C_IntPendingFlag)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
base->S = kI2C_IntPendingFlag;
|
||||||
|
|
||||||
|
if (base->S & kI2C_ReceiveNakFlag) {
|
||||||
|
i2c_stop(obj);
|
||||||
|
return I2C_ERROR_NO_SLAVE;
|
||||||
|
} else {
|
||||||
|
i2c_stop(obj);
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memset(&master_xfer, 0, sizeof(master_xfer));
|
memset(&master_xfer, 0, sizeof(master_xfer));
|
||||||
master_xfer.slaveAddress = address >> 1;
|
master_xfer.slaveAddress = address >> 1;
|
||||||
master_xfer.direction = kI2C_Write;
|
master_xfer.direction = kI2C_Write;
|
||||||
|
|
Loading…
Reference in New Issue