Failed to send data via SPI in PWM interrupt.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Translation_Bot
Community Manager
Community Manager
Community Manager

Hello: Recently, during motor development, I used SPI to control the MOS driver and turn the motor on and off. The following problems occur when sending data via SPI in PWM interrupt. 1. Using Cy_SCB_SPI_Transfer function to send, query the send status, the bit is always in the state of sending, resulting in the program has been stopped here, not in the interrupt to send can be sent to complete.2. Using Cy_SCB_SPI_WriteArray function can finish sending in PWM interrupt, but can't read the data received by SPI synchronously.Thanks. 2923328@qq.com Mr Wild 24.04.03

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/TRAVEO-T2G/%E5%9C%A8PWM%E4%B8%AD%E6%96%AD%E4%B8%AD%E9%80%9A%E8%BF%87SPI%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5/td-p/727702

0 Likes
3 Replies
Translation_Bot
Community Manager
Community Manager
Community Manager

Hi yeqingchi.

1. Cy_SCB_SPI_Transfer sends data by interrupting the txbuffer/rxbuffer interrupt, which may cause the SPI interrupt to be in the pending state in the PWM interrupt, so you can try to change the SPI interrupt priority to a higher one for testing.

2. Cy_SCB_SPI_WriteArray is to send data directly by writing into the FIFO, if you want to receive you need to call Cy_SCB_SPI_ReadArray.

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/TRAVEO-T2G/%E5%9C%A8PWM%E4%B8%AD%E6%96%AD%E4%B8%AD%E9%80%9A%E8%BF%87SPI%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5/m-p/727751

0 Likes
Translation_Bot
Community Manager
Community Manager
Community Manager

Hello: It was found that it was outside the interrupt while sending and in the interrupt while sending again. It will appear that it is always in the state of sending. Stopping the outside sending is not a problem. However, the outside is monitoring the status of the MOS driver chip and cannot be canceled yet. Now, the SPI priority has been raised to the highest level. It sends two bytes at a time. How can I solve this?

thank you

 

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/TRAVEO-T2G/%E5%9C%A8PWM%E4%B8%AD%E6%96%AD%E4%B8%AD%E9%80%9A%E8%BF%87SPI%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5/m-p/727853

0 Likes
Translation_Bot
Community Manager
Community Manager
Community Manager

Hello,

Not really understanding your application, is it reading the MOS status via interrupt and then sending it out via SPI? Can you lower the PWM frequency a bit and test it again?

smartconx_target@Q!w2e3r4t5y6u7i8o9p0||/t5/TRAVEO-T2G/%E5%9C%A8PWM%E4%B8%AD%E6%96%AD%E4%B8%AD%E9%80%9A%E8%BF%87SPI%E5%8F%91%E9%80%81%E6%95%B0%E6%8D%AE%E5%A4%B1%E8%B4%A5/m-p/727926

0 Likes