cancel
Showing results for 
Search instead for 
Did you mean: 

SPI master slave sync problem

zoharr
Associate II
Posted on May 29, 2014 at 13:23

Hello,

I'm trying to use stm32l152 as SPI slave, and communicate with master via PC with 

USB-SPI device.

I've configure SPI2 as slave. Slave clock set to 4MHz.

I'm using NSS hardware, and getting ETXI once CS gets low in NSS pin.

The PC program using USB-SPI device.

The clock is configure to 3MHz.

CPOL and CPHA are compatible in master and slave.

I'm trying to transfer 24 bits, with 8 bit buffer of STM32.

the master transmit 3 bytes in the same CS.

I'm testing all my signals with scope:

The master transmit the correct signals (0x78, 0x55, 0x33).

The slave code receive the correct data and send the proper data (0x12, 0x34, 0x56).

The problem is that the master receives incorrect data in the MISO.

The data in MISO line is: 

1. 0x12, 0x12, 0x34

2. 0x56, 0x12, 0x34

3. 0x56, 0x12, 0x34 

.....

The first byte is sent twice, and as a result all data is shifted.

I trying to understand where is the problem, in the master or in the slave?

Thanks for any help

#spi-master-slave-sync-problem
3 REPLIES 3
Posted on May 29, 2014 at 21:40

Hard to say without seing actual code or hearing more details.

When does the slave place the first byte (0x12) into SPI_DR?

JW
iron
Associate II
Posted on September 05, 2014 at 00:56

I am having a similar problem trying to send data from an Arduino master to the ST Micro slave.  It looks as if the data is sent or received twice and shifted.

Posted on September 09, 2014 at 12:10

Hi rogel.zohar,

Please note that the data should be ready in the SPI DR register (slave) before the clock generation.

Thus in the slave side you need to write in the SPI DR register then check on TXE flag.

Try to do that and keep us informed about your finding.

Regards.