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

nRF52 / having 2 processes: 1 master (based on time) and 1 slave

Hello,

I've a process, let's call it P1, that sends I2C instructions for a LED driver (it's like an infinite loop of  I2C instructions for registers management that have to be done together).

I want to do this P1 for a certain time (like for example 10 minutes). 

What kind of implementation do I need to do for that?    I've tried to used the simple timer but it never reaches its timeout because the CPU is blocked in my P1....

  • Hello,

    What sort of timer did you try to use?

    Have you tried to look into the app_timer module? There is an example in the SDK\examples\timer-project. This should give an interrupt that has a higher priority than your main loop (which I assume that your LED driver is running in?).

    What do you mean with a "process"? Do you use FreeRTOS, or is it running in the main() function of your project?

     

    Please note that with a timeout of 10 minutes, you will probably need to configure your timer prescaler.

     

     

    Best regards,

    Edvin

  • Hi,

    Well I finally managed to acheive my goal using the simple-timer .

    Anyway I think I 'll face this question in the future.  

    By "process" I mean a TASK  as a function which contains an infinite loop (TASK  P2) that has to be stopped by a master function (TASK  P1) upon any kind of event (timeout of a timer for example).  I think it must be done with an interrupt or something alike but I didn't find any examples in the SDK so far.

    John.

  • Hello,

     

    The reason I asked about your process/task is because I was wondering whether it was something that you are calling from your main() function, or if you have a process/task running in a "thread" in e.g. FreeRTOS. The difference being the IRQ level of the call. I will get back to the IRQ levels later.

    There are a few models that you can look into.

    The first one is nrfx_timer.c, which has a simple example found in SDK15.0.0, found in the path: SDK15\examples\peripheral\timer

    You will see that in this project, a timer is set up, and started in the main() function. It has a timeout handler called timer_led_event_handler(...) which will be called upon timeout.

     

    The physical timer that is used in this example is TIMER0. You can see this in sdk_config.h:

    #define TIMER_ENABLED 1

    ...

    #define TIMER0_ENABLED 1.

    What you can also see in this file is the define:

    #define TIMER_DEFAULT_CONFIG_IRQ_PRIORITY 7

    This means that this timer has the lowest priority available above main(). The priorities are described here. So if you are running a task/process or whatever with a higher priority (lower IRQ) than the timeout handler, the timeout handler will not get called until the interrupt with the higher priority is done. If you are running this task/process from main(), then the timeout handler with IRQ = 7 will interrupt the main() function, preform the functions in the interrupt handler, and then return to main().

     

    Please be aware that if you are going to use this timer in a project together with the SoftDevice (for a BLE application), then you must change the timer to use another timer than TIMER0, since this timer is required by the SoftDevice.

     

    The other module you can look into is the app_timer. This is used in most of the examples found in ble_peripheral. It works in a similar way.

     

    Best regards,

    Edvin

Related