I2C drivers seems to be corrupting memory
Posted: Thu Nov 16, 2017 2:08 am
Kind of a strange one that I have been fighting all day. When I perform an operation on bytes read from i2c before shutting i2c down, the bytes get corrupted.
And here is a snippet of code that does NOT work - only difference is the order of operations
Code: Select all
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, i2c_addr << 1 | READ_BIT, ACK_CHECK_EN);
i2c_master_read_byte(cmd, &bytes[0], ACK_VAL);
i2c_master_read_byte(cmd, &bytes[1], NACK_VAL);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
bytes[0] = bytes[0] & mask;
if(low_first) data[0] = bytes[1] << 8 | bytes[0];
else data[0] = bytes[0] << 8 | bytes[1];
Code: Select all
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, i2c_addr << 1 | READ_BIT, ACK_CHECK_EN);
i2c_master_read_byte(cmd, &bytes[0], ACK_VAL);
i2c_master_read_byte(cmd, &bytes[1], NACK_VAL);
bytes[0] = bytes[0] & mask;
if(low_first) data[0] = bytes[1] << 8 | bytes[0];
else data[0] = bytes[0] << 8 | bytes[1];
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);