The works used are based on the SDK10 engineering
In the nrf51_sdk_10.0.0_dc26b5e\examples\peripheral\twi_sensor will be used as the template
Modify Code MAIN.C
1#include <stdio.h>2#include"Boards.h"3#include"app_util_platform.h"4#include"App_error.h"5#include"nrf_drv_twi.h"6#include"Nrf_delay.h"7#include"mpu6050.h"8#include"Twi_master.h"9#include"segger_rtt.h"Ten One /** A * @brief Function for main application entry. - */ - intMainvoid) the { - uint8_t ID; - Twi_master_init (); - +segger_rtt_printf (0,"mpu6050 test\r\n"); -segger_rtt_printf (0,"mpu6050 Address 0x68\r\n"); + if(Mpu6050_init (0x68) ==false) A { atsegger_rtt_printf (0,"mpu6050 Init fail\r\n"); - } -Mpu6050_register_read (0x75u, &id,1); -segger_rtt_printf (0,"mpu6050 ID is%02x \ r \ n", id); - -segger_rtt_printf (0,"mpu6050 Address 0x69\r\n"); in if(Mpu6050_init (0x69) ==false) - { tosegger_rtt_printf (0,"mpu6050 Init fail\r\n"); + } -Mpu6050_register_read (0x75u, &id,1); thesegger_rtt_printf (0,"mpu6050 ID is%02x \ r \ n", id); * $ while(true)Panax Notoginseng { - } the}
Note: When the mpu_ad0 is dangling/connected to GND, the IIC slave address of the module is: 0X68; When the mpu_ad0 is connected to VCC, the IIC slave address of the module is: 0X69.
Why write more a 0x69, is because the actual test found PIN8 and PIN9 short-circuit ... So the baby's heart is bitter not to say.
Need to add files
.. \.. \.. \.. \.. \components\drivers_ext\mpu6050\mpu6050.c
.. \.. \.. \.. \.. \components\drivers_nrf\twi_master\deprecated\twi_sw_master.c
Add header File
.. \.. \.. \.. \.. \components\drivers_ext\mpu6050
.. \.. \.. \.. \.. \components\drivers_nrf\twi_master\deprecated
.. \.. \.. \.. \.. \components\drivers_nrf\twi_master\deprecated\config
Finally, according to their own circuit modification twi_master_config
#ifndef twi_master_config #define Twi_master_config#define TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER (10U) #define Twi_master_config_data_pin_number (9U )#endif
Output results
NRF51822 's Simulated IIC