SPI Slave [SOLVED]

pylon:
If I interpret this configuration of the master correctly you chose the wrong mode on the slave side:

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;

SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;




Does this mean SCK is active LOW and the second edge is the time the data is viable? If so I think the mode on the slave side should be 3 and not 0 according to this picture http://en.wikipedia.org/wiki/File:SPI_timing_diagram2.svg

If the modes are not equal a correct transmission is not possible.

Thx, i try to change it in this way

SPIE - Enables the SPI interrupt when 1
SPE - Enables the SPI when 1
DORD - Sends data least Significant Bit First when 1, most Significant Bit first when 0
MSTR - Sets the Arduino in master mode when 1, slave mode when 0
CPOL - Sets the data clock to be idle when high if set to 1, idle when low if set to 0
CPHA - Samples data on the falling edge of the data clock when 1, rising edge when 0
SPR1 and SPR0 - Sets the SPI speed, 00 is fastest (4MHz) 11 is slowest (250KHz)

with the master configuration i think i need:
DORD = 1
CPOL = 1
CPHA = 1
Is it now correct?

Graynomad:
How fast is the master sending data?

I suspect while you are faffing around with Serial.print()s you receive about 20 bytes in the SPI.

I would accumulate ALL the data then print it.

Also because the two events (SPI and serial) are asynchronous you probably read SPDR half way through receiving a byte.

I think there are issues with the way you are returning data as well, but let's get one direction working first.


Rob

I don't know the spi clock of stm32vldiscovery, i know internal max clock is 24mhz.
With 2 stm32 code of master work perfectly then problem isn't in master code,
I try to use a new variable to store spi data received and then i print it as u say.
Thx for help.