Skip to main content
Bgh.1
Associate II
February 2, 2022
Question

Problems encountered in the implementation of The PIT interrupt

  • February 2, 2022
  • 5 replies
  • 1842 views

Hello all

I want to send some SPI command periodically in SPC560p40 Microcontroller, so I am trying to generate a periodic interrupt request using PIT. I take “SPC560Pxx_RLA PIT Test Application for Discovery�? as example and write my code as bellow:

0693W00000JOFsHQAX.jpgAlso you can see my PIT settings below:

0693W00000JOFrsQAH.jpg 

 But I observed that the PIT with lowest timer is triggered only once and is not triggered any more. Also other PIT don’t work.

0693W00000JOFrxQAH.jpgCan you help me to solve this problem?

with regards

Bahareh

    This topic has been closed for replies.

    5 replies

    ODOUV.1
    ST Employee
    February 2, 2022

    Hello,

    you could try to move the SPI management into your main loop; and only keep a synchronisation counter in the interrup:

    global int cnt1 = 0;

    in callback1 cnt1++;

    in main loop: if (cnt>0) {Send SPI message, cnt1--}

    Best Regards,

    -Olivier

    Bgh.1
    Bgh.1Author
    Associate II
    February 3, 2022

    Hi Olivier,

    thank you for your fast response.

    I do your comment as below:

    0693W00000JONDqQAP.jpgbut I observed that the PIT don’t work and don't send any SPI command.

    with regards

    Bahareh

    ODOUV.1
    ST Employee
    February 3, 2022

    Hello Bahareh,

    1)

    I have 2 safety recommendations in your current code:

    a) replace if (counter == 1) by if (counter>0) to be able react if counter is 2 or 3 or more

    b) protect your counter access form interrupt acces in your main loop:

     osalEnterCritical();

     counter--;

     osalExitCritical();

    2) help to debug your issue:

    a) Could you try to toggle a LED in your callback function to check if your PIT is working fine ?

    b) Could you try to send SPI data INCONDITIONNALLY in your main loop to check your SPI is working ?

    Best Regards,

    -Olivier

    Bgh.1
    Bgh.1Author
    Associate II
    February 5, 2022

    I do your recommendation and replace (counter == 1) by (counter>0) also use these codes:

     osalEnterCritical();

     counter--;

     osalExitCritical();

    but the program don't work and don't send any SPI command.

    I also send 1 SPI code UNCONDITIONALLY in main loop,the SPI is working good.

    I attached the program file. can you please check it?

    ODOUV.1
    ST Employee
    February 7, 2022

    Hello,

    >>"I also send 1 SPI code UNCONDITIONALLY in main loop, the SPI is working good."

    Good point.

    Then could you try to toggle a LED in your callback function to check if your PIT is working fine ?

    Best Regards,

    -Olivier

    ODOUV.1
    ST Employee
    February 7, 2022

    Do not use 100 Hz (too high)

    but only 2 Hz to toggle the LED

    0693W00000JOmJPQA1.png

    Bgh.1
    Bgh.1Author
    Associate II
    February 7, 2022

    I send the SPI code(for example 0xBBBB) in main loop and toggle a LED in callback function, when I use them separately, both of them works good.

    But when I send the SPI command(for example 0xCCCC) in PIT callback it just send 1 code at the required time and then the MCU stop!!!

    I check two cases:

    1- use SPI code directly in callback function

    2- use a counter in call back function and use the counter as condition for SPI command.

    but in both cases, after 1 callback function, the LED toggle and SPI command stop working.

    0693W00000JOp3yQAD.jpg0693W00000JOp4DQAT.jpgI also try use 1-4 Hz frequency, there is no change in result!

    I think something is wrong when I use SPI in PIT callback function!

    Giuseppe DI-GIORE
    ST Employee
    February 27, 2022

    Hello,

    spi_lld_send() needs interrupts to complete, then if called from an interrupt routine

    need to do the following:

    • enable nested interrupts
    • configure SPI interrupts with a priority higher than PIT interrupt
    • in the PIT interrupt callback
      • osalExitCritical();
      • send SPI command
      • osalEnterCritical();

    Regards.