2024-05-25 03:49 PM
Привіт! У мене проблема з отриманням даних із датчика LSM6DS3. Коли я намагаюся прочитати значення реєстру "WHO_AM_I", я отримую надто короткі імпульси у відповідь, які не можуть бути прочитані поданими до його тактового сигналу.
Я використовую цю плату з сенсором. SPI. Головним є STM32F411.
3v3 -> 3,3 В
GND -> GND
SA0 -> PA6 -> SPI1_MISO
CS -> PA4 -> GPIOA4
SDA -> PA7 -> SPI1_MOSI
SCL -> PA5 -> SPI1_SCK
У випадку, коли я надсилаю значення 0x8F, я отримую результат, як показано нижче. У той же час я повинен отримати значення 0x69 або 01101001 у двійковому вигляді. І якщо ви важливо подивіться на результати нижче, ви побачите, ніби щось заважає, імпульс занадто короткі, щоб їх можна було записати.
Я намагався прочитати значення в інших реєстрах "CTRL9_XL" і там така ситуація. Я повинен отримати 00111000, але я отримав 00110000, ніби імпульси не були стиснуті та записані на одне значення менше:
Налаштування SPI:
2024-05-25 04:02 PM
Everything was published in Ukrainian for some reason, I apologize. Dubbed in English:
Hello! I'm having a problem getting data from the LSM6DS3 sensor. When I try to read the value of the "WHO_AM_I" register, I get too short pulses in response that cannot be read by applying it to its clock.
I am using this sensor board. SPI. The main one is STM32F411.
3v3 -> 3.3V
GND -> GND
SA0 -> PA6 -> SPI1_MISO
CS -> PA4 -> GPIOA4
SDA -> PA7 -> SPI1_MOSI
SCL -> PA5 -> SPI1_SCK
In the case when I send the value 0x8F, I get the result as shown below. At the same time I should get the value 0x69 or 01101001 in binary form. And if you look carefully at the results below, you will see that something is interfering, the pulse is too short to be recorded.
I tried to read the value in other "CTRL9_XL" registers and there is such a situation. I should get 00111000, but I got 00110000, as if the pulses were not compressed and written one less value:
SPI settings:
void SpiConfig(void){
RCC->APB2ENR |= (1 << 12);
/////////////////////////////////////////////////// //////////
SPI1->CR1 |= (1 << 0) | (1 << 1); //CPHA=1 CPOL=1
SPI1->CR1 |= (1 << 2); //Master mod
SPI1->CR1 |= (2 << 3); //010: fPCLK/8 BR[2:0] 5 MHz SPI CLK
SPI1->CR1 &= ~(1 << 7); //LSBFIRST = 0 => MSB first, then LSB
SPI1->CR1 |= (1 << 8 ) | (1 << 9); //High level SSI and SSM Software control enabled
SPI1->CR1 &= ~(1 << 10); //RXONLY = 0 => Full duplex mode
SPI1->CR1 &= ~(1 << 11); //8-bit
SPI1->CR2 = 0;
}
GPIO settings:
void SpiGPIOConfig(void){
RCC->AHB1ENR |= (1 << 0); //Enable RCC for GPIO_A
GPIOA->MODER |= (2 << 10) | (2 << 12) | (2 << 14) | (1 << 8);
//Alternative function for PA5/6/7 common output for PA4
GPIOA->MODER &= ~(1 << 9); //Push-Pull for PA5/6/7/4 (default)
GPIOA->OSPEEDR |= (3 << 10) | (3 << 12) | (3 << 14) | (3 << 8); //High speed for PA5/6/7/4
GPIOA->AFR[0] |= (5 << 20) | (5 << 24) | (5 << 28); //AF5 (AFRL 0 - 7) on PA5/6/7
}
Transfer:
void SPI_Transmit (uint8_t *data, int size){
//1. Wait for the TXE bit to be set in the registration state
int i = 0;
while(i < size){
while (!((SPI1->SR) & (1 << 1))){}; //Wait for the TXE bit to be set -> This indicates that the buffer is empty
SPI1->DR = data[i]; //Load the data into the data register
i++;
}
while(!((SPI1->SR) & (1 << 1))){}; //Wait for the TXE bit to be set -> This indicates that the buffer is empty
while(((SPI1->SR) & (1 << 7))){}; //Wait for the BSY bit to clear -> This means that the SPIs are not busy with communications
uint8_t temp = SPI1->DR;
temperature = SPI1->SR;
}
Main function:
...
uint8_t RxData[6];
address uint8_t = 0x8f;
while(1){
CS_EN(); // pull the pin low
SPI_Transmit (&address, 1); // send the address
SPI_Receive (RxData, 1); // get 1 byte of data
CS_DIS(); // pull the pin high
Delay_ms(1);
}
If you need to provide something else to find the error, then tell me, I will provide everything you need
2024-05-26 11:00 AM
SPI mode set in the STM32 matches the mode expected by the LSM6DS3. If necessary, try switching to CPOL=0, CPHA=0 (Mode 0) and see if that resolves the issue. If you fear that your sensor itself is faulty, you can cross-check the sensor with an Arduino UNO with the sample code and library given here: https://learn.sparkfun.com/tutorials/lsm6ds3-breakout-hookup-guide/all
If you want to switch to an alternative acelerometer, you can think of HMC6343 Accelerometer. The HMC6343 is a solid-state compass module with tilt compensation. Module. https://www.pcbway.com/project/shareproject/HMC6343_Accelerometer_Module_7ed027c5.html
.