cancel
Showing results for 
Search instead for 
Did you mean: 

Why F030C8 SPI performes like this? ''Data packing“ problem

blue_eagle
Associate II
Posted on January 08, 2016 at 17:15

IDE environment: KEIL v5.14 + CubeMX v4.12 + CubeF0 v1.4

Chip type:F030C8T6

Debugger:ST-LINK VII

When I use SPI in polling mode, i found a weird thing. I have never met this before when I were using F1xx series chips.

The date size is set to 8-bit long and MSB first (SPIx_CR1=0x36C,SPIx_CR2=0x1700).

Here is the main code.

while(1)

{

SPI1->DR = 0XFF;

while(SPI1->SR & SPI_SR_BSY);

while(!(SPI1->SR & SPI_SR_RXNE));

temp = SPI1->DR;

}

This is the corresponding waveform.

0690X00000602QeQAI.bmp

Is the sentence ''SPI1->DR = 0XFF;'' a kind of ''16-bit access of SPIx_DR''?

When I replaced 0XFF with a uint8_t variable the waveform didn't change at all.

I also changed the optimization level to -O0, but it had no effect.

''Data packing'' is too inconvenient to communicate with some devices,like nRF24L01. Can anyone tell me how to read/write SPIx_DR in a 8-bit way like it is in F1xx series? 

Thanks.
4 REPLIES 4
Posted on January 08, 2016 at 17:28

Is the sentence ''SPI1->DR = 0XFF;'' a kind of ''16-bit access of SPIx_DR''?

What's the structure define it as being? Because it will use that to determine it.

Can anyone tell me how to read/write SPIx_DR in a 8-bit way like it is in F1xx series? 

 

*((uint8_t *)&SPI1->DR) = 0xFF; // simple casting

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
blue_eagle
Associate II
Posted on January 09, 2016 at 02:59

Hi clivel,

Thank you for your advise, it works!

I also try to change the define of DR in the structure to uint8_t, it has the same effect. :D

But I am still confused why ?SPI1->DR = 0XFF;? and ''*((uint8_t *)&SPI1->DR) = 0XFF ;'' show up in the same assembly statement.

Sentence:SPI1->DR = 0XFF;

0690X000006036aQAA.jpg

Sentence:*((uint8_t *)&SPI1->DR) = 0XFF ;

0690X000006036fQAA.jpg

Do you have any idea?

Thanks again.

Posted on January 09, 2016 at 03:08

STR (Word) vs STRB (Byte)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
blue_eagle
Associate II
Posted on January 10, 2016 at 02:12

Thank you Clivel. You are nice.