OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2478|回复: 2

求大佬帮忙看看NRF的主函数

[复制链接]

3

主题

10

帖子

0

精华

初级会员

Rank: 2

积分
53
金钱
53
注册时间
2018-3-21
在线时间
23 小时
发表于 2018-4-11 10:49:55 | 显示全部楼层 |阅读模式
5金钱
会出现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]

最佳答案

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

3

主题

10

帖子

0

精华

初级会员

Rank: 2

积分
53
金钱
53
注册时间
2018-3-21
在线时间
23 小时
 楼主| 发表于 2018-4-11 10:49:56 | 显示全部楼层
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2018-4-12 00:42:34 | 显示全部楼层
仿真找问题
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-9 12:00

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表