初级会员
- 积分
- 99
- 金钱
- 99
- 注册时间
- 2014-3-20
- 在线时间
- 9 小时
|
5金钱
通过51单片机测温湿度,然后通过NRF发送给STM32的通道2,然后如果有蓝牙连接的 话,不停的发送给蓝牙上位机。出现一个问题,就是存放数据的数组经常是空的!贴上代码
<div style="background-color:#E8E8E8;">
[mw_shl_code=c,true]
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "lcd.h"
#include "usart.h"
#include "sys.h"
#include "tim2.h"
#include "usart1.h"
#include "24l01.h"
#include "sim900a.h"
/** @addtogroup Template
* @{
*/
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u8 VALUE_BUFF[255];
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
u8 *p2,*p1;
DELAY_Init();
NVIC_Configuration();
TIM2_All_Init();
USART1_Init(115200);
USART2_Init(115200);
NRF24L01_Init();
SIM900A_Init();
LCD_Init();
LCD_Clear(WHITE);
LCD_Show_Picture(23,2,80,78,logo);
LCD_Show_String(25,80,BLACK,WHITE,"Smart Home");
/* Infinite loop */
while(NRF24L01_Check())
{
LCD_Show_String(25,92,RED,WHITE,"NRF Error");
delay_ms(300);
LCD_Show_String(25,92,BLACK,WHITE," ");
delay_ms(300);
}
NRF24L01_RX_Mode();
while(1)
{
if((u8*)strstr((const char*)(tmp_buf3),"WARNING")!=0)
{
if(SIM900A_send_cmd("AT+CMGS=\"15731131533\"",">",200)==0) //?è????·????????ú????
{
printf("%s","WARNING"); SIM900A_send_cmd((u8*)0X1A,"+CMGS:",100);
USART1_RX_STA=0;
}
memset(tmp_buf3,0,33);
}
if(USART1_RX_STA&0x8000) //?®??1??SIM900A???é
{
USART1_RX_BUF[USART1_RX_STA&0X7FFF]='\0';
if((u8*)strstr((const char*)(USART1_RX_BUF),"CMTI:")!=0) //??????????
{
p1=(u8*)strstr((const char*)(USART1_RX_BUF),",");
sprintf((char*)p2,"AT+CMGR=%s",p1+1);
delay_ms(200);
if(SIM900A_send_cmd(p2,"000000",600)==0) //?ì????????·????·
{
if((u8*)strstr((const char*)(USART1_RX_BUF),"1")!=0)
{
if((u8*)strstr((const char*)(USART1_RX_BUF),"OPENTHEDOOR")!=0)
{
NRF24L01_TX_Mode(1);
if(NRF24L01_TxPacket("test")==0x20);
if(NRF24L01_TxPacket("kaimen")==0x20) ;
callnumber("Door Opened");
}
}
if((u8*)strstr((const char*)(USART1_RX_BUF),"2")!=0)
{
if((u8*)strstr((const char*)(USART1_RX_BUF),"STATE")!=0)
{
callnumber(tmp_buf2);
}
}
if((u8*)strstr((const char*)(USART1_RX_BUF),"3")!=0)
{
if((u8*)strstr((const char*)(USART1_RX_BUF),"IR_ON")!=0)
{
NRF24L01_TX_Mode(3);
if(NRF24L01_TxPacket("IR_ON")==0x20);
}
if((u8*)strstr((const char*)(USART1_RX_BUF),"IR_OFF")!=0)
{
NRF24L01_TX_Mode(3);
if(NRF24L01_TxPacket("IR_OFF")==0x20);
}
if((u8*)strstr((const char*)(USART1_RX_BUF),"IR_IGNORE")!=0)
{
NRF24L01_TX_Mode(3);
if(NRF24L01_TxPacket("IR_IGNORE")==0x20);
}
}
if((u8*)strstr((const char*)(USART1_RX_BUF),"4")!=0)
{
if((u8*)strstr((const char*)(USART1_RX_BUF),"OPEN")!=0)
{
NRF24L01_TX_Mode(4);
if(NRF24L01_TxPacket("OPEN")==0x20);
}
if((u8*)strstr((const char*)(USART1_RX_BUF),"CLOSE")!=0)
{
NRF24L01_TX_Mode(4);
if(NRF24L01_TxPacket("CLOSE")==0x20);
}
if((u8*)strstr((const char*)(USART1_RX_BUF),"HALF")!=0)
{
NRF24L01_TX_Mode(4);
if(NRF24L01_TxPacket("HALF")==0x20);
}
}
USART1_RX_STA=0;
}
USART1_RX_STA=0;
}
else
{
USART1_RX_STA=0;
}
}
if(BlueTooth_State)
{
if(USART2_RX_STA&0x8000)
{
if((u8*)strstr((const char*)(USART2_RX_BUF),"1")!=0)
{
if((u8*)strstr((const char*)(USART2_RX_BUF),"OPENTHEDOOR")!=0)
{
NRF24L01_TX_Mode(1);
if(NRF24L01_TxPacket("test")==0x20) ; //??????·????????????????ú??????·????????ü??
if(NRF24L01_TxPacket("kaimen")==0x20)
{
USART2_to_Phone_Transmit(3,"DOOROK");
delay_ms(200);
}
}
}
if((u8*)strstr((const char*)(USART2_RX_BUF),"2")!=0)
{
if((u8*)strstr((const char*)(USART2_RX_BUF),"STATE")!=0)
{
USART2_to_Phone_Transmit(2,tmp_buf2);
USART2_printf("jinlaile");
delay_ms(200);
}
}
if((u8*)strstr((const char*)(USART2_RX_BUF),"3")!=0)
{
if((u8*)strstr((const char*)(USART2_RX_BUF),"IR_ON")!=0)
{
NRF24L01_TX_Mode(3);
if(NRF24L01_TxPacket("IR_ON")==0x20)
{
USART2_to_Phone_Transmit(4,"IROK");
delay_ms(200);
}
}
if((u8*)strstr((const char*)(USART2_RX_BUF),"IR_OFF")!=0)
{
NRF24L01_TX_Mode(3);
if(NRF24L01_TxPacket("IR_OFF")==0x20)
{
USART2_to_Phone_Transmit(4,"IROK");
delay_ms(200);
}
}
if((u8*)strstr((const char*)(USART2_RX_BUF),"IR_IGNORE")!=0)
{
NRF24L01_TX_Mode(3);
if(NRF24L01_TxPacket("IR_IGNORE")==0x20)
{
USART2_to_Phone_Transmit(4,"IROK");
delay_ms(200);
}
}
}
if((u8*)strstr((const char*)(USART2_RX_BUF),"4")!=0)
{
if((u8*)strstr((const char*)(USART2_RX_BUF),"OPEN")!=0)
{
NRF24L01_TX_Mode(4);
if(NRF24L01_TxPacket("OPEN")==0x20)
{
USART2_to_Phone_Transmit(3,"CURTAINOK");
delay_ms(200);
USART2_to_Phone_Transmit(2,"OPENED");
delay_ms(300);
}
}
if((u8*)strstr((const char*)(USART2_RX_BUF),"CLOSE")!=0)
{
NRF24L01_TX_Mode(4);
if(NRF24L01_TxPacket("CLOSE")==0x20)
{
USART2_to_Phone_Transmit(3,"CURTAINOK");
delay_ms(200);
USART2_to_Phone_Transmit(2,"CLOSED");
delay_ms(300);
}
}
if((u8*)strstr((const char*)(USART2_RX_BUF),"HALF")!=0)
{
NRF24L01_TX_Mode(4);
if(NRF24L01_TxPacket("HALF")==0x20)
{
USART2_to_Phone_Transmit(3,"CURTAINOK");
delay_ms(200);
USART2_to_Phone_Transmit(2,"HALF");
delay_ms(300);
}
}
}
USART2_RX_STA=0;
}
// USART2_to_Phone_Transmit(2,tmp_buf2);
delay_ms(200);
}
}
下面是NRF接收中断其中的tmp_buf2就是出问题的数组。
<div style="background-color:#E8E8E8;">
[mw_shl_code=c,true]void EXTI15_10_IRQHandler(void)
{
u8 sta;
if(EXTI_GetITStatus(EXTI_Line12) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line12);
sta=NRF24L01_Read_Reg(STATUS); //????×????????÷????
if(sta&MAX_TX)//????×??ó??·?????
{
NRF24L01_Write_Reg(FLUSH_TX,0xff);//????TX FIFO?????÷
NRF24L01_CE1;
}
if(sta&TX_OK)//·????ê??
{
NRF24L01_Write_Reg(FLUSH_TX,0xff);//????TX FIFO?????÷
NRF24L01_RX_Mode();
NRF24L01_CE1;
}
if(sta&RX_OK)//??????????
{
switch((sta&0x0e))
{
case 0 : NRF24L01_Read_Buf(RD_RX_PLOAD,tmp_buf0,RX_PLOAD_WIDTH); break; //?¨??0
case 2 : NRF24L01_Read_Buf(RD_RX_PLOAD,tmp_buf1,RX_PLOAD_WIDTH); break; //?¨??1
case 4 : NRF24L01_Read_Buf(RD_RX_PLOAD,tmp_buf2,RX_PLOAD_WIDTH); break; //?¨??2
case 6 : NRF24L01_Read_Buf(RD_RX_PLOAD,tmp_buf3,RX_PLOAD_WIDTH); break; //?¨??3
case 8 : NRF24L01_Read_Buf(RD_RX_PLOAD,tmp_buf4,RX_PLOAD_WIDTH); break; //?¨??4
case 10 : NRF24L01_Read_Buf(RD_RX_PLOAD,tmp_buf5,RX_PLOAD_WIDTH); break; //?¨??4
default : break;
}
NRF24L01_Write_Reg(FLUSH_RX,0xff);//????RX FIFO?????÷
NRF24L01_RX_Mode();
}
NRF24L01_Write_Reg(WRITE_REG_NRF+STATUS,sta); //????????±ê??
}
EXTI_ClearITPendingBit(EXTI_Line12);
}
[/mw_shl_code]
</div>
<br />
[/mw_shl_code]
</div>
<br /> |
|