cancel
Showing results for 
Search instead for 
Did you mean: 

any idea how to connect magnetometer LIS2MDLTR made by ST ?

MNapi
Senior III

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!

 

Untitled.png

Untitled1.png

 

2 REPLIES 2
TDK
Super User

> whoami_val[0] should be = 0x40

And what do you get?

 

Send a dummy HAL_SPI_Transmit command before pulling CS low.

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

I think your SPI setting is wrong, its half-duplex-master spi :

AScha3_0-1755966533621.png

AScha3_1-1755967143355.png

+ dont drive it at max speed for beginning...try 2 Mbit or so;

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