2025-08-23 5:39 AM - edited 2025-08-23 5:40 AM
here is the code I am trying
uint8_t whoami_reg[1];
whoami_reg[0] = 0x4F | 0x80; // read command
uint8_t whoami_val[1];
whoami_val[0] = 0;
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); // CS low
HAL_SPI_Transmit(&hspi1, whoami_reg, 1, HAL_MAX_DELAY);
HAL_SPI_Receive(&hspi1, whoami_val, 1, HAL_MAX_DELAY);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET); // CS high
whoami_val[0] should be = 0x40
I tried all the possible settings CPOL (HIGH and LOW) , CPHA ( 1 edge and 2 edge) , slower baud and nothing, I read some posts other people had problem too with SPI but apparently made it working only with I2C
I even tried to solder another LIS2MDLTR and another, nothing!
2025-08-23 7:12 AM
> whoami_val[0] should be = 0x40
And what do you get?
Send a dummy HAL_SPI_Transmit command before pulling CS low.
2025-08-23 9:39 AM - edited 2025-08-23 9:43 AM
I think your SPI setting is wrong, its half-duplex-master spi :
+ dont drive it at max speed for beginning...try 2 Mbit or so;