cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 to stm32f7 port Spi wrong clk signal

Christian Fehrenbacher
Associate II
Posted on December 12, 2016 at 14:28

Hello,

until now I have a custom board with a stm32f4 and it works fine with the standard peripheral lib.

I tried the new stm32f767 and the board started working after a few changes.

Except the SPI, I can receive and transmit data, the CS works, but the clock signal is wrong.

I need a data length of 8 bit, but I get 16 Bit.

(I get 16 pulses at the clock pin instead of 8, the signal on MOSI, MISO and CS are correct)

I don't see my mistake in the register settings, what did I miss?

spi2->CR1     : 0x035D

spi2->CR2     : 0x1700

spi2->SR      : 0x0643

spi2->DR      : 0x040C

spi2->CRCPR    : 0x0007

spi2->RXCRCR  : 0x0000

spi2->TXCRCR  : 0x0000

spi2->I2SCFGR : 0x0000

spi2->I2SPR      : 0x0002

I don't use HAL because it would be a lot of work to port the whole project and the register differences are small.

Thanks for every suggestion.

Kind regards

Chris

#clk #spi #stm32f4 #clock #stm32f7 #stm32f767
5 REPLIES 5
Posted on December 12, 2016 at 15:00

F7's SPI features the unfortunate data packing feature, contrary to F4. Do you take this into account when writing into SPIx_DR?

JW

Posted on December 12, 2016 at 15:39

Hello JW,

tanks for the respond.

The data pins (MOSI and MISO) are fine, the data arrives, only the clk signal is wrong.

In the CR2 Register is the DS part, where you can configure the data length.

I need 8 Bit, but if I set it to  8-Bit I get 16.

If I set it to 5 Bit I get 10 and so on.

I tried to set it to 0, that's a forbidden value, it should force the data length to 8 according to the manual, but ended in 16 Bit.

I read the register value back right before the read operation and after the initialisation, there is no corruption after the initialisation.

If I set the data length to 4 Bit, it generates the 8 Bit I want, so I am happy with that work around.

Perhaps it is a error in the manual ...

greetings

Chris

Posted on December 12, 2016 at 15:42

Chris,

read the 'data packing' subchapter in the 'F7 RM.

Jan

Posted on December 13, 2016 at 08:33

Hello Christian,

Jan is right. On the F303, there is the same feature and if you just write SPIx.DR = data, the compiler will assume that you want to write 16 bits to DR (because DR is 16 bits, even if data is an 8 bits variable). The trick here is to force an 8-bit write to DR, like this:

*(__IO uint8_t *) ((uint32_t)SPIx + (uint32_t)0x0C) = data; // Replace SPIx with the actual SPI you are using

Have a nice day,

Carl

P.S. How do you format code in the new forum software ?

Posted on December 13, 2016 at 08:39

Hello Jan and Carl,

thanks for the help.