Hi,
I am currently working on SoC sensor, which is there is a process for uploading firmware from the controller to a sensor through I2C. So I am creating a function for read_block and write_block. Read block do save data from I2C to a array buffer, and write block write a buffer through I2C.
Below is my code for block read and block write.
/**************************************************************************//**
* @brief Write a Block
*****************************************************************************/
uint8_t i2c_block_write(uint8_t device, uint8_t address, uint8_t length, uint8_t const *data)
{
uint8_t ret;
uint8_t i2c_write_data[length+1];
i2c_write_data[0] = address ;
for (int i = 0; i < length+1; i++) {
i2c_write_data[i + 1] = data[i];
}
ret = nrf_drv_twi_tx(&m_twi, device, i2c_write_data, sizeof(i2c_write_data),false);
while(nrf_drv_twi_is_busy(&m_twi));
return ret;
}
/**************************************************************************//**
* @brief Read a Block
*****************************************************************************/
uint8_t i2c_block_read(uint8_t device, uint8_t address, uint16_t length, uint8_t *data)
{
uint8_t ret;
uint8_t register_address[1];
register_address[0] = address;
nrf_drv_twi_tx(&m_twi, device, register_address, sizeof(register_address),true);
while (m_xfer_done == false);
while(nrf_drv_twi_is_busy(&m_twi));
ret = nrf_drv_twi_rx(&m_twi, device, data, length);
while (m_xfer_done == false);
while(nrf_drv_twi_is_busy(&m_twi));
return ret;
}
When I implement it on main code, I can do Read Block I2C, but I can't do write block, it is stuck on pull-ed condition (in my condition, it is pulled up). But when I debug on it, it does the process, but after checking the signal response, there is no signal even from controller to sensor. Below is picture for logic analyzer and in notepad is a debugging process that I wrote on firmware.
Anybody know why my block write is not working? Thank you.
