Esempio n. 1
0
void send256(void)
{
	u8 i;
	tbuf[0] = 0x55;
	tbuf[1] = 0xaa;
	NRF24L01_TxPacket(tbuf);
	delay(10);
	for (i = 0; i < 8; i++)
		NRF24L01_TxPacket(LED_Buf[i]);
}
Esempio n. 2
0
//Send a packet and receive the ACK
//Return true in case of success.
//Polling implementation
unsigned char NRF24L01_SendPacket(char *payload, char len, char *ackPayload, char *ackLen)
{
  char status = 0;
  
  //Send the packet
  NRF24L01_TxPacket(payload, len);
  //Wait for something to happen
  while(((status=NRF24L01_Nop())&0x70) == 0);
  
  // Clear the flags
  NRF24L01_WriteReg(REG_STATUS, 0x70);
  
  //Return FALSE if the packet has not been transmited
  if (status&BIT_MAX_RT) {
    NRF24L01_FlushTx();
    return 0;
  }
    
  //Receive the ackPayload if any has been received
  if (status&BIT_RX_DR)
    *ackLen = NRF24L01_RxPacket(ackPayload);
  else 
    *ackLen = 0;
  
  NRF24L01_FlushRx();
  
  return status&BIT_TX_DS;
}
Esempio n. 3
0
void Data_Send_Voltage(T_RC_Voltage *data)
{
	rt_uint8_t _cnt=0;
	data_to_send[_cnt++]=0XAA;
	data_to_send[_cnt++]=0xAA;
	data_to_send[_cnt++]=0x05;//µçѹ¹¦ÄÜ×Ö
	data_to_send[_cnt++]=0;
	
	rt_uint16_t _temp;//µçѹ¿Ï¶¨ÎªÕý
	_temp = data->Voltage1*100;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	_temp = data->Voltage2*100;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);	
	
	_temp =  data->Voltage3*100;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	data_to_send[3] = _cnt-4;
	
	
	rt_uint8_t sum = 0;
	for(rt_uint8_t i=0;i<_cnt;i++)
		sum += data_to_send[i];
	data_to_send[_cnt++]=sum;
	
	NRF24L01_TxPacket(data_to_send);
	
}
Esempio n. 4
0
int main(void)
 {	 
	u8 R='b';		
	delay_init(72);	    	 //延时函数初始化	  
	usart1_init();	 	//串口初始化
 	NRF24L01_Init();    	//初始化NRF24L01 
	LED();	  
 	while(NRF24L01_Check());	//检查NRF24L01是否在位.	
	
 	while(1)
	{
		NRF24L01_TX_Mode();
		if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE))
		{
			R =USART_ReceiveData(USART1);
			USART_ClearFlag(USART1, USART_FLAG_TC);		
			USART_SendData(USART1, USART_ReceiveData(USART1));
			USART_ClearFlag(USART1, USART_FLAG_RXNE);				
		}  
		NRF24L01_TxPacket(&R);  	
		if(R=='a')
		GPIO_ResetBits(GPIOE, GPIO_Pin_5); //PE=0,LED亮
		if(R=='b')
		GPIO_SetBits(GPIOE, GPIO_Pin_5); //PE=1,LED灭		
	}
}
void nrf24l01_send_ack(void)
{
	uint8_t buffer[TX_PLOAD_WIDTH] = {0};
	buffer[0] = NRF_ACK;
	nrf_state = TX_OK;
	NRF24L01_TxPacket(buffer);
}
void rf1send(rt_uint8_t * str)
{ 
      rt_kprintf("\r\n \r\n"); 
      TX_Mode();
      rt_kprintf("\r\n RF1 发送数据:%s \r\n", str); 
      NRF24L01_TxPacket(str);
      RX_Mode();
}
Esempio n. 7
0
void main()
{	
  	while(1)
	{
	    init_NRF24L01();
	  	CE=1;
	    NRF24L01_TxPacket(Txbuf);
	    Delay_ms(10);
		check_ACK();//发送应答信号检测,LED闪烁标志发送成功  
	}				
}
Esempio n. 8
0
//发送数据包, 发送完成后自动返回监听自己的通道
//0,ok;1,err
 u8 send_pkt(pkt_t * pkt)
{
    u32 t;
    u8 res;
    TX_Mode(&ch);//准备发射//130us
    t = systick;
    do {
        res = NRF24L01_TxPacket((u8 *)pkt);//发送数据 //发送次数超限用时10.7ms//发送成功830us
    }while(res != TX_DS && (systick - t < 10));//20ms内不停尝试//5us 
    RX_Mode(&mych);//最后返回接收模式//100us
    return (res != TX_DS);
}
Esempio n. 9
0
void Data_Send_Senser(T_RC_Sensor *data)
{
	rt_uint8_t _cnt=0;
	data_to_send[_cnt++]=0XAA;
	data_to_send[_cnt++]=0xAA;
	data_to_send[_cnt++]=0x02;
	data_to_send[_cnt++]=0;
	
	rt_int16_t _temp;
	_temp = data->ACC.X;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	_temp = data->ACC.Y;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	_temp = data->ACC.Z;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	_temp = data->GYR.X;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	_temp = data->GYR.Y;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	_temp = data->GYR.Z;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);

	_temp = data->MAG.X;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	_temp = data->MAG.Y;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	_temp = data->MAG.Z;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	data_to_send[3] = _cnt-4;
	
	rt_uint8_t sum = 0;
	for(rt_uint8_t i=0;i<_cnt;i++)
		sum += data_to_send[i];
	data_to_send[_cnt++]=sum;
	
	NRF24L01_TxPacket(data_to_send);
	
	
}
//todo
void nrf24l01_send_position(Point pos)
{
	uint8_t buffer[TX_PLOAD_WIDTH];
	uint32_t posx = pos.x*1000+0.5f;
	uint32_t posy = pos.y*1000+0.5f;
	buffer[0] = posx>>24;
	buffer[1] = posx>>16;
	buffer[2] = posx>>8;
	buffer[3] = posx;
	buffer[4] = posy>>24;
	buffer[5] = posy>>16;
	buffer[6] = posy>>8;
	buffer[7] = posy;
	
	nrf_state = TX_OK;
	NRF24L01_TxPacket(buffer);
}
Esempio n. 11
0
void Data_Send_Status(T_RC_Status *data)
{
	rt_uint8_t _cnt=0;
	data_to_send[_cnt++]=0XAA;
	data_to_send[_cnt++]=0xAA;
	data_to_send[_cnt++]=0x01;
	data_to_send[_cnt++]=0;
	
	rt_int16_t _temp;
	_temp =  data->ANGLE.rol*100;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	_temp =  data->ANGLE.pit*100;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	_temp =  data->ANGLE.yaw*100;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	_temp = data->ALT_CSB;
	data_to_send[_cnt++]=BYTE1(_temp);
	data_to_send[_cnt++]=BYTE0(_temp);
	
	data_to_send[_cnt++]=BYTE3(data->ALT_PRS);
	data_to_send[_cnt++]=BYTE2(data->ALT_PRS);	
	data_to_send[_cnt++]=BYTE1(data->ALT_PRS);
	data_to_send[_cnt++]=BYTE0(data->ALT_PRS);
	
	if(data->ARMED==0)			
		data_to_send[_cnt++]=0xA0;	//Ëø¶¨
	else if(data->ARMED==1)		
		data_to_send[_cnt++]=0xA1;

	data_to_send[3] = _cnt-4;
	
	rt_uint8_t sum = 0;
	for(rt_uint8_t i=0;i<_cnt;i++)
		sum += data_to_send[i];
	data_to_send[_cnt++]=sum;
	
	NRF24L01_TxPacket(data_to_send);
}
Esempio n. 12
0
//任务0
void KEY0_TASK()
{
    u8 key,mode;
    u16 t=0;
    u8 tmp_buf[33];

    u8 key_buf[33] = "key0_pres";


    LCD_Clear(WHITE);
    Show_Str(50,50,200,24,"当前任务0 :",24,0);

    NRF24L01_TX_Mode();
    mode=' ';//从空格键开始

    //
    while(1)
    {
        if(NRF24L01_TxPacket(tmp_buf)==TX_OK)
        {
            LCD_ShowString(30,170,239,32,16,"Sended DATA:");
            LCD_ShowString(0,190,lcddev.width-1,32,16,tmp_buf);
            for(t=0; t<32; t++)
            {

                tmp_buf[t]=key_buf[t];
            }
            tmp_buf[32]=0;//加入结束符
        }
        else
        {
            LCD_Fill(0,170,lcddev.width,170+16*3,WHITE);//清空显示
            LCD_ShowString(30,170,lcddev.width-1,32,16,"Send Failed ");
        }
        LED0=!LED0;
        delay_ms(1500);
    }
}
Esempio n. 13
0
void main( void )
{

  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;
  button_init();
  led_init();
  Clock_Init();
  NRF24L01_init(1,1);
  NRF24L01_ConfigMode(MODETX);
  NRF24L01_TxPacket(temp);
  NRF24L01_ConfigMode(MODERX);
  while(1)
  {
    LPM3;  

    //SMG_Display(rece_buf[0]);
    led1_on(0);
    Delay_ms(300);
    led1_off(0);
    Delay_ms(300);
  }
}
Esempio n. 14
0
void TIM4_IRQHandler(void)		//1ms中断一次,用于程序读取6050等
{
    if( TIM_GetITStatus(TIM4 , TIM_IT_Update) != RESET ) 
    {     
     Ledcounter++;
      
     if(Ledcounter==59)Led1=1;
     if(Ledcounter==60){Led1=0;Ledcounter=0;}
     

      TxBuf[0]=(Throttle*10)&0xff;
      TxBuf[1]=((Throttle*10)>>8);     //油门量装入待发送数组的前两个字节
      TxBuf[2]=Pitch;                  //俯仰角装入第3个字节
      TxBuf[3]=Roll;                   //横滚角转入第4个字节
      TxBuf[4]=Yaw;                    //偏航角装入第5个字节
      TxBuf[31]=(Throttle<=5) ? 0:0xA5;//紧急熄火标志字节控制     
      NRF24L01_TxPacket(TxBuf);	//数据包发送,最大重发次数15次
     
     
      TIM_ClearITPendingBit(TIM4 , TIM_FLAG_Update);   //清除中断标志  
      
        
        
    } 
Esempio n. 15
0
//触摸画板功能演示函数   
void Wireless_Play(void)
{				  	
	u8 err=0,i;		 
	u8 key;	 
	u8 mode;//24L01的模式设置
	u8 tmp_buf[5];//低4个字节,传递坐标值,最高一个字节:0,正常画图,1清除;2,退出;  
	  
	mode=Wireless_Mode_Set();
	if(mode==0)
	{
		SPIx_Init();//设置回原来的				 
		SPIx_SetSpeed(SPI_SPEED_4);//18Mhz 
		return;//24L01检测失败,直接退出
	}	 			
	if(mode==2)
	{			    
		Load_Gui_Show("清除","发送","返回");//加载界面 
		TX_Mode();//发送模式
	}else
	{
		Load_Gui_Show("清除","接收","返回");//加载界面 
		RX_Mode();//接收模式
	}
	LCD_Fill(0,0,240,296,LGRAY);//填充灰色 
	POINT_COLOR=BLUE;//设置字体为蓝色  	 
	while(1)
	{	  		   				 
		key=AI_Read_TP(20);//得到触点的状态
		if(mode==1)//接收模式
		{
			if(NRF24L01_RxPacket(tmp_buf)==0)//一旦接收到信息,则显示出来.
			{
				Pen_Point.X=tmp_buf[0];
				Pen_Point.X=(Pen_Point.X<<8)+tmp_buf[1];
 				Pen_Point.Y=tmp_buf[2];
				Pen_Point.Y=(Pen_Point.Y<<8)+tmp_buf[3];
				switch(tmp_buf[4])
				{
					case 0://正常画点
						Draw_Big_Point(Pen_Point.X,Pen_Point.Y);//画点
						break;
					case 1://清除
						LCD_Fill(0,0,240,296,LGRAY);//填充灰色
						break;
					case 2://退出
						Pen_Point.Key_Reg=0;//清除笔状态
						SPIx_Init();//设置回原来的				 
						SPIx_SetSpeed(SPI_SPEED_4);//18Mhz 
						return; 
				}	  
			}
		}
		if(key)//触摸屏被按下						  
		{	
			Pen_Point.Key_Reg|=0x80;//标记按下了按键    
			if(Pen_Point.Y<296&&mode==2)//在画图区域内,且为发送模式
			{
				tmp_buf[0]=Pen_Point.X>>8;
				tmp_buf[1]=Pen_Point.X&0xFF;
				tmp_buf[2]=Pen_Point.Y>>8;	 
				tmp_buf[3]=Pen_Point.Y&0xFF; 
				tmp_buf[4]=0;//功能为0,正常画图  
				Draw_Big_Point(Pen_Point.X,Pen_Point.Y);//画点
				err=0;	      
				while(NRF24L01_TxPacket(tmp_buf)!=TX_OK)//等待发送完成
				{
					err++;
					if(err>10)return;//连续超过10次错误,则返回
				}
			}      
		}else if(Pen_Point.Key_Reg&0X80)//按键松开了 
Esempio n. 16
0
void main()			   
{													  
	uchar shujv[8];		
	uchar stop=0;
	uchar cejv=1; 
	uchar flag=0;
	uchar helpcejv=0;	 
	init_io();
	led0=1;led1=1;ledk=1; 
	while(NRF_Check())	 
	{
		led0=0;
		delayms(1000);
		led0=1;
		delayms(1000);								  
	}	
	TX_Mode();		   //设置为发送模式
	/*************自己加的***********************/
	while(CNRF_Check())	 //检查nrf是否存在
	{
		led0=0;
		delayms(1000);
		led0=1;
		delayms(1000);								  
	}	
	CTX_Mode();
	/*************自己加的***********************/
	stop=byte_read(0x2000);		//读取上一次保留的值
	while(1)
	{
			wenshi(shujv); //写入前4个数据
		//	yali(shujv);//写入第5个数据
		//	shache(shujv);//写入第六个数据
	Get_weight();
	if (weight_shiwu/1000<=5)
	shujv[4]='0';
	else shujv[4]='1';


	if(stop==0)		 
		shujv[5]='1';
	if(stop==1)		 
		shujv[5]='0';
		if(out==0)	
		shujv[6]='1';
		else	
		shujv[6]='0';

		//////////////////////////////
			if(NRF24L01_TxPacket(shujv)==TX_OK)	
			{
				led1=0;
				delayms(300);
				led1=1;
				delayms(10);
				/////
				flag=1;
			}
			else flag=0;

	   //////////////////////////////
			if(flag==1)
			{
				if(CNRF24L01_TxPacket(shujv)==TX_OK)	
				{
					led3=0;
					delayms(300);
					led3=1;
					delayms(10);
					cejv=0;		
					helpcejv=0;
				}	
				else  
				{
					helpcejv++;
					delayms(100);
					if(helpcejv>2)
					{  			led2=0;
								delayms(300);
								led2=1;
								delayms(10);
						cejv=0;
						helpcejv=0;	
					}		 
				}
			/////////////////////////////////////////////////
							
			if(shache(cejv,stop)==1)	
			{
					led0=0;
					delayms(300);
					led0=1;
					delayms(10);
			stop=1;							  
			SectorErase(0x2000);
			byte_write(0x2000,stop);
			}
			if(checkbutton(cejv,stop)==0)
			{stop=1;
						
			SectorErase(0x2000);
			byte_write(0x2000,stop);
			}
			}			
	}
}