基于
STM32
单片机用NFR24L01发射数据和接收数据不一样求大神解决;程序如下:
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "key.h"
#include "spi.h"
#include "24l01.h"
#include "mpu6050.h"
#include "bsp_i2c.h"
//ALIENTEK Mini STM32??·?°?·????ú??24
//?????¨?????é
//?????§????
www.openedv.com
//?????????í??×?????????????
int main(void)
{
short Gyro[4];
short Accel[6];
u8 key,mode;
u16 t=0;
// int16_t x;
u8 tmp_buf[33],tmp[33];
delay_init(); //???±??????????
NVIC_Configura
tion();
uart_init(115200); //?®??????????9600
LED_Init(); //????????LED??????????????
LCD_Init(); //??????LCD
KEY_Init(); //°??ü??????
MPU6050_Init();
i2c_GPIO_Config();
NRF24L01_Init(); //??????NRF24L01
POINT_COLOR=RED;//?è??×??????ì??
LCD_ShowString(60,50,200,16,16,"Mini STM32");
LCD_ShowString(60,70,200,16,16,"NRF24L01 TEST");
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"2014/3/12");
while(NRF24L01_Check()) //?ì?éNRF24L01??·?????.
{
LCD_ShowString(60,130,200,16,16,"NRF24L01 Error");
delay_ms(200);
LCD_Fill(60,130,239,130+16,WHITE);
delay_ms(200);
}
LCD_ShowString(60,130,200,16,16,"NRF24L01 OK");
while(1)//??????·??·?¨????????????!
{
key=KEY_Scan(0);
if(key==KEY0_PRES)
{
mode=0;
break;
}else if(key==KEY1_PRES)
{
mode=1;
break;
}
t++;
if(t==100)LCD_ShowString(10,150,230,16,16,"KEY0:RX_Mode KEY1:TX_Mode"); //?????????á??????
if(t==200)
{
LCD_Fill(10,150,230,150+16,WHITE);
t=0;
}
delay_ms(5);
}
LCD_Fill(10,150,240,166,WHITE);//??????????????
POINT_COLOR=BLUE;//?è??×?????????
if(mode==0)//RX模式
{
LCD_ShowString(60,150,200,16,16,"NRF24L01 RX_Mode");
LCD_ShowString(60,170,200,16,16,"Received DATA:");
NRF24L01_RX_Mode();
while(1)
{
tmp[0]=((int16_t)tmp_buf[0]<<8)+tmp_buf[1];
tmp[1]=((int16_t)tmp_buf[2]<<8)+tmp_buf[3];
tmp[2]=((int16_t)tmp_buf[4]<<8)+tmp_buf[5];
if(NRF24L01_RxPacket(tmp_buf)==0)//???©??????????,?ò????????.
{
printf("
加速度%8dn",tmp[1]);
printf("
加速度%8dn",tmp[2]);
printf(" 陀螺仪 %8dn",tmp[0]);
tmp[32]=0;//加入结束符
LCD_ShowString(0,190,239,32,16,tmp);
}else delay_us(100);
t++;
if(t==10000)//灯延时
{
t=0;
LED0=!LED0;
}
};
}else//TX模式
{
LCD_ShowString(60,150,200,16,16,"NRF24L01 TX_Mode");
NRF24L01_TX_Mode();
mode=' ';//从空格键开始
while(1)
{
MPU6050ReadGyro(Gyro);
tmp_buf[0]=Gyro[2]/256;
tmp_buf[1]=Gyro[2]%256;
MPU6050ReadAcc(Accel);
tmp_buf[2]=Accel[0]/256;
tmp_buf[3]=Accel[0]%256;
tmp_buf[4]=Accel[1]/256;
tmp_buf[5]=Accel[1]%256;
printf(" 加速度%8dn",Accel[0]);
printf("
加速度%8dn",Accel[1]);
printf(" 陀螺仪%8dn",Gyro[2]);
if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
{
tmp_buf[32]=0;//?????á??·?
LCD_ShowString(60,170,239,32,16,"Sended DATA:");
LCD_ShowString(0,190,239,32,16,tmp_buf);
// key=mode;
// for(t=0;t<32;t++)
// {
// key++;
// if(key>('~'))key=' ';
// tmp_buf[t]=key;
// }
// mode++;
// if(mode>'~')mode=' ';
tmp_buf[32]=0;// 加入结束符
}else
{
LCD_ShowString(60,170,239,32,16,"Send Failed ");
LCD_Fill(0,188,240,218,WHITE);//??????????????
};
LED0=!LED0;
delay_ms(1500);
};
}
}
说明:本人想把MPU6050数据直接发送到另一个板子上并且显示出来,红色部分是发送和接收的东西,问题是发送的数据和接受的数据不一样,如下图,本程序是在原子的程序上改的,去掉了一些之前发的东西,
0