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
  • When ‘twi_handler’ added, I get success for all 127 address. I am not sure why this happened.

     What does your twi_handler function look like? 

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

    "Blocking communication means that the MCU stalls until the byte is transferred from the data register. In the code, this is usually implemented as checking of the status bit in the “while” loop. However, this approach might not be applicable for some time-critical applications"

    The TWI Scanner uses blocking mode. To enable non-blocking mode, you can add a twi_handler. 

    Please see the TWI master documentation on basic usage.

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

     What does your twi_handler function look like? 

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

    "Blocking communication means that the MCU stalls until the byte is transferred from the data register. In the code, this is usually implemented as checking of the status bit in the “while” loop. However, this approach might not be applicable for some time-critical applications"

    The TWI Scanner uses blocking mode. To enable non-blocking mode, you can add a twi_handler. 

    Please see the TWI master documentation on basic usage.

Children
No Data
Related