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

Blocking & Non-Blocking operations on TWI

Hello,

 

I am using nRF52832, SDK_15.3.0, S132 SoftDevice and Segger for flashing the image. I am using ‘ble_app_blinky’.

I connected my sensor to nRF52832 DK over TWI. When ‘twi_scanner’ example code loaded I received the address of the slave device.

Just to crosscheck I ported ‘twi_scanner’ as is into ‘ble_app_blinky’. Even here it worked fine.

 

1) But later I have gone through ‘twi_senor’ example and changed

From     :  nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);

To          :  nrf_drv_twi_init(&m_twi, &twi_config, twi_handler, NULL);

 When ‘twi_handler’ added, I get success for all 127 address. I am not sure why this happened.

    for (address = 1; address <= TWI_ADDRESSES; address++)
    {
        err_code = nrf_drv_twi_rx(&m_twi, address, &sample_data, sizeof(sample_data));
        if (err_code == NRF_SUCCESS)
        {
            detected_device = true;
            NRF_LOG_INFO("TWI device detected at address 0x%x.", address);
        }
        NRF_LOG_FLUSH();
    }

2) Under ‘nrf_drv_twi_init’ for event handler it is mentioned as “If NULL, blocking mode is enabled”. What does it mean.

Thanks & Regards

Vishnu Beema

Parents
  • beemavishnu said:
    Yes, in ble_app_blinky, I mixed both 'twi_scanner' to read the address and 'twi_sensor' to add twi handler.

     Ok, thanks! 

    beemavishnu said:
    If 'twi_scanner' example is blocking mode, then can I assume 'twi_sensor' as non-blocking mode. But still due to 'while (m_xfer_done == false)' whether 'twi_sensor' code will behave as a blocking mode. Please correct me if I am wrong.

     TWI_sensor is considered as a non-blocking example since it uses a twi_handler, at least the twi driver is configured as non-blocking. However, I agree that the example is confusing when adding the flag m_xfer_done, when polling this flag the example could potentially be blocking.

    Hope this clears some confusion. 

    Kind regards,
    Øyvind

Reply Children
No Data
Related