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

nrf_drv_twi doesnt read multiple bytes in SDK 12.2

I am trying to use the function or any function with my BLE UART application. I have a timer that expires to kickoff reading of some sensors and then when I try to read my sensor it only writes the address and data register then reads the the device address and stops at one byte regardless of what argument I place in length to receive. The even wierder thing is in a stnadalone non softdevice application I test my I2C devices and it reads all 3 data bytes if I place a breakpoint before the read here is my code snippet.

static void read_sensor_data()

	ret_code_t err_code = 0;
	m_xfer_done = false;
	uint8_t m_txbuf = LM75B_REG_TEMP;
	uint8_t m_sample = 0;

	nrf_drv_twi_tx(&m_twi, LM75B_ADDR, &m_txbuf, 1, false);
	while (m_xfer_done == false);

	m_xfer_done = false;
/* Read 1 byte from the specified address - skip 3 bits dedicated for fractional part of temperature. */
ret_code_t err_code = nrf_drv_twi_rx(&m_twi, LM75B_ADDR, &m_sample, 3);
	while (!m_xfer_done);
Parents
  • Hi,

    You need to provide a buffer to the function nrf_drv_twi_rx() for storing the additional bytes. Now you are only providing a single variable. Try this:

    uint8_t m_sample[3];
    nrf_drv_twi_rx(&m_twi, LM75B_ADDR, m_sample, sizeof(m_sample);
    

    Best regards,

    Jørgen

  • Jorgen, I got it work sort of however I still have the same behavior using nrf_drv_twi_xfer, I had to set flags to 0 and so it does a TX followed by RX of 3 bytes, however I cannot get the software to halt for the 3 bytes to finish it only waits fro one byte even though my scope shows the entire transaction as expected. Interesting to note I still need a breakpoint in order to see the full transaction and it NACKs the address on read when it is free running. Can you please help??? I will try different FLAG settings for this function.

Reply
  • Jorgen, I got it work sort of however I still have the same behavior using nrf_drv_twi_xfer, I had to set flags to 0 and so it does a TX followed by RX of 3 bytes, however I cannot get the software to halt for the 3 bytes to finish it only waits fro one byte even though my scope shows the entire transaction as expected. Interesting to note I still need a breakpoint in order to see the full transaction and it NACKs the address on read when it is free running. Can you please help??? I will try different FLAG settings for this function.

Children
No Data
Related