cancel
Showing results for 
Search instead for 
Did you mean: 

Problems encountered in the implementation of The PIT interrupt

Bgh.1
Associate II

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

8 REPLIES 8
ODOUV.1
ST Employee

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

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

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

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

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

Do not use 100 Hz (too high)

but only 2 Hz to toggle the LED

0693W00000JOmJPQA1.png

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

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.