中级会员
 
- 积分
- 235
- 金钱
- 235
- 注册时间
- 2019-7-8
- 在线时间
- 27 小时
|
1金钱
我用C8T6的最小系统板接MPU6050单独测试的时候没有问题,用匿名四轴上位机也能正常显示波形和飞控状态,但是把它和NRF的程序融合在一起的时候就不行了,把C8T6上的MPU6050数据通过NRF传给ZET6用触摸屏显示出来的TEMP,ROLL,PITCH,YAW值全部为0,接线应该没有问题,模块代码也基本上是copy原子哥的例程,就是把NRF的PG678引脚改成了PB678引脚,方便接在C8T6上,下面是主函数,请大家帮忙看看:#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
#include "led.h"
#include "mpu6050.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h"
#include "24l01.h"
//′®¿ú1·¢Ëí1¸ö×Ö·û
//c:òa·¢ËíμÄ×Ö·û
void usart1_send_char(u8 c)
{
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); //Ñ-»··¢Ëí,Ö±μ½·¢Ëííê±Ï
USART_SendData(USART1,c);
}
//′«Ëíêy¾Y¸øÄäÃûËÄÖáéÏλ»úèí¼t(V2.6°æ±¾)
//fun:1|Äü×Ö. 0XA0~0XAF
//data:êy¾Y»o′æÇø,×î¶à28×Ö½ú!!
//len:dataÇøóDD§êy¾Y¸öêy
void usart1_niming_report(u8 fun,u8*data,u8 len)
{
u8 send_buf[32];
u8 i;
if(len>28)return; //×î¶à28×Ö½úêy¾Y
send_buf[len+3]=0; //D£ÑéêyÖÃáã
send_buf[0]=0X88; //Ö¡í·
send_buf[1]=fun; //1|Äü×Ö
send_buf[2]=len; //êy¾Y3¤¶è
for(i=0;i<len;i++)send_buf[3+i]=data[i]; //¸′ÖÆêy¾Y
for(i=0;i<len+3;i++)send_buf[len+3]+=send_buf[i]; //¼ÆËãD£Ñéoí
for(i=0;i<len+4;i++)usart1_send_char(send_buf[i]); //·¢Ëíêy¾Yμ½′®¿ú1
}
//·¢Ëí¼óËù¶è′«¸DÆ÷êy¾YoííóÂYòÇêy¾Y
//aacx,aacy,aacz:x,y,zèy¸ö·½ÏòéÏÃæμļóËù¶èÖμ
//gyrox,gyroy,gyroz:x,y,zèy¸ö·½ÏòéÏÃæμÄíóÂYòÇÖμ
void mpu6050_send_data(short aacx,short aacy,short aacz,short gyrox,short gyroy,short gyroz)
{
u8 tbuf[12];
tbuf[0]=(aacx>>8)&0XFF;
tbuf[1]=aacx&0XFF;
tbuf[2]=(aacy>>8)&0XFF;
tbuf[3]=aacy&0XFF;
tbuf[4]=(aacz>>8)&0XFF;
tbuf[5]=aacz&0XFF;
tbuf[6]=(gyrox>>8)&0XFF;
tbuf[7]=gyrox&0XFF;
tbuf[8]=(gyroy>>8)&0XFF;
tbuf[9]=gyroy&0XFF;
tbuf[10]=(gyroz>>8)&0XFF;
tbuf[11]=gyroz&0XFF;
usart1_niming_report(0XA1,tbuf,12);//×Ô¶¨òåÖ¡,0XA1
}
//í¨1y′®¿ú1éϱ¨½áËãoóμÄ×Ëì¬êy¾Y¸øμçÄÔ
//aacx,aacy,aacz:x,y,zèy¸ö·½ÏòéÏÃæμļóËù¶èÖμ
//gyrox,gyroy,gyroz:x,y,zèy¸ö·½ÏòéÏÃæμÄíóÂYòÇÖμ
//roll á1ö½Ç.μ¥λ0.01¶è¡£ -18000 -> 18000 ¶Ôó| -180.00 -> 180.00¶è
//pitch:¸©Ñö½Ç.μ¥λ 0.01¶è¡£-9000 - 9000 ¶Ôó| -90.00 -> 90.00 ¶è
//yaw ½Ïò½Ç.μ¥λÎa0.1¶è 0 -> 3600 ¶Ôó| 0 -> 360.0¶è
void usart1_report_imu(short aacx,short aacy,short aacz,short gyrox,short gyroy,short gyroz,short roll,short pitch,short yaw)
{
u8 tbuf[28];
u8 i;
for(i=0;i<28;i++)tbuf[i]=0;//Çå0
tbuf[0]=(aacx>>8)&0XFF;
tbuf[1]=aacx&0XFF;
tbuf[2]=(aacy>>8)&0XFF;
tbuf[3]=aacy&0XFF;
tbuf[4]=(aacz>>8)&0XFF;
tbuf[5]=aacz&0XFF;
tbuf[6]=(gyrox>>8)&0XFF;
tbuf[7]=gyrox&0XFF;
tbuf[8]=(gyroy>>8)&0XFF;
tbuf[9]=gyroy&0XFF;
tbuf[10]=(gyroz>>8)&0XFF;
tbuf[11]=gyroz&0XFF;
tbuf[18]=(roll>>8)&0XFF;
tbuf[19]=roll&0XFF;
tbuf[20]=(pitch>>8)&0XFF;
tbuf[21]=pitch&0XFF;
tbuf[22]=(yaw>>8)&0XFF;
tbuf[23]=yaw&0XFF;
usart1_niming_report(0XAF,tbuf,28);//·é¿ØÏÔê¾Ö¡,0XAF
}
int main(void)
{
u8 report=1; //ĬèÏ¿aÆôéϱ¨
u8 tmp_buf[33];
float pitch,roll,yaw; //Å·à-½Ç
short aacx,aacy,aacz; //¼óËù¶è′«¸DÆ÷Ô-ê¼êy¾Y
short gyrox,gyroy,gyroz; //íóÂYòÇÔ-ê¼êy¾Y
short temp; //릏
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏè¼¶£¬2λÏìó|óÅÏè¼¶
uart_init(500000); //′®¿ú3õê¼»ˉÎa500000
delay_init(); //Ñóê±3õê¼»ˉ
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
MPU_Init(); //3õê¼»ˉMPU6050
NRF24L01_Init();
/*u16 led0pwmval=0;
u16 a=17000;
u8 dir=1;
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏè¼¶£¬2λÏìó|óÅÏè¼¶
uart_init(115200); //′®¿ú3õê¼»ˉÎa115200
LED_Init(); //LED¶Ë¿ú3õê¼»ˉ
TIM3_PWM_Init(19999,71); // 72·ÖÆμ£¬×î¸ßÆμÂê20000
while(1)
{
delay_ms(500);
if(dir)led0pwmval+=500;
else led0pwmval-=500;
if(led0pwmval>18000)dir=0;
if(led0pwmval==0)dir=1;
a+=500;
if(a>19500) a=17500;
TIM_SetCompare2(TIM3,a); //òÔ45¡ãÎa»ù±¾×a¶ˉμ¥λ
LED0=!LED0;
delay_ms(200);
} */
while(mpu_dmp_init()&&NRF24L01_Check())
{
//LED0=!LED0;
delay_ms(200);
}
while(1)
{
NRF24L01_TX_Mode();
if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)
{
temp=MPU_Get_Temperature(); //μÃμ½Î¶èÖμ
MPU_Get_Accelerometer(&aacx,&aacy,&aacz); //μÃμ½¼óËù¶è′«¸DÆ÷êy¾Y
MPU_Get_Gyroscope(&gyrox,&gyroy,&gyroz); //μÃμ½íóÂYòÇêy¾Y
if(report)mpu6050_send_data(aacx,aacy,aacz,gyrox,gyroy,gyroz);//óÃ×Ô¶¨òåÖ¡·¢Ëí¼óËù¶èoííóÂYòÇÔ-ê¼êy¾Y
if(report)usart1_report_imu(aacx,aacy,aacz,gyrox,gyroy,gyroz,(int)(roll*100),(int)(pitch*100),(int)(yaw*10));
//LED0=!LED0;
//delay_ms(200);
}
tmp_buf[0]=temp/1000+'0';
tmp_buf[1]=temp/100%10+'0';
tmp_buf[2]=temp/10%10+'0';
tmp_buf[3]=temp%10+'0';
//temp=pitch*10;
if(temp<0)
{
temp=-temp;
tmp_buf[4]='-';
}
else
tmp_buf[4]='+';
//tmp_buf[5]=temp/100+'0';
//tmp_buf[6]=temp/10%10+'0';
NRF24L01_TxPacket(tmp_buf);
LED0=!LED0;
delay_ms(200);
}
}
|
|