Triggering SPI DMA transfer with interrupt

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

cross mob
AlNo_3504021
Level 1
Level 1

Hello,

I'm trying to create an application which starts a SPI DMA transfer of 200 bytes every time there is a positive edge on one of the GPIO pins. Right now, I am polling the pin using CyU3PGpioGetValue and starting the DMA transfer on the positive edge by calling CyU3PSpiSetBlockXfer. However, this does not provide the speed that I need for my application, and the RTOS thread manager interrupting the execution of my application thread occasionally causes the application to miss the edge. I tried configuring a GPIO interrupt handler using the Api provided in cyu3gpio.h, but was unable to get CyU3PSpiSetBlockXfer to run inside of the ISR, as it seems like some API calls cannot be called within an interrupt handler. Is there any way to directly set the DMA controller to read SPI data in on an interrupt, or to allow for running a SPI transfer inside an ISR?

Thank you for any insight.

0 Likes
1 Solution

Hi,

Yes that's correct api has many checks to do before toggling the GPIO pin. These checks took time but they are necessary for correct operation. If you are sure that you are toggling the right GPIO pin then go ahead and use register access.

-Regards

Abhinav

View solution in original post

0 Likes
5 Replies
VlKh_2251656
Level 5
Level 5
10 likes given 5 likes given First like received

Hello.

Use

CyU3PDmaChannelSetWrapUp (&dmaBuffer);

0 Likes
abhinavg_21
Moderator
Moderator
Moderator
50 likes received 25 likes received 10 likes received

Hi,

You can raise an event flag in the GPIO ISR and then poll that event in "for" loop. Most of the firmware examples that comes along with SDK package uses this technique.

Just search for event flags firmware examples.

-Regards

Abhinav

0 Likes

I implemented an event for when the interrupt is triggered per your suggestion, which fixed the issue where I was missing busy pin edges. However it takes approximately 24 microseconds from the GPIO line going high to the SPI starting to clock out data using this methodology (as compared to 8 microseconds by polling), which is unfortunately too slow for my use case (needs to be 10 microseconds or less). Is there any way that you know of to reduce that time delay, or to manually set the ISR for GPIO interrupts, to avoid overhead from using the API calls.

Thanks

0 Likes
AlNo_3504021
Level 1
Level 1

Update: I was able to resolve the issue by polling the GPIO pin directly via register access instead of going through the API.

0 Likes

Hi,

Yes that's correct api has many checks to do before toggling the GPIO pin. These checks took time but they are necessary for correct operation. If you are sure that you are toggling the right GPIO pin then go ahead and use register access.

-Regards

Abhinav

0 Likes