2018-10-21 10:25 AM
Hello.
I am working on a project and using STM32L053 board.
For now, my goal is to create a channel of SPI communication, master & slave, an to test my code.
I am using only 1 ST board which serves both as master and slave.
I have defined all necessary GPIOs using the CubeMX program - miso, mosi, clk, (software nss).
As part of the requirements i need to use the DMA in order to transmitte and receive date.
Each SPI has it's own Rx & Tx buffers which are connected to the relevant channel of the DMA.
The problem:
I have been able to send data only in one direction: Master --> Slave - I load the Tx buffer of the master and send it to the slave. The slave receives it properly into it's Rx buffer. I also see the DMA channels do what they are suppose to do.
The other way around does not seem to work. No matter what i have tried, the master wont get back a reply for the slave.
Any ideas to what should i pay more attention or check in my code ??
2018-10-21 10:56 AM
The master has to shift data out, or otherwise generate a clock, for the slave to be able to respond.
This is often achieved by sending dummy data.
2018-10-21 11:47 AM
Thank you for your answer.
Of course i have tried doing that. My current test is sending a few messages one after the other, one is valid and the other is a dummy.
The data does not shift back to the master in this case.
At first i thought that my DMA initialization was wrong but i went over my parameters many times and they are ok.
2018-10-21 03:09 PM
Do you see the data coming from slave on the MISO line when observed by an oscilloscope/logic analyzer?
Do you see those data in the data register of SPI in a debugger? (But don't look at SPI registers by debugger when you want the DMA to work).
JW
2018-10-21 11:00 PM
No, i cant see the MISO line when observed by an oscilloscope.
When i send data from master to slave, at the end of the transmission i can see inside the slave's DR the last char that was sent.
2018-10-22 06:51 AM
I think i found the problem.
I seems that the master's Rx and slave's Tx should always be enabled during the entire process.
Previously i have enabled them in different places in my code, now i enabling the relevant DMA channels in the beginning, where i initialize all DMA parameters and never touch them again.
Thank you