购买正点原子的ATK-IMU901模块后,发现例程给的是HAL库的,以下是我将其转为标准库的方法。
1.将例程文件夹中的IMU901和usart2复制到新的工程文件夹中的HARDWARE里,并在新工程文件中的C/C++中添加这两个文件夹。

2.在HARDWARE中添加imu901.c,ringbuffer.c,usart2.c。

3.对于usart2的修改,可以直接替换成我下面贴出的程序.
usart.c:
#include "sys.h"
#include "usart2.h"
#include "ringbuffer.h"
#define UART2_RX_BUFFER_SIZE 256
uint8_t uart2RxBuffer[UART2_RX_BUFFER_SIZE];
ringbuffer_t uart2RxFifo;
/**
* @brief 串口X初始化
* @param 无
* @retval 无
*/
void usart2_init(uint32_t bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能USART2,GPIOA时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 , ENABLE);
//USART2_TX GPIOA.2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.2
//USART2_RX GPIOA.3初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;//PA3
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(GPIOA, &GPIO_InitStructure);


3897

被折叠的 条评论
为什么被折叠?



