4808 views |0 replies
Last login 2023-4-5
Online Time 703 hours
Prestige 221 points
Points 174 points
【GD32F350 Sharing】【IV】L3G4200D Gyroscope Driver Writing
[Copy link]
In the step counting algorithm, a gyroscope is needed to detect changes in human motion posture. Here, the L3G4200D gyroscope is used. The L3G4200D is a MEMS motion sensor launched by STMicroelectronics: a three-axis digital output gyroscope. The optional -250~250, -500~500, and -2000-2000dps are available. At the same time, the IIC interface is used for data output. Here, the previous analog IIC is used for easy transplantation.
Similarly, add the l3g4200d source file and header file to the Driver folder in the project directory, and reconfigure the interface:#define L3G4200_Addr 0xD2 //Define the slave address of the device in the IIC bus, modify it according to the different ALT ADDRESS address pins//***************L3G4200D internal register address*********** #define WHO_AM_I 0x0F #define CTRL_REG1 0x20 #define CTRL_REG2 0x21 #define CTRL_REG3 0x22 #define CTRL_REG4 0x23 #define CTRL_REG5 0x24 #define REFERENCE 0x25 #define OUT_TEMP 0x26 #define STATUS_REG 0x27 #define OUT_X_L 0x28 #define OUT_X_H 0x29 #define OUT_Y_L 0x2A #define OUT_Y_H 0x2B #define OUT_Z_L 0x2C #define OUT_Z_H 0x2D #define FIFO_CTRL_REG 0x2E #define FIFO_SRC_REG 0x2F #define INT1_CFG 0x30 #define INT1_SRC 0x31 #define INT1_TSH_XH 0x32 #define INT1_TSH_XL 0x33 #define INT1_TSH_YH 0x34 #define INT1_TSH_YL 0x35 #define INT1_TSH_ZH 0x36 #define INT1_TSH_ZL 0x37 #define INT1_DURATION 0x38 复制代码 //L3G4200D IIC control function void I2C_GPIO_Config(void); void I2C_Delay(void); uint8_t I2C_Start(void); void I2C_Stop(void); void I2C_Ack(void); void I2C_NoAck(void); uint8_t I2C _WaitAck(void); void I2C_SendByte(uint8_t SendByte); unsigned char I2C_RadeByte(void); uint8_t Single_Write(unsigned char SlaveAddress,unsigned char REG_Address,unsigned char REG_data); unsigned char Single_Read(unsigned char SlaveAddress,unsigned char REG_Address); void Init_L3G4200D(void); void READ_L3G4200D(void); void Send_data(uint8_t axis); void DATA_printf(unsigned char *s,short temp_data); 复制代码 The three-axis angular velocity information printed out using the serial port debugging is as follows: