stm32 驱动MPU6500陀螺仪传感器

#include "mpu6500.h"
#include "sys.h"
#include "delay.h"
#include "usart.h"   
#include "log.h"
#include "spi.h"

static void MPU6500_set_cs(MPU6500_CS_TypeDef num);
static void MPU6500_clear_cs(MPU6500_CS_TypeDef num);

/**
 * @brief 检查MPU6500设备的连接状态
 * 
 * 该函数通过读取MPU6500设备的设备识别号来检查设备是否正确连接
 * 如果设备识别号与预定义的MPU6500设备ID不匹配,则表示设备未正确连接
 * 
 * @param addr MPU6500设备的I2C地址
 * @return uint8_t 
 *         返回0表示设备已正确连接,返回1表示设备连接错误
 */
static uint8_t MPU6500_Check(u8 addr)
{
  // 初始化设备识别号为ERROR,用于指示设备连接状态
  uint8_t deviceID = ERROR;

  // 从指定地址的MPU6500设备中读取设备识别号
  deviceID = MPU6500_Read_Byte(addr, MPU6500_WHO_AM_I);
  
  // 检查读取到的设备识别号是否与MPU6500的预定义设备ID匹配
  if(deviceID != MPU6
#include "sys.h" #include "delay.h" #include "usart.h" #include "led.h" #include "timer.h" #include "FreeRTOS.h" #include "task.h" #include "debug_cmdshell.h" #include "stabilizer.h" //任务优先级 #define START_TASK_PRIO 1 //任务堆栈大小 #define START_STK_SIZE 128 //任务句柄 TaskHandle_t StartTask_Handler; //任务函数 void start_task(void *pvParameters); //任务优先级 #define TASK2_TASK_PRIO 3 //任务堆栈大小 #define TASK2_STK_SIZE 512 //任务句柄 TaskHandle_t Task2Task_Handler; //任务函数 void task2_task(void *pvParameters); int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//设置系统中断优先级分组4 delay_init(); //延时函数初始化 uart_init(115200); //初始化串口 LED_Init(); //初始化LED stabilizerInit(); //创建开始任务 xTaskCreate((TaskFunction_t )start_task, //任务函数 (const char* )"start_task", //任务名称 (uint16_t )START_STK_SIZE, //任务堆栈大小 (void* )NULL, //传递给任务函数的参数 (UBaseType_t )START_TASK_PRIO, //任务优先级 (TaskHandle_t* )&StartTask_Handler); //任务句柄 vTaskStartScheduler(); //开启任务调度 } //开始任务任务函数 void start_task(void *pvParameters) { taskENTER_CRITICAL(); //进入临界区 xTaskCreate((TaskFunction_t )task2_task, (const char* )"task2_task", (uint16_t )TASK2_STK_SIZE, (void* )NULL, (UBaseType_t )TASK2_TASK_PRIO, (TaskHandle_t* )&Task2Task_Handler); xTaskCreate(stabilizerTask, "STABILIZER", 450, NULL, 5, NULL); /*创建姿态任务*/ vTaskDelete(StartTask_Handler); //删除开始任务 taskEXIT_CRITICAL(); //退出临界区 } //task2任务函数 void task2_task(void *pvParameters) { //u8 task2_num=0; u16 len; while(1) { //task2_num++; //任务2执行次数加1 注意task1_num2加到255的时候会清零!! //printf("任务2已经执行:%d次\r\n",task2_num); if(USART_RX_STA&0x8000) { len=USART_RX_STA&0x3fff; debugcmd_process(USART_
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式软硬件叶玄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值