| 
 
新手入门 
 
	积分32金钱32 注册时间2015-9-20在线时间2 小时 | 
 
5金钱 
| 我先说下我的问题。我做了一个遥控,用到了ADC,NRF24L01和PWM。遥控器采集ADC数据并发送,接收机接收数据并生成PWM波。因为AD转换值是12位,我通过一系列转化,在接受机中将数值转化为我所需要的值来驱动无刷电调,从而驱动电机。但是在控制过程中,NRF24L01发送了一会儿数据突然发送不了了。我不知道是什么原因,求解答。程序如下:(主程序)遥控器: 
 #include "stm32f10x.h"
 #include "24l01.h"
 #include "spi.h"
 #include "adc.h"
 #include "delay.h"
 #include "usart.h"
 int main(void)
 {
 u16 adcx1;
 u8 temp_buf1[2];
 SystemInit ();
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
 delay_init();                     //延时函数初始化
 uart_init(9600);                 //串口初始化为9600
 Adc_Init();                                  //ADC初始化
 printf("ADC初始化完成\r\n");
 NRF24L01_Init();            //初始化NRF24L01
 while(NRF24L01_Check());
 printf("NRF初始化完成\r\n");
 NRF24L01_TX_Mode();
 printf("发送模式\r\n");
 while(1)
 {
 adcx1=Get_Adc_Average(ADC_Channel_0,10);
 printf("adc数据:");
 temp_buf1[0]=(adcx1>>8);
 temp_buf1[1]=(adcx1&0x00ff);
 while(NRF24L01_TxPacket(temp_buf1)!=TX_OK);
 printf("=%d\r\n",adcx1);
 }
 }
 
 
 
 接收机:
 #include "stm32f10x.h"
 #include "spi.h"
 #include "pwm.h"
 #include "24l01.h"
 #include "delay.h"
 int main(void)
 {
 u8 buf1[2];
 u16 a,a1;
 delay_init();                     //延时函数初始化
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 设置中断优先级分组2
 TIM3_PWM_Init(20000,72);
 NRF24L01_Init();            //初始化NRF24L01
 while(NRF24L01_Check());
 NRF24L01_RX_Mode();
 while(1)
 {
 while(NRF24L01_RxPacket(buf1)==0)
 {
 a=(buf1[0]<<8)+buf1[1];
 a1=a/4+800;
 }
 TIM_SetCompare3(TIM3,a1);
 }
 
 }
 
 
 
 
 | 
 |