cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F417: SPI2 slave clock issues

tomwinkler9
Associate II
Posted on November 26, 2012 at 21:56

Hello,

My custom STM32F417 board is connected to a RaspberryPi via SPI2. The RaspberryPi is master, the STM slave. I'm able to receive data from the Rasp and for validation purposes I'm directly sending it back to the master in the RXNE interrupt handler:

void SPI2_IRQHandler(void){

  if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_RXNE) == SET)

   {

     SPI_I2S_SendData(SPI_I2S_ReceiveData(SPI2));

   }

}

This works fine for SPI clock rates up to about 11MHz. However, for larger frequencies is do not receive the full data back at the SPI master. At 12Mhz it seems that every other byte is skipped (well not really but almost). To it looks like the STM is not able to keep up with this clock speed (the clock obviously ist generated by the RaspberryPi). The Reference states that SPI2 is able to handle data at up to 21Mbps. What would I have to do to achieve that? Is that only possible via DMA?

Thank you,

Tom
3 REPLIES 3
Posted on November 27, 2012 at 18:28

It depends on many factors you did not care to mention, eg. transferred word size, processor clock, other interrupts and DMA running on the system, compiler and switches used, type of memory where this code is run from.

Just  a few easy facts, if the processor clock is at its maximum 168MHz and the transferred word size is 8 bits, there are around 120 cycles available per transferred word at 11MHz SPI clock. The ISR entry and exit for CM3 takes 12+12 cycles (I believe for CM4 this is the same).

Draw your own conclusions.

JW

frankmeyer9
Associate II
Posted on November 27, 2012 at 19:31

Apart from software/performance issues, you might need to look at the actual transmitted signals. For a rectangular signal of 11MHz, you have significant harmonics up to the VHF range, so you might look for a matching cable impedance, or shorten the wires considerably.

Andrew Neil
Evangelist III
Posted on November 27, 2012 at 19:53

''To [me] it looks like the STM is not able to keep up with this clock speed (the clock obviously ist generated by the RaspberryPi)''

 

 

That's an assumption. You need to verify whether the problem is in the STM or the RPi - or both...