You are here

Using DMA to transfer a Struct variable | Cypress Semiconductor

Using DMA to transfer a Struct variable

Summary: 2 Replies, Latest post by H L on 08 Feb 2012 10:13 PM PST
Verified Answers: 0
Last post
Log in to post new comments.
PDES's picture
10 posts

Hi everyone,

I need to transfer a struct variable composed of two fields (uint8,uint16) towards an SPI interface.

I tried to use a DMA channel and only one TD, configured to transfer 1 byte per burst with increment of the source address.

With this configuration, if I set the struct variable as: (0x0F,0xFFFF) I see on the oscilloscope: 0x0F,0X00FF.

Even using 3 byte per burst the result is the same.

Is it needed to use a dedicate TD for each field of the Struct variable or I need to configure the DMA channel and the TD in a different way ?


Thanks in advance


user_1377889's picture
9301 posts

A struct in C can be seen as a sequence of bytes (uint8). When you handle it just like that and use the sizeof(struct MyStructure) macro to calculate the number of bytes to transfer nothing can go wrong.

The SPI interface may go wrong when you send data faster than they are clocked out of the interface. I do not know how you are checking the FIFO in your DMA-process. I doubt that the supplied interrupt routines wotk together with DMA.

I would suggest to set the TX-Buffer-size to a sufficient value and send the structure as a whole (array of bytes) to the SPI and let it be handled by the internal interrupts.


user_460349's picture
1362 posts

 I think the GCC compiler paded with extra bytes inside structures.  

You can verify this checking the address of the first and the second element of the structure.

I can't remember if you have to use the attribute "align" or "pack". you can find it in the GCC help manual.




Log in to post new comments.