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

how to read data from slave via TWI

Hi,

I am trying to use GPIOTE_PIN_HANDLER in the master nrf52. What is the correct way to read data from slave?

Slave device is sending data using nrfx_twis_tx_prepare() and in master device, I am trying to receive data like below:

void gpiote_pin_event_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
	if ((pin == INTERRUPT_PIN) && (NRF_GPIOTE_POLARITY_HITOLO)) {

    	uint8_t rx_buf[1];

        err_code = nrfx_twim_rx(&m_twi, ADDR_SLAVE, rx_buf, sizeof(rx_buf));
        APP_ERROR_CHECK(err_code);
    }

I could not receive anything in master as nrfx_twim_rx() does not executes fully.

Is above the correct way to receive data in master device? Or does master first need to transmit buffer to slave and then slave fills that buffer with data?

If any examples exist for this kind of scenario, please provide pointers.

Parents
  • Hi Anisa

    You can see that the TWIS_EVT_READ_REQ and WRITE_REQ functions are called in nrfx_twis.c when the TWI peripheral is idle (NRFX_TWIS_SUBSTATE_IDLE). For more details please check your SDK. in this path ....\modules\nrfx\drivers\src\nrfx_twis.c

    Due to the summer holidays in Norway, our support team is understaffed this week, and delayed replies must be expected. Sorry for the inconvenience!

    Best regards,

    Simon

  • Hi Simon,

    Thanks for the reply. So the state of slave device (nrf52) must be checked with (NRFX_TWIS_SUBSTATE_IDLE, and when state is idle them Master (nrf52) sends the buffer using nrf_drv_twi_tx to slave. Slave fills this buffer with data. Master again reads it via nrf_drv_twi_rx().

    Is above understanding correct? Any code examples on how to communicate between 2 nRF52 devices?

    SDK documentation says:

    Note:Peripherals using EasyDMA (including TWIS) require the transfer buffers to be placed in the Data RAM region. If this condition is not met, this function will fail with the error code NRFX_ERROR_INVALID_ADDR.

    How to put buffer in RAM?

  • Any code examples on how to communicate between 2 nRF52 devices

    Again, as said in your previous thread, the way to approach this is not to try to do both ends at once!

    Start by getting your Master thoroughly working, debugged, and instrumented  with a standard Slave.

    Then you can move onto your own slave.

Reply Children
No Data
Related