|
/**
* @brief 中断服务函数
* @param 无
* @retval 无
*/
void UART2_Isr() interrupt 8
{
if(S2CON & 0x02)//发送中断
{
S2CON &= ~0x02;//清除中断标志
busy_send = 0;//发送命令忙
}
if(S2CON & 0x01)//接收中断
{
S2CON &= ~0x01;//清除中断标志
zylora_cmdpro.lorarevcmdinfo[zylora_cmdflg.LoRaRcvCnt++] = S2BUF;
if(zylora_cmdflg.LoRaRcvCnt == 10)
{
if(zylora_cmdpro.revcmd_info.Cmd != 0x61)
{
zylora_cmdflg.LoRaRcvFlg = 1;
busy_recv = 1;//接收命令忙
}
}
else if(zylora_cmdflg.LoRaRcvCnt == 11)
{
if(zylora_cmdpro.revcmd_info.Cmd != 0x61)
{
zylora_cmdflg.LoRaRcvFlg = 1;
busy_recv = 1;//接收命令忙
}
}
else if(zylora_cmdflg.LoRaRcvCnt == 12)
{
zylora_cmdflg.LoRaRcvFlg = 1;
busy_recv = 1;//接收命令忙
}
}
}
/**
* @brief 初始化串口2
* @param 无
* @retval 无
*/
void Uart2_Init(void) // 9600bps@24.000MHz
{
COMx_InitDefine COMx_InitStructure; //结构定义
GPIO_InitTypeDef GPIO_InitStructure; //结构定义
GPIO_InitStructure.Pin = GPIO_Pin_0 | GPIO_Pin_1; //指定要初始化的IO, GPIO_Pin_0 ~ GPIO_Pin_7
GPIO_InitStructure.Mode = GPIO_PullUp; //指定IO的输入或输出方式,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
GPIO_Inilize(GPIO_P1,&GPIO_InitStructure); //初始化
COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //模式, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
COMx_InitStructure.UART_BRT_Use = BRT_Timer2; //选择波特率发生器, BRT_Timer1, BRT_Timer2 (注意: 串口2固定使用BRT_Timer2)
COMx_InitStructure.UART_BaudRate = 9600ul; //波特率, 一般 110 ~ 115200
COMx_InitStructure.UART_RxEnable = ENABLE; //接收允许, ENABLE或DISABLE
COMx_InitStructure.BaudRateDouble = DISABLE; //波特率加倍, ENABLE或DISABLE
UART_Configuration(UART2, &COMx_InitStructure); //初始化串口1 UART1,UART2,UART3,UART4
NVIC_UART2_Init(ENABLE,Priority_1); //中断使能, ENABLE/DISABLE; 优先级(低到高) Priority_0,Priority_1,Priority_2,Priority_3
UART2_SW(UART2_SW_P10_P11); //UART2_SW_P10_P11,UART2_SW_P46_P47
busy_send = 0; //复位标志
busy_recv = 0; //复位标志
ZYLoRa_MD0 = 1;
ZYLoRa_MD1 = 0;
ZYLoRa_AUX = 1;
}
/**
* @brief 数据发送字节
* @param 无
* @retval 无
*/
void Uart2Send(u8 dat)
{
while(busy_send);
busy_send = 1;
S2BUF = dat;
}
Uart2Send(0x5A);无数据发送出来 |
|