cancel
Showing results for 
Search instead for 
Did you mean: 

How do i get L3GD20 Gyro sensor to work on STM32L0?

MikeP
Senior

Hello,

I am simply tring to communicate with the L3GD20 Gyrosensor using the WhoAmI command.

I am sending 0x0F and i'm expecting 0xD7 back (11010111) but I only received 0xFF which means i'm doing something wrong

I am using STM32CubeMX to generate the code , Keil IDE and using STM32L071

https://www.mouser.co.uk/datasheet/2/389/l3gd20h-954865.pdf

Any help would be appreciated!

//put CS low
HAL_GPIO_WritePin(GYRO_CS_GPIO_Port,GYRO_CS_Pin,GPIO_PIN_RESET);
		
//Transmit register address
spiData[0] = 0x0F;
HAL_SPI_Transmit(&hspi1,spiData,1,10);
	
//read
HAL_SPI_Receive(&hspi1,&spiData[1],1,10);
 
//put CS High
HAL_GPIO_WritePin(GYRO_CS_GPIO_Port,GYRO_CS_Pin,GPIO_PIN_SET);

1 ACCEPTED SOLUTION

Accepted Solutions
MikeP
Senior

I realised my error, I didn't enable the read bit. so instead of sending 0x0F (0000 1111) I should have sent 0xCF (1100 1111).

View solution in original post

1 REPLY 1
MikeP
Senior

I realised my error, I didn't enable the read bit. so instead of sending 0x0F (0000 1111) I should have sent 0xCF (1100 1111).