会出现0或者乱码 有大佬帮忙看看为什么吗
还有这个MPU数据有时候会没有
主机的
[mw_shl_code=c,true]#include "led.h"
#include "delay.h"
#include "sys.h"
#include "mpu6050.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h"
#include "oled.h"
#include "24l01.h"
int main(void)
{
u8 tmp_buf[33];
short temp1,temp2,temp3;
float pitch,roll,yaw;
short aacx,aacy,aacz;
short gyrox,gyroy,gyroz;
delay_init();
LED_Init();
MPU_Init();
OLED_Init();
OLED_Clear();
NRF24L01_Init();
NVIC_Configuration();
OLED_ShowString(60,0,"OK");
if((NRF24L01_Check()==0))
{
if(mpu_dmp_init()==0)
{
LED0=!LED0;
}
}
/*while(mpu_dmp_init())
{
LED1=!LED1;
}*/
NRF24L01_TX_Mode();
if(mpu_dmp_get_data(&pitch,&roll,&yaw))
{
LED1=!LED1;
while(1)
{
//temp1=MPU_Get_Temperature();
MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz);
temp1=temp1/100;
temp2=pitch;
temp3=yaw;
tmp_buf[0]=temp1/256;
tmp_buf[1]=temp1%256;
tmp_buf[2]=temp2/256;
tmp_buf[3]=temp2%256;
tmp_buf[4]=temp3/256;
tmp_buf[5]=temp3%256;
tmp_buf[6]='a';
tmp_buf[32]=0;
OLED_ShowNum(0,2,temp2,3,16);
if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
{
OLED_ShowNum(0,20,temp2,3,16);
tmp_buf[32]=0;
delay_ms(200);
}
}
}
}
从机的
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "24l01.h"
#include "oled.h"
#include "timer.h"
#include "ultrasonic.h"
#include "oled.h"
#include "lcd.h"
int main(void)
{
u8 tmp_buf[33];
int short temp1,temp2,temp3;
delay_init();
LED_Init();
OLED_Init();
OLED_Clear() ;
NRF24L01_Init();
NVIC_Configuration();
Timer_SRD_Init(5000,7199);
ULTRASONIC_Init();
/*OLED_ShowString(0,0,"MPU:");
OLED_ShowString(0,2,"TEMP:");
OLED_ShowString(0,4,"PITCH:");
OLED_ShowString(0,6,"YAW:");*/
OLED_ShowString(60,0,"OK");
if(NRF24L01_Check())
{
OLED_ShowString(60,2,"OK1");
NRF24L01_RX_Mode();
while(1)
{
OLED_ShowString(60,4,"OK2");
if(NRF24L01_RxPacket(tmp_buf)==0)
{
tmp_buf[32]=0;
temp1=((int16_t)tmp_buf[0]<<8)+tmp_buf[1];
temp2=((int16_t)tmp_buf[2]<<8)+tmp_buf[3];
temp3=((int16_t)tmp_buf[4]<<8)+tmp_buf[5];
OLED_ShowChar(30,0,tmp_buf[6]);
OLED_ShowString(60,6,"OK3");
if(temp1<0)
{
OLED_ShowChar(0,2,13);
temp1=-temp1;
}
else
OLED_ShowNum(20,2,temp1,3,12);
if(temp2<0)
{
OLED_ShowChar(0,4,13);
temp2=-temp2;
}
else
OLED_ShowNum(20,4,temp2,3,12);
if(temp3<0)
{
OLED_ShowChar(0,6,13);
temp3=-temp3;
}
else
OLED_ShowNum(20,6,temp3,3,12);
}
}
}
}
[/mw_shl_code]
|