2011-01-10 01:55 PM
Receiving SPI data through DMA - STM32 internal hardware error ?
#spi-dma2011-05-17 05:21 AM
Try doing it slower. Try using different source/dest buffers. Look at the transaction with a logic analyzer.
2011-05-17 05:21 AM
I set the slowest SPI clock possible which is below 400 kHz in my application. It
didn't help. I will try to use different buffers.2011-05-17 05:21 AM
I've just checked different buffers as well as setting 16-bit SPI data length. It didn't help either. I don't have a logic analyzer...
I also examined my SPI functions on 2 different PCBs with 2 different SD cards and the problem existed with the two cards and PCBs.2011-05-17 05:21 AM
Hi k.robert,
Just one question: Why channel 2 and channel 3 have the same address, I guess that one should have buffer address and the other the SPI data register address, isn't it ? DMA1_Channel2->CMAR = (u32) Buffer; DMA1_Channel3->CMAR = (u32) Buffer; The code isn't commented si it needs much time to understand.MCU Lüfter2011-05-17 05:21 AM
Hi Robert,
I think that it should be something like this DMA1_Channel2->CPAR = (u32) SPI_ADDRESS; or DMA1_Channel3->CPAR = (u32) SPI_ADDRESS; Thanks to correct me in any case.MCU Lüfter2011-05-17 05:21 AM
The following code:
DMA1_Channel2->CPAR = (u32) SPI_ADDRESS; or DMA1_Channel3->CPAR = (u32) SPI_ADDRESS; is written in DMA initialization routine. SPI_ADDRESS equeals to SPI data register address (SPI_DR) To receive data via SPI the CLK clock must be active. The only way to do so is to send ''dummy'' data like it is done by sending data through SPI. I discovered something strange. It turns out that sending data sometimes works incorrectly as well... I connected an oscilloscope to CLK and MOSI. The CLK signal is ok but i noticed there are corrupted bits sent on MOSI (instead of '1' i get '0' in some of the sent bytes). For example, when i send all bytes of 0x18 value, some of the bytes that i see on the oscilloscope are 0x00.2011-05-17 05:21 AM
Hi robert,
In such case, you should check your board, perhaps you have something pulling down the line.MCU Lüfter2011-05-17 05:21 AM
It seems i solved the problem with sending data. The data length in SPI register (DFF bit) was set to 16-bit wide. In such case DMA->CMAR memory address register should be written with a value which must be an even numer (2 byte aligned). If the addres is not even DMA reads incorrect values which in turn are sent through SPI. I set the correct address and it work fine now. But i still have issues with the receiver...
2011-05-17 05:21 AM
Hello Robert,
Can you please mention the steps you have taken in order to get the receiving part of SPI work without DMA. I am also trying to do that. But it is not working properly. I need to receive in slave mode. Thank you.