DMATransfer(0xFF, txBuffer, rxBuffer, sizeof(rxBuffer));
while (0u == (SPI_ReadTxStatus() & SPI_STS_SPI_DONE)) // <- Forgotten semicolon here???
memset(rxBuffer, 0, sizeof(rxBuffer)); // <- otherwise receive buffer gets overwritten!
You could use an interrupt that indicates a finished DMA, but when the ss line has to go high again you will have to wait for a finished SPI transfer.
Yes i forgot to write the semicolon because i was cleaning the code of the project :D.
I used memset function to fill the array with zeroes after the transfer, i think now it's working, but i was trying to avoid wait the SPI to finish the transfer inside the interrupt routine.
Maybe if i wait for the interrupt of the Rx DMA channel i do not wait to much, it's asserted finishing the 0x05 byte on the image.
Also on the beginning of the program i read the free TDs with CyDmaTdFreeCount() and i get 0x68 (104 decimal), where can be the rest of the TDs?
Thanks for the help :D
DMA.cywrk_.Archive07.zip 538.3 K
The TDs are a property of the DMA-controller. What you receive when allocating a TD is an index-numberinto the controller's array of TDs
i was trying to avoid wait the SPI to finish the transfer inside the interrupt routine. Not a bad idea!!! I would suggest to set a flag within the handler and wait for the flag in the main-loop.
Just my 2ct:
SPI is (as all serial connections) comparably slow (when compared to CPU speed) and usually does not need a fast reaction. DMA is able to shovel amounts of data A simple SPIM_PutArray() is a "fire -and-forget-it" function, all will be handled internally and at need I can control the state of transmission. I usually use DMA to transfer data from fast devices (ADC, SAR) where the response time is short and the available amount of statements to execute is restricted .
Thanks for the feedback, and yes, i did compare the usual API vs. the DMA transfers and there are almost no differences on matter of time, the unique one i found is i do not have to control the /SS line.
Always thanks for the tips Bob, those are really helpfull
You are always welcome, Carlos!