cancel
Showing results for 
Search instead for 
Did you mean: 

SPI slave doesn't transmit, STM32F407VE

Ivan Feoctistov
Associate II
Posted on March 21, 2018 at 10:00

I have STM32F103C8 as a SPI master and a STM32F407VE as a SPI slave.

I haven't worked with SPI enough to find optimal way to write communication mechanism, and earlier work with SPI only on AVR and Texas Instruments C2000 platforms, so STM32 is new for me.

That's what I remember about SPI: Master initializes communication, sends data by MOSI with CLK. Slave can answer to request only when master will send something. So - slave should be ready to push data by MISO when CLK will appear. Hope that's right.

Transmission and receiving by interrupt works fine. F103 transmits by command HAL_SPI_Transmit() to F407, which receiving data in ISR, every byte, no troubles.

But now's my headache begins.

Master sends command to slave to get ready for answer. Slave collects data in one array and pushes it to transmit buffer. Master, after 1ms delay sends zeroes to slave just to receive whole array of data from slave. '\n' means the end of transmission.

So how I should organize that?

Slave receiving command to get ready, that's alright.

Slave collected data in one array.

What should be next?

I use command 

HAL_SPI_Transmit() and push there whole array. As I hope - this data will be held in SPITx buffer, and when CLK appears - will be pushed through MISO until master stops communication. 

But it's not working like that. Master receiving nothing.

The question is: How slave should transmit data to master? When? What functions should be used?

P.S. Using STM32CubeMX, it means - HAL lib, as you can see.

#stm32 #stm32f4 #hal #spi #spi-slave
1 ACCEPTED SOLUTION

Accepted Solutions
Ivan Feoctistov
Associate II
Posted on March 22, 2018 at 12:58

Found and solved problem.

Slave was receiving command to get ready byte by byte. Every received byte caused interrupt, and in the end of interrupt callback function next receiving interrupt was enabled.

After handling interrupt all SPI flags resetting to normal state. So when I was receiving dummy data from master - RxCallback was called, and at the end of processing all SPI flags was reset automatically, so slave couldn't insert anything to SPI Tx register.

Now interrupts are enabling only if command still isn't received. If command to get ready received - only flag to get ready is setting on. Data is pushed in function HAL_SPI_Transmit(), and after it stands a function that waits SPI to transmit everything it has in buffers. Only then I turn on SPI Rx interrupt.

View solution in original post

1 REPLY 1
Ivan Feoctistov
Associate II
Posted on March 22, 2018 at 12:58

Found and solved problem.

Slave was receiving command to get ready byte by byte. Every received byte caused interrupt, and in the end of interrupt callback function next receiving interrupt was enabled.

After handling interrupt all SPI flags resetting to normal state. So when I was receiving dummy data from master - RxCallback was called, and at the end of processing all SPI flags was reset automatically, so slave couldn't insert anything to SPI Tx register.

Now interrupts are enabling only if command still isn't received. If command to get ready received - only flag to get ready is setting on. Data is pushed in function HAL_SPI_Transmit(), and after it stands a function that waits SPI to transmit everything it has in buffers. Only then I turn on SPI Rx interrupt.