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

[TIMER] Receive another message when a timer is active.

Hi, I'm HongJae.

I'm developing a Bluetooth peripheral program with nrf52.

Briefly,

if I send a hexadecimal message(e.g 0x35), GPIO's are ON.

After 1 minute from getting the message, GPIO's are OFF. 

To count 1 minute, I've used "nrf_delay_ms" function.

At first it seemed to work well, but it wans't.

Following is my code.

Specifically,

If I send the message (e.g. 0x35),

0x35 case loop is executed. 

However, 0x35 case loop can't be completed, because of "nrf_delay_ms" function.

It can't reach deinit_ble_pwm1() before nrf_delay_ms() is finished 

Therefore, I should wait for 1 min to send another message.

Before using "nrf_delay_ms" function,

I don't have to wait 1 min to send other messages.

I can send messages during GPIO turn on.

Could you let me know that 

how to receive messages when a timer is active?  

Thanks,

Parents
  • Hello,

    To count 1 minute, I've used "nrf_delay_ms" function.

     

    Could you let me know that 

    how to receive messages when a timer is active?  

    I think there might be a misunderstanding here. nrf_delay_ms is not a timer in the normal microcontroller sense. nrf_delay_ms is just wasted NOP CPU cycles, that approximately will take a certain number of ms to complete. Due to this, the CPU is actually in use / active for the entire time of the nrf_delay_ms, it is just that its computations are worthless.

    What you instead would like to do is use the TIMER peripheral, so that you do not have to use active CPU time to measure the passing of time.
    You can read more about the TIMER peripheral in its documentation. I would also highly recommend that you take a look at the TIMER example from the SDK. The TIMER example demonstrates how you could set up a TIMER to trigger every 500 ms, and have that event toggle a LED.
    Using a TIMER instead of nrf_delay_ms will free up your CPU to do other things while waiting for the time to pass.

    Please also keep in mind that the SoftDevice takes priority over any application layer code, so that the Bluetooth Low-Energy connection is maintained, regardless of what your application code is doing. This means that the SoftDevice will take control over the CPU every so often which is needed to fulfill the BLE requirements.

    I am not sure I have understood all that you are asking about in your ticket - in the case that I have not, please let me know what I might have missed, or if anything still should be unclear!

    For the record, when sharing code please use the " Insert - > Code " option as it drastically increases the readability of your code you have shared.

    Best regards,
    Karl

Reply
  • Hello,

    To count 1 minute, I've used "nrf_delay_ms" function.

     

    Could you let me know that 

    how to receive messages when a timer is active?  

    I think there might be a misunderstanding here. nrf_delay_ms is not a timer in the normal microcontroller sense. nrf_delay_ms is just wasted NOP CPU cycles, that approximately will take a certain number of ms to complete. Due to this, the CPU is actually in use / active for the entire time of the nrf_delay_ms, it is just that its computations are worthless.

    What you instead would like to do is use the TIMER peripheral, so that you do not have to use active CPU time to measure the passing of time.
    You can read more about the TIMER peripheral in its documentation. I would also highly recommend that you take a look at the TIMER example from the SDK. The TIMER example demonstrates how you could set up a TIMER to trigger every 500 ms, and have that event toggle a LED.
    Using a TIMER instead of nrf_delay_ms will free up your CPU to do other things while waiting for the time to pass.

    Please also keep in mind that the SoftDevice takes priority over any application layer code, so that the Bluetooth Low-Energy connection is maintained, regardless of what your application code is doing. This means that the SoftDevice will take control over the CPU every so often which is needed to fulfill the BLE requirements.

    I am not sure I have understood all that you are asking about in your ticket - in the case that I have not, please let me know what I might have missed, or if anything still should be unclear!

    For the record, when sharing code please use the " Insert - > Code " option as it drastically increases the readability of your code you have shared.

    Best regards,
    Karl

Children
No Data
Related