Skip to content

MCUXpresso I2C: Handle 0 byte write #3502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/i2c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ int i2c_start(i2c_t *obj)

int i2c_stop(i2c_t *obj)
{
obj->next_repeated_start = 0;
if (I2C_MasterStop(i2c_addrs[obj->instance]) != kStatus_Success) {
obj->next_repeated_start = 0;
return 1;
}

Expand Down Expand Up @@ -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_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));
master_xfer.slaveAddress = address >> 1;
master_xfer.direction = kI2C_Write;
Expand Down