Problems encountered in the implementation of The PIT interrupt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-02 4:16 AM
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:
Also you can see my PIT settings below:
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.
Can you help me to solve this problem?
with regards
Bahareh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-02 5:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-03 1:09 AM
Hi Olivier,
thank you for your fast response.
I do your comment as below:
but I observed that the PIT don’t work and don't send any SPI command.
with regards
Bahareh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-03 1:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-04 9:21 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-06 11:59 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 12:13 AM
Do not use 100 Hz (too high)
but only 2 Hz to toggle the LED
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-07 4:06 AM
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.
I 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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-02-27 2:38 PM
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.
