nrf51822源程序如下:
- /****************************************Copyright (c)****************************************************
- **
- **
- **
- **--------------File Info---------------------------------------------------------------------------------
- ** File name: main.c
- ** Last modified Date:
- ** Last Version:
- ** Descriptions: 使用的SDK版本-SDK_12.0.0
- **
- **--------------------------------------------------------------------------------------------------------
- ** Created by: 青風電子
- ** Descriptions: MPU6050原始數據讀取實驗
- **--------------------------------------------------------------------------------------------------------*/
- #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"
- /* 開發板中MPU6050模塊和串口占用的nRF52832管腳資源
- P0.06:UART_TXD :串口發送
- P0.08:UART_RXD :串口接收
- P0.07:UART_CTS : 未使用流控
- P0.05:UART_RTS : 未使用流控
- 串口需要短接對應的跳線帽
- P0.22:IIC時鐘
- P0.23:IIC數據
- */
- #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,流控關閉
- * 參 數 : 無
- * 返回值 : 無
- ******************************************************************************/
- 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, //關閉流控
- false,
- UART_BAUDRATE_BAUDRATE_Baud115200 //波特率設置為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函數
- * 入 參 : 無
- * 返回值 : 無
- ***********************************************************************************************/
- int main(void)
- {
- int16_t AccValue[3],GyroValue[3];
- uint8_t id;
-
- nrf_gpio_cfg_output(LED_1);//配置管腳P0.17為輸出,驅動指示燈D1
- nrf_gpio_pin_set(LED_1); //設置指示燈D1初始狀態為熄滅
-
- 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*******************************************/
復制代碼
所有資料51hei提供下載:
mpu6050驅動.rar
(602.6 KB, 下載次數: 23)
2018-12-11 17:28 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|