標(biāo)題:
nrf51822的MPU6050驅(qū)動(dòng)程序
[打印本頁(yè)]
作者:
falali162
時(shí)間:
2018-12-11 10:13
標(biāo)題:
nrf51822的MPU6050驅(qū)動(dòng)程序
nrf51822源程序如下:
/****************************************Copyright (c)****************************************************
**
**
**
**--------------File Info---------------------------------------------------------------------------------
** File name: main.c
** Last modified Date:
** Last Version:
** Descriptions: 使用的SDK版本-SDK_12.0.0
**
**--------------------------------------------------------------------------------------------------------
** Created by: 青風(fēng)電子
** Descriptions: MPU6050原始數(shù)據(jù)讀取實(shí)驗(yàn)
**--------------------------------------------------------------------------------------------------------*/
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "app_uart.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "mpu6050.h"
#include "twi_master.h"
/* 開發(fā)板中MPU6050模塊和串口占用的nRF52832管腳資源
P0.06:UART_TXD :串口發(fā)送
P0.08:UART_RXD :串口接收
P0.07:UART_CTS : 未使用流控
P0.05:UART_RTS : 未使用流控
串口需要短接對(duì)應(yīng)的跳線帽
P0.22:IIC時(shí)鐘
P0.23:IIC數(shù)據(jù)
*/
#define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE 1 /**< UART RX buffer size. */
void uart_error_handle(app_uart_evt_t * p_event)
{
if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_communication);
}
else if (p_event->evt_type == APP_UART_FIFO_ERROR)
{
APP_ERROR_HANDLER(p_event->data.error_code);
}
}
/*******************************************************************************
* 描 述 : 串口初始化。波特率115200bps,流控關(guān)閉
* 參 數(shù) : 無(wú)
* 返回值 : 無(wú)
******************************************************************************/
void uart_config(void)
{
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
RTS_PIN_NUMBER,
CTS_PIN_NUMBER,
APP_UART_FLOW_CONTROL_DISABLED, //關(guān)閉流控
false,
UART_BAUDRATE_BAUDRATE_Baud115200 //波特率設(shè)置為115200bps
};
APP_UART_FIFO_INIT(&comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_error_handle,
APP_IRQ_PRIORITY_LOW,
err_code);
APP_ERROR_CHECK(err_code);
}
/**********************************************************************************************
* 描 述 : main函數(shù)
* 入 參 : 無(wú)
* 返回值 : 無(wú)
***********************************************************************************************/
int main(void)
{
int16_t AccValue[3],GyroValue[3];
uint8_t id;
nrf_gpio_cfg_output(LED_1);//配置管腳P0.17為輸出,驅(qū)動(dòng)指示燈D1
nrf_gpio_pin_set(LED_1); //設(shè)置指示燈D1初始狀態(tài)為熄滅
uart_config(); //配置串口,禁止流控,波特率:115200
twi_master_init();
nrf_delay_ms(2000);
while(mpu6050_init(0x68) == false)
{
printf("mpu6050 init fail\r\n");
nrf_delay_ms(500);
}
printf("mpu6050 init ok\r\n");
mpu6050_register_read(0x75U, &id, 1);
printf("mpu6050 id is %d \r\n",id);
while (true)
{
MPU6050_ReadAcc( &AccValue[0], &AccValue[1] , &AccValue[2] );
MPU6050_ReadGyro(&GyroValue[0] , &GyroValue[1] , &GyroValue[2] );
printf("ACC: %d %d %d ",AccValue[0],AccValue[1],AccValue[2]);
printf("GYRO: %d %d %d \r\n",GyroValue[0],GyroValue[1],GyroValue[2]);
nrf_delay_ms(500);
}
}
/********************************************END FILE*******************************************/
復(fù)制代碼
所有資料51hei提供下載:
mpu6050驅(qū)動(dòng).rar
(602.6 KB, 下載次數(shù): 23)
2018-12-11 17:28 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
henryxue
時(shí)間:
2019-8-9 13:26
非常感謝
作者:
henryxue
時(shí)間:
2019-8-9 13:26
非常感謝你的慷慨指導(dǎo)
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1