static void uart16chk(int16_t a) { static uint8_t t; t = a; UartBuf_WD(&UartTxbuf,t); checksum ^= t; t = a >> 8 & 0xff; UartBuf_WD(&UartTxbuf,t); checksum ^= t; }
//------------------------------------------------------ void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) { USART_SendData(USART1, UartBuf_RD(&UartTxbuf)); //环形数据缓存发送 if(UartBuf_Cnt(&UartTxbuf)==0) USART_ITConfig(USART1, USART_IT_TXE, DISABLE);//假如缓冲空了,就关闭串口发送中断 } else if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(USART1, USART_IT_RXNE);//清除接收中断标志 //此种环形缓冲数组串口接收方式,适用于解包各种数据,很方便。对数据的要求是: //发送方必须要求有数据包头,以便解决串口数据无地址的问题 Udatatmp = (uint8_t) USART_ReceiveData(USART1); //临时数据赋值 UartBuf_WD(&UartRxbuf,Udatatmp); //写串口接收缓冲数组 #ifdef BT_SRC_APP CommApp(Udatatmp); #endif #ifdef BT_SRC_PC CommPC(Udatatmp); #endif } }
static void uart32chk(uint32_t a) { static uint8_t t; t = a; UartBuf_WD(&UartTxbuf,t); checksum ^= t; t = a >> 8; UartBuf_WD(&UartTxbuf,t); checksum ^= t; t = a >> 16; UartBuf_WD(&UartTxbuf,t); checksum ^= t; t = a >> 24; UartBuf_WD(&UartTxbuf,t); checksum ^= t; }
void UartSendBuffer(uint8_t *dat, uint8_t len) { uint8_t i; for (i=0; i<len; i++) { UartBuf_WD(&UartTxbuf, *dat); dat++; } USART_ITConfig(USARTy, USART_IT_TXE, ENABLE);// }
void UartSendBuffer(uint8_t *dat, uint8_t len) { volatile uint8_t i = 0; for (i = 0; i < len; i++){ UartBuf_WD(&UartTxbuf, *dat); dat++; } if (len) SCI1CR2_TIE = 1; //打开串口发送器中断 开始啪啪啪的发送缓冲中的数据 }
void RTtest(void) { uint8_t i, cnTemp; cnTemp = UartBuf_Cnt(&UartRxbuf); if (cnTemp == 5) { for (i=0; i<cnTemp; i++) { UartBuf_WD(&UartTxbuf, UartBuf_RD(&UartRxbuf)); } USART_ITConfig(USARTy, USART_IT_TXE, ENABLE); } // UartBufClear(&UartRxbuf); }
void interrupt VectorNumber_Vsci1 SCI1_ISR(void) { volatile uint8_t datatemp = 0; //如果发送器中断使能且发送器空则表明触发发送器中断 if (SCI1CR2_TIE & SCI1SR1_TDRE){ if (UartBuf_Cnt(&UartTxbuf)) SCI1DRL = UartBuf_RD(&UartTxbuf); else{ SCI1CR2_TIE = 0;//如果发送缓存空,则关闭发送中断 } } else if (SCI1SR1_RDRF|SCI1SR1_OR ){ Chartemp = (uint8_t)SCI1DRL; led_printf(Chartemp); UartBuf_WD(&UartRxbuf, Chartemp); //printf("%c", Chartemp); } // // static i = 0; // unsigned char ch; // ch = SCI1_Read(); // SCI1_Send(ch); // if (ch == SEND_HEAD) // { // i = 0; // } // g_STBuf[i++] = ch; // if (i == 4) // { // i = 0; // g_SCI1_READ_flag = 1; // } }
void USARTy_IRQHandler(void) { // uint8_t i; if (USART_GetITStatus(USARTy, USART_IT_TXE) != RESET) { USART_SendData(USARTy, UartBuf_RD(&UartTxbuf)); if(UartBuf_Cnt(&UartTxbuf) == 0 ) USART_ITConfig(USARTy, USART_IT_TXE, DISABLE); } else if(USART_GetITStatus(USARTy, USART_IT_RXNE) != RESET) { USART_ClearITPendingBit(USARTy, USART_IT_RXNE);//清除接收中断标志 UdataTemp = (uint8_t)USART_ReceiveData(USARTy); UartBuf_WD(&UartRxbuf, UdataTemp);//写串口接收缓冲数组 } }
//------------------------------------------------------ void USART1_IRQHandler(void) { if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET) { USART_SendData(USART1, UartBuf_RD(&UartTxbuf)); //环形数据缓存发送 if(UartBuf_Cnt(&UartTxbuf)==0) USART_ITConfig(USART1, USART_IT_TXE, DISABLE);//假如缓冲空了,就关闭串口发送中断 } else if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { //此种环形缓冲数组串口接收方式,适用于解包各种数据,很方便。对数据的要求是: //发送方必须要求有数据包头,以便解决串口数据无地址的问题 Udatatmp = USART_ReceiveData(USART1); //临时数据赋值 UartBuf_WD(&UartRxbuf,Udatatmp); //写串口接收缓冲数组 if(UartBuf_Cnt(&UartRxbuf)==0) USART_SendData(USART1, 'E');//串口接收数组长度等于0时,发送接收数组空标志 if(UartBuf_Cnt(&UartRxbuf)==UartRxbuf.Mask) USART_SendData(USART1, 'F');//串口接收数组长度等于掩码时,发送接收缓冲满标志 USART_ClearITPendingBit(USART1, USART_IT_RXNE);//清除接收中断标志 } }
uint8_t Uart1_Put_Char(unsigned char DataToSend) { UartBuf_WD(&UartTxbuf,DataToSend);//将待发送数据放在环形缓冲数组中 USART_ITConfig(USART1, USART_IT_TXE, ENABLE); //启动发送中断开始啪啪啪发送缓冲中的数据 return DataToSend; }
//unsigned char DataToSend 要发送的字节数据 RS232发送一个字节 void UART1_Put_char(uint8_t dataToSend) { UartBuf_WD(&UartTxbuf, dataToSend); USART_ITConfig(USARTy, USART_IT_TXE, ENABLE); }
static void uart8chk(uint8_t _x) { UartBuf_WD(&UartTxbuf,_x); checksum ^= _x; }