初级会员
- 积分
- 67
- 金钱
- 67
- 注册时间
- 2015-5-23
- 在线时间
- 0 小时
|
5金钱
基于STM32单片机用NFR24L01发射数据和接收数据不一样求大神解决;程序如下:<br />
#include "led.h"<br />
#include "delay.h"<br />
#include "sys.h"<br />
#include "usart.h"<br />
#include "lcd.h"<br />
#include "key.h"<br />
#include "spi.h"<br />
#include "24l01.h"<br />
#include "mpu6050.h"<br />
#include "bsp_i2c.h"<br />
//ALIENTEK Mini STM32??·?°?·????ú??24<br />
//?????¨?????é <br />
//?????§????www.openedv.com<br />
//?????????í??×????????????? <br />
<br />
int main(void)<br />
{ <br />
short Gyro[4];<br />
short Accel[6];<br />
u8 key,mode;<br />
u16 t=0; <br />
// int16_t x; <br />
u8 tmp_buf[33],tmp[33]; <br />
delay_init(); //???±?????????? <br />
NVIC_Configuration(); <br />
uart_init(115200); //?®??????????9600<br />
LED_Init(); //????????LED??????????????<br />
LCD_Init(); //??????LCD <br />
KEY_Init(); //°??ü??????<br />
MPU6050_Init();<br />
i2c_GPIO_Config();<br />
NRF24L01_Init(); //??????NRF24L01 <br />
POINT_COLOR=RED;//?è??×??????ì?? <br />
LCD_ShowString(60,50,200,16,16,"Mini STM32"); <br />
LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST"); <br />
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");<br />
LCD_ShowString(60,110,200,16,16,"2014/3/12"); <br />
while(NRF24L01_Check()) //?ì?éNRF24L01??·?????. <br />
{<br />
LCD_ShowString(60,130,200,16,16,"NRF24L01 Error");<br />
delay_ms(200);<br />
LCD_Fill(60,130,239,130+16,WHITE);<br />
delay_ms(200);<br />
} <br />
LCD_ShowString(60,130,200,16,16,"NRF24L01 OK");<br />
while(1)//??????·??·?¨????????????!<br />
{<br />
key=KEY_Scan(0);<br />
if(key==KEY0_PRES)<br />
{<br />
mode=0; <br />
break;<br />
}else if(key==KEY1_PRES)<br />
{<br />
mode=1;<br />
break;<br />
}<br />
t++;<br />
if(t==100)LCD_ShowString(10,150,230,16,16,"KEY0:RX_Mode KEY1:TX_Mode"); //?????????á??????<br />
if(t==200)<br />
{ <br />
LCD_Fill(10,150,230,150+16,WHITE);<br />
t=0; <br />
}<br />
delay_ms(5); <br />
} <br />
LCD_Fill(10,150,240,166,WHITE);//?????????????? <br />
POINT_COLOR=BLUE;//?è??×????????? <br />
<br />
<br />
if(mode==0)//RX模式<br />
{<br />
LCD_ShowString(60,150,200,16,16,"NRF24L01 RX_Mode"); <br />
LCD_ShowString(60,170,200,16,16,"Received DATA:"); <br />
NRF24L01_RX_Mode(); <br />
while(1)<br />
{ <br />
<span style="background-color:#E53333;"> tmp[0]=((int16_t)tmp_buf[0]<<8)+tmp_buf[1];</span><br />
<span style="background-color:#E53333;"> tmp[1]=((int16_t)tmp_buf[2]<<8)+tmp_buf[3];</span><br />
<span style="background-color:#E53333;"> </span><span style="background-color:#E53333;">tmp[2]=((int16_t)tmp_buf[4]<<8)+tmp_buf[5];</span><br />
<br />
<br />
<br />
<br />
if(NRF24L01_RxPacket(tmp_buf)==0)//???©??????????,?ò????????.<br />
{<br />
<br />
<br />
<br />
printf(" <span>加速度</span>%8d\n",tmp[1]);<br />
printf(" <span>加速度</span>%8d\n",tmp[2]);<br />
printf(" 陀螺仪 %8d\n",tmp[0]);<br />
<br />
tmp[32]=0;//加入结束符<br />
LCD_ShowString(0,190,239,32,16,tmp); <br />
}else delay_us(100); <br />
t++;<br />
if(t==10000)//灯延时<br />
{<br />
t=0;<br />
LED0=!LED0;<br />
} <br />
}; <br />
}else//TX模式<br />
{ <br />
LCD_ShowString(60,150,200,16,16,"NRF24L01 TX_Mode"); <br />
NRF24L01_TX_Mode();<br />
mode=' ';//从空格键开始<br />
while(1)<br />
{ <br />
<br />
<br />
<span style="background-color:#E53333;"> MPU6050ReadGyro(Gyro);</span><br />
<span style="background-color:#E53333;"> </span><br />
<span style="background-color:#E53333;"> tmp_buf[0]=Gyro[2]/256;</span><br />
<span style="background-color:#E53333;"> tmp_buf[1]=Gyro[2]%256;</span><br />
<br />
<br />
<span style="background-color:#E53333;"> MPU6050ReadAcc(Accel);</span><br />
<br />
<span style="background-color:#E53333;"> tmp_buf[2]=Accel[0]/256;</span><br />
<span style="background-color:#E53333;"> </span><span style="background-color:#E53333;">tmp_buf[3]=Accel[0]%256;</span><br />
<br />
<br />
<span style="background-color:#E53333;"> tmp_buf[4]=Accel[1]/256;</span><br />
<span style="background-color:#E53333;"> tmp_buf[5]=Accel[1]%256;</span><br />
<br />
<span style="background-color:#E53333;"> </span><br />
printf(" 加速度%8d\n",Accel[0]);<br />
printf(" <span>加速度</span>%8d\n",Accel[1]);<br />
printf(" 陀螺仪%8d\n",Gyro[2]); <br />
<br />
if(NRF24L01_TxPacket(tmp_buf)==TX_OK)<br />
{<br />
<br />
<br />
<br />
<br />
tmp_buf[32]=0;//?????á??·?<br />
LCD_ShowString(60,170,239,32,16,"Sended DATA:"); <br />
LCD_ShowString(0,190,239,32,16,tmp_buf); <br />
<br />
<br />
// key=mode;<br />
// for(t=0;t<32;t++)<br />
// {<br />
// key++;<br />
// if(key>('~'))key=' ';<br />
// tmp_buf[t]=key; <br />
// }<br />
// mode++; <br />
// if(mode>'~')mode=' '; <br />
tmp_buf[32]=0;// 加入结束符<br />
}else<br />
{ <br />
LCD_ShowString(60,170,239,32,16,"Send Failed "); <br />
LCD_Fill(0,188,240,218,WHITE);//?????????????? <br />
};<br />
LED0=!LED0;<br />
delay_ms(1500); <br />
};<br />
} <br />
}<br />
<br />
说明:本人想把MPU6050数据直接发送到另一个板子上并且显示出来,红色部分是发送和接收的东西,问题是发送的数据和接受的数据不一样,如下图,本程序是在原子的程序上改的,去掉了一些之前发的东西,<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="background-color:#E53333;"></span><br /> |
最佳答案
查看完整内容[请看2#楼]
short Gyro[4];
short Accel[6]; 这都是短整型数据只会把1个字节的数据给tmp_buf[t] 要是你是16位的数据 那么没处理好的话只会把低八位的数据给tmp_buf[t] 我是这么理解的
|