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

  • Yes I did....That is the weird thing I am trying to explain if I run it in debug mode with a break point in twi_handler it works, however when the software is free running it does the write data transaction and then starts the read transaction however it never completes and is aborted. Maybe the softdevice is causing this? However I have several other sensors which are working fine using same code. I also saw in the datasheet the device stops sending data as soon as no ACK from master was sent so I am assuming thats why it is aborting the operation as opposed to the other devices, although it doesnt even receive one byte when the transaction is aborted it only had wrote the read address to the I2C bus followed by a stop condition

Reply
  • Yes I did....That is the weird thing I am trying to explain if I run it in debug mode with a break point in twi_handler it works, however when the software is free running it does the write data transaction and then starts the read transaction however it never completes and is aborted. Maybe the softdevice is causing this? However I have several other sensors which are working fine using same code. I also saw in the datasheet the device stops sending data as soon as no ACK from master was sent so I am assuming thats why it is aborting the operation as opposed to the other devices, although it doesnt even receive one byte when the transaction is aborted it only had wrote the read address to the I2C bus followed by a stop condition

Children
No Data
Related