Hi,
I have recently inherited a project from a former worker. The code intends to read data from a peripherial through TWI (the peripherial is a Si7053 digital temperature sensors from Silicon Labs).
I am using the dev board PCA10040 v 1.1.1 2017.1. I am compiling the code with gcc and using Eclipse Mars.2 (4.5.2).
I was not getting the expected values form the readings so first I tried the peripherial in a Arduino Board and it works properly (peripherial issue discarded). Then I debbuged the app with gdb and I found the problem:
the nrf_drv_twi_rx (infocenter.nordicsemi.com/index.jsp function is returning a NRF_ERROR_BUSY, so I guess it is not reading properly.
This is the function:
bool twi_read_register (uint8_t * reg, uint8_t * p_data, uint8_t length_reg, uint8_t length_data) {
// Variables
uint32_t err_code;
uint32_t timeout = TWI_TIMEOUT;
// Enable TWI
nrf_drv_twi_enable(&m_twi_instance);
// Transfer the address of the device to read data from it
err_code = nrf_drv_twi_tx(&m_twi_instance, ADDRESS, reg, length_reg, false);
// Check if error in transfer
if(err_code != NRF_SUCCESS) return false;
// Wait until twi_tx done flag change or timeout
while((!twi_tx_done) && --timeout);
if(!timeout) return false;
twi_tx_done = false;
// Receive data from the sensor
err_code = nrf_drv_twi_rx(&m_twi_instance, ADDRESS, p_data, length_data);
// Check if error when receiving
if(err_code != NRF_SUCCESS) return false;
// Wait until twi_rx done flag change or timeout
timeout = TWI_TIMEOUT;
while((!twi_rx_done) && --timeout);
if(!timeout) return false;
twi_rx_done = false;
return true;
}
//ADRESS = 0x40
//reg = 0xE3
//length_reg = 1
//length_data = 2
I am quite lost. Any help would be welcome.