2022-02-07 10:51 PM
I`m usung STEVAL-MKI193V1 board + STM32f103c8.
After init, It shows me sometimes 0x48 0x4C 0x54, 0x56 but it should be 0x6B.
But sometimes after debugging multiple reboots, step by step executions, I manage to see the number 0x6b and everything works correctly, looks like a heisenbug.
My commection scheme:
VDD - +3.3
VDDIO - +3.3
GND - GND
NSS - SPI2_NSS (pa12)
SCK - SPI2_SCK (pa13)
SDO - SPI2_MISO (pa14)
SDA - SPI2_MOSI (pa15)
INT2 - GND
INT1 - GND
uint16_t SPI_rx(uint8_t address) {
uint8_t ret = 0;
address = 0x80 | address;
GPIO_ResetBits(SPI2_NSS, SPI2_PIN_CS);
while (!SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI2, address);
while (!SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE));
SPI_I2S_ReceiveData(SPI2);
while (!SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI2, 0x00); //send null for recieve data
while (!SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE));
ret = SPI_I2S_ReceiveData(SPI2);
GPIO_SetBits(SPI2_NSS, SPI2_PIN_CS);
return ret;
}
/*call function*/
id = SPI_rx(ASM330LHH_WHO_AM_I);
2022-02-11 07:30 AM
Hi @Akellaerepelkin ,
note that the WHO_AM_I register is 0x0F instead of 0xF0 as reported by you.
I believe however this is not the problem here. Are the SPI lines stable, from the oscilloscope? Maybe it's only a matter of delays, since you are able to obtain the correct WHO_AM_I in a step-by-step debug.
Can you try the same procedure leaving the INTx pin floating?
AG
2022-02-22 05:46 AM
Made more stable:
Yes, you`re right - 0x0F instead of 0xF0, otherwise nothing would work. It is mistake in text. I used official library.
Thanks.