⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.c

📁 freemodbus-v1-1-1-0.zip v1.1.1版本的代码 支持多个平台
💻 C
📖 第 1 页 / 共 2 页
字号:
 else    /* Wait until the transmit shift register is empty */    while (!(UARTx->SR & UART_TxEmpty));   UARTx->TxBUFR = ((*Data) & 0x01FF);}/******************************************************************************** Function Name  : UART_DataSend* Description    : This function sends several data bytes to the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer on the data to send* Input 3        : The data length in bytes* Output         : None* Return         : None*******************************************************************************/void UART_DataSend(UART_TypeDef *UARTx, u8 *Data, u8 DataLength){   while(DataLength--)  {    UART_ByteSend(UARTx,Data);    Data++;  }}/******************************************************************************** Function Name  : UART_9BitDataSend* Description    : This function sends several 9-bit data to the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer to the data to send* Input 3        : The data length * Output         : None* Return         : None*******************************************************************************/void UART_9BitDataSend(UART_TypeDef *UARTx, u16 *Data, u8 DataLength){   while(DataLength--)  {    UART_9BitByteSend(UARTx,Data);    Data++;  }}/******************************************************************************** Function Name  : UART_StringSend* Description    : This function sends a string to the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer on the string to send* Output         : None* Return         : None*******************************************************************************/void UART_StringSend(UART_TypeDef *UARTx, u8 *String){  u8 *Data=String;  while(*Data != '\0')    UART_ByteSend(UARTx, Data++);   *Data='\0';  UART_ByteSend(UARTx, Data);}/******************************************************************************** Function Name  : UART_ByteReceive* Description    : This function gets a data byte from the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer on the data where the data will be stored* Input 3        : The time-out period* Output         : The received 8-bit data* Return         : The UARTx.SR register content*******************************************************************************/u16 UART_ByteReceive(UART_TypeDef *UARTx, u8 *Data, u8 TimeOut){   u16 wStatus = 0;/* reload the Timeout counter */   UARTx->TOR=TimeOut;/* while the UART_RxFIFO is empty and no Timeoutidle */   while (!((wStatus=UARTx->SR) & (UART_TimeOutIdle|UART_RxHalfFull|UART_RxBufFull)));/* then read the Receive Buffer Register */   *Data = (u8)UARTx->RxBUFR;   return wStatus;}/******************************************************************************** Function Name  : UART_9BitByteReceive* Description    : This function gets a 9-bit data from the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer on the buffer where the data will be stored* Input 3        : The time-out period value* Output         : The received 9-bit data* Return         : The UARTx.SR register contents*******************************************************************************/u16 UART_9BitByteReceive(UART_TypeDef *UARTx, u16 *Data, u8 TimeOut){  u16 wStatus = 0;/* reload the Timeout counter */  UARTx->TOR=TimeOut;/* while the UART_RxFIFO is empty and no Timeoutidle */  while (!((wStatus=UARTx->SR) & (UART_TimeOutIdle|UART_RxHalfFull|UART_RxBufFull))); /* then read the RxBUFR*/  *Data = (u16)UARTx->RxBUFR;   return wStatus;}/******************************************************************************** Function Name  : UART_DataReceive* Description    : This function gets 8 bits data bytes from the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer on the buffer where the data will be stored* Input 3        : The data length* Input 4        : The time-out period value* Output         : The received 8-bit data buffer* Return         : The UARTx.SR register contents*******************************************************************************/u16 UART_DataReceive(UART_TypeDef *UARTx, u8 *Data, u8 DataLength, u8 TimeOut){   u16 wStatus = 0;  while(DataLength--)    wStatus=UART_ByteReceive(UARTx,Data++,TimeOut);  return wStatus;}/******************************************************************************** Function Name  : UART_9BitDataReceive* Description    : This function gets several 9-bits data from the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer on the buffer where the data will be stored* Input 3        : The data length* Input 4        : The time-out value* Output         : The received 9-bit data buffer* Return         : The UARTx.SR register contents*******************************************************************************/u16 UART_9BitDataReceive(UART_TypeDef *UARTx, u16 *Data, u8 DataLength, u8 TimeOut){  u16 wStatus = 0;    while(DataLength--)    wStatus=UART_9BitByteReceive(UARTx,Data++,TimeOut);  return wStatus;}/******************************************************************************** Function Name  : UART_StringReceive* Description    : This function gets 8-bit data bytes from the selected UART.* Input 1        : UARTx (x can be 0,1, 2 or 3) the selected UART* Input 2        : A pointer on the buffer where the string will be stored* Output         : The received string* Return         : The UARTx.SR register contents*******************************************************************************/u16 UART_StringReceive(UART_TypeDef *UARTx, u8 *Data){  u8 *pSTRING=Data;  u16 wStatus = 0;  do  { /* while the UART_RxFIFO is empty  */    while (!((wStatus=UARTx->SR) & (UART_RxHalfFull|UART_RxBufFull))); /* then read the RxBUFR */    *(pSTRING++) = (u8)UARTx->RxBUFR;  } while((*(pSTRING - 1)!=0x0D)&(*(pSTRING - 1)!='\0'));  *(pSTRING - 1)='\0';  return wStatus;}#ifdef USE_SERIAL_PORT/******************************************************************************** Function Name  : sendchar* Description    : This function sends a character to the selected UART.* Input 1        : A pointer on the character to send.* Output         : None* Return         : None*******************************************************************************/void sendchar( char *ch ){   #ifdef USE_UART0     #define  UARTx  UART0   #endif /* Use_UART0 */   #ifdef USE_UART1     #define  UARTx  UART1   #endif /* Use_UART1 */   #ifdef USE_UART2     #define  UARTx  UART2   #endif /* Use_UART2 */   #ifdef USE_UART3     #define  UARTx  UART3   #endif /* Use_UART3 */   UART_ByteSend(UARTx,(u8 *)ch);}#endif /* USE_SERIAL_PORT *//******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -