This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI blocks after send receive sequences

Hello

I am using a custom board, based on nRF52832 CIAAB0. I have also S132 installed, and I am using SDK 13.1.0. TWI pins are P0.16 - SCL & P0.18 - SDA. The code is based on twi_sensor example, and should be able to be integrated with ble_app_uart.

I am trying to configure a MS5837 sensor, and read data from it via TWI. The Arduino Library I am trying to replicate could be found here. As part of the custom driver, I have to go through the following send-receive sequence:

uint8_t buffer[2];

ret_code_t err_code;

// Reset the MS5837, per datasheet

uint8_t data = MS5837_RESET;

m_xfer_done = false;
err_code = nrf_drv_twi_tx(&m_twi, MS5837_ADDR, &data, sizeof(data), false);
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);

// Wait for reset to complete
nrf_delay_ms(10);

for ( uint8_t i = 0 ; i < 8 ; i++ ) {
		
	    data = MS5837_PROM_READ + (i*2);
	    m_xfer_done = false;
	    err_code = nrf_drv_twi_tx(&m_twi, MS5837_ADDR, &data, 1, true);
	    APP_ERROR_CHECK(err_code);
	    while (m_xfer_done == false);

	    m_xfer_done = false;
	    err_code = nrf_drv_twi_rx(&m_twi, MS5837_ADDR, buffer, 2);
	    APP_ERROR_CHECK(err_code);	
	    while (m_xfer_done == false);

	    C[i] = ((buffer[0] << 8) | buffer[1]);
	}

Each and every time, twi gets stuck at the second iteration of the for loop, after receiving data and passing the while loop.

The questions are:

  1. Am I using the wrong approach in receiving the data from the sensor?
  2. Is there any way of using TWI in SDK 13.1.0? I have seen some new functions in TWIM HAL chapter (nordic infocenter) but there's no example on how they could be used. As far as I have researched, nrf_drv_twi_tx / rx are described first in SDK 9.
Related