I am using an AE Cloud Kit to communicate to a slave device using the RIIC I2C Framework.
Using a logic analyzer I can confirm that my device address is correct, and the R/W and ACK bit are correct when reading and writing.
The issue is when reading any register from the slave device, all I get is 0xFF's. I have tried different slave devices as well with no luck.
The code where this error happens is below. Some variables are not used as the code is still a rough draft.
ssp_err_t slave_read_current(volatile int current_in_A)
{
ssp_err_t err;
uint8_t rxtx_data[4];
uint32_t result;
uint32_t payload;
//int current_in_A;
uint32_t calculated_crc;
uint32_t read_crc;
volatile int data1;
int16_t receive_buffer[2];
err = g_sf_i2c_current.p_api->lock (g_sf_i2c_current.p_ctrl);
/* Start a current measurement. */
rxtx_data[0] = 0xAE;
err = g_sf_i2c_current.p_api->write(g_sf_i2c_current.p_ctrl, rxtx_data, 1, false, TX_WAIT_FOREVER);
if (SSP_SUCCESS != err)
{
return err;
}
/* Setup the read from address. */
err = g_sf_i2c_current.p_api->read(g_sf_i2c_current.p_ctrl, (uint8_t *)&result, 2, false, TX_WAIT_FOREVER);
if (SSP_SUCCESS != err)
{
return err;
}
tx_thread_sleep(2);
//data1 = (receive_buffer[0]<<8) | receive_buffer[1];
current_in_A = ((result * 0.000305185) * 100);
//p_fcurrent = current_in_A;
g_sf_i2c_current.p_api->unlock (g_sf_i2c_current.p_ctrl);
return SSP_SUCCESS;
}
The data from the register should be stored in &result. Any insight as to why I am only get 0xFF's would be appreciated. Thanks!