标题:
HT32F52352DMP单片机读取MPU9250数据源程序
[打印本页]
作者:
iron_001
时间:
2021-4-2 12:17
标题:
HT32F52352DMP单片机读取MPU9250数据源程序
单片机源程序如下:
#include "ht32.h"
#include "ht32_board.h"
#include "usart_int.h"
#include <string.h>
#include "usart.h"
#include "./IMU901/ringbuffer.h"
#include "./IMU901/imu901.h"
#include "delay.h"
#include "motor.h"
#include "NRF24L01.h"
#include "usart1.h"
#include "ANO_DT.h"
#include "pid.h"
#include "mpu9250.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h"
#include "stdio.h"
/*
1号电机 30解锁 31-40 占空比 372-480
3号电机 30解锁 31-40 占空比 372-480
2号电机 18解锁 19-34 占空比 228-408
4号电机 18解锁 21-39 占空比 252-468
*/
u8 tmp_buf[33]= "hello";
u8 k;
float mpu_pitch,mpu_roll,mpu_yaw; //欧拉角
short aacx,aacy,aacz; //加速度传感器原始数据
short gyrox,gyroy,gyroz;//陀螺仪原始数据
short temp; //温度
#define Key1 1<<8 //Key1=PA8
#define Key2 1<<13 //Key2=PC13
#define Key1_DIR { HT_GPIOA->INER |= HT_GPIOA->PUR |= Key1;} //Key1块の矗ど筿
#define Key2_DIR { HT_GPIOC->INER |= HT_GPIOC->PUR |= Key2;} //Key2块の矗ど筿
#define Key1_0 !(HT_GPIOA->DINR & Key1) //浪琩琌龄Key1=0
#define Key1_1 HT_GPIOA->DINR & Key1 //浪琩琌龄Key1=1
#define Key2_0 !(HT_GPIOC->DINR & Key2) //浪琩琌龄Key2=0
#define Key2_1 HT_GPIOC->DINR & Key2 //浪琩琌龄Key2=1
void Key_Init(void)
{
HT_CKCU->AHBCCR |= 1<<16;
HT_CKCU->AHBCCR |= 1<<18;
Key1_DIR
Key2_DIR
}
int main(void)
{
static u8 t =23;
// u8 buff[20];
//NRF24L01_Init();
USART0_Configuration(256000); //USART0的初始化,波特率为460800
// printf("OK\n");
//// ringbuffer_init(&usart0RxFifo, (uint8_t*)buff, 256); //FIFO结构体的初始化
UART0_Configuration(115200);
// PWM_Init();
// Key_Init();
//// unlocked();
//// delay_ms(500);
//// delay_ms(500);
//// delay_ms(500);
//// delay_ms(500);
MPU_Init(); //初始化MPU9250
// if(NRF24L01_Check()==0)
// {
// }
if(mpu_dmp_init())
{
}
// NRF24L01_TX_Mode();
while (1)
{
// Data_Send_To_PC();
delay_ms(5);
// Angle_PWM(attitude.pitch,attitude.roll,attitude.yaw);
Angle_PWM(mpu_pitch,mpu_roll,mpu_yaw);
t++;
if(t == 100)
{
// HT32F_DVB_LEDToggle(HT_LED1);
// HT32F_DVB_LEDToggle(HT_LED2);
}
if(mpu_mpl_get_data(&mpu_pitch,&mpu_roll,&mpu_yaw)==0)
{
temp=MPU_Get_Temperature(); //得到温度值
MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //得到加速度传感器数据
MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //得到陀螺仪数据
printf("x:%f,y:%f,z:%f\n",mpu_pitch,mpu_roll,mpu_yaw);
HT32F_DVB_LEDInit(HT_LED2);
HT32F_DVB_LEDOn(HT_LED2);
}
}
}
复制代码
所有代码51hei提供下载:
MPU9250DMP.7z
(611.51 KB, 下载次数: 12)
2021-4-2 15:23 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1