cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452CC SPI send wrong data

fmaesso
Associate

Hi, Its my first post. Im trying a STM32L452 and IIS3dwb on SPI2 (SPI2_CLK on PB13). When I send the WHO_AM_I command, the SPI2_MOSI send only 0x0F instead 0x8F (0x0F OR 0x80). SPI2 setup is CPOL = High, CPHA = 2 Egde, 8 bits, MSB First, Baud Rate = 10MHz. PB1 is CS for IIS3DWB. 

 

Acc = IIS3DWB_RegRead(IIS3DWB_WHO_AM_I);

 

unsigned char IIS3DWB_RegRead(unsigned char reg) {

unsigned char value = ((reg & 0x7F) | 0x80);

HAL_GPIO_WritePin(ACC_CS_GPIO_Port, ACC_CS_Pin, 0);

HAL_SPI_Transmit(&hspi2, &value, 1, 5000);

HAL_SPI_Receive(&hspi2, &value, 1, 5000);

HAL_GPIO_WritePin(ACC_CS_GPIO_Port, ACC_CS_Pin, 1);

return value;

}

 

dso_01_01_02_11_25.bmp

 Where am I going wrong?

Thanks!

3 REPLIES 3
TDK
Guru

That signal is definitely 0x8F.

 

TDK_1-1698328955326.png

 

If you feel a post has answered your question, please click "Accept as Solution".

I'm ashamed!

sorry

Thanks

> When I send the WHO_AM_I command, the SPI2_MOSI send only 0x0F instead 0x8F

Why do you think so? To me, this looks exactly like 0b10001111 = 0x8F (in SPI mode 3 as required by the sensor).

 

waclawekjan_1-1698330063133.png

JW