Skip to main content
Visitor II
February 8, 2022
Question

After a long poweroff I can`t read ASM330LHH_WHO_AM_I (0xF0) register correctly.

  • February 8, 2022
  • 1 reply
  • 1227 views

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);

    This topic has been closed for replies.

    1 reply

    Visitor II
    February 11, 2022

    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

    SPere.4Author
    Visitor II
    February 22, 2022

    Made more stable:

    1. Used different wires (shorter). Because I think electromagnetic interference takes place.
    2. Also I noticed that good working depends of right poweron - sometimes I need to reeboot it several times. I thint I need to make MEMS poweron with some delay.
    3. As you mentioned - made INTx pin floating.
    4. No syncronization in MCU debug-mode, there was something similar: https://community.st.com/s/question/0D53W000003vhUNSAY/h3lis331dl-id-problem

    Yes, you`re right - 0x0F instead of 0xF0, otherwise nothing would work. It is mistake in text. I used official library.

    Thanks.