probe_rs232c.c
来自「ucos 移植 stm32 在iar5.2通过运行良好」· C语言 代码 · 共 586 行 · 第 1/2 页
C
586 行
/* Configure GPIOD.8 as push-pull. */
gpio_init.GPIO_Pin = GPIO_Pin_8;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOD, &gpio_init);
/* Configure GPIOD.9 as input floating. */
gpio_init.GPIO_Pin = GPIO_Pin_9;
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &gpio_init);
#else
BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
/* Configure GPIOB.10 as push-pull. */
gpio_init.GPIO_Pin = GPIO_Pin_10;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &gpio_init);
/* Configure GPIOB.11 as input floating. */
gpio_init.GPIO_Pin = GPIO_Pin_11;
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &gpio_init);
#endif
/* ------------------ SETUP USART3 -------------------- */
USART_Init(USART3, &usart_init);
USART_ClockInit(USART3, &usart_clk_init);
USART_Cmd(USART3, ENABLE);
BSP_IntVectSet(BSP_INT_ID_USART3, ProbeRS232_RxTxISRHandler);
BSP_IntEn(BSP_INT_ID_USART3);
#endif
}
/*
*********************************************************************************************************
* ProbeRS232_RxTxISRHandler()
*
* Description : Handle Rx and Tx interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : This is an ISR.
*
* Note(s) : (1) If this port is used in an RTOS, the interrupt entrance/exit procedure should be
* performed by the ISR that calls this handler.
*********************************************************************************************************
*/
void ProbeRS232_RxTxISRHandler (void)
{
USART_TypeDef *usart;
CPU_INT08U rx_data;
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)
usart = USART1;
#elif (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)
usart = USART2;
#elif (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)
usart = USART3;
#else
return;
#endif
if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
rx_data = USART_ReceiveData(usart) & 0xFF; /* Read one byte from the receive data register. */
ProbeRS232_RxHandler(rx_data);
USART_ClearITPendingBit(usart, USART_IT_RXNE); /* Clear the USART1 receive interrupt. */
}
if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
ProbeRS232_TxHandler();
USART_ClearITPendingBit(usart, USART_IT_TXE); /* Clear the USART1 transmit interrupt. */
}
}
/*
*********************************************************************************************************
* ProbeRS232_RxISRHandler()
*
* Description : Handle Rx interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : This is an ISR.
*
* Note(s) : (1) This function is empty because receive interrupts are handled by ProbeRS232_RxTxISRHandler().
*********************************************************************************************************
*/
void ProbeRS232_RxISRHandler (void)
{
}
/*
*********************************************************************************************************
* ProbeRS232_RxIntDis()
*
* Description : Disable Rx interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : (1) The application should call this function to stop communication.
*********************************************************************************************************
*/
void ProbeRS232_RxIntDis (void)
{
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
#endif
}
/*
*********************************************************************************************************
* ProbeRS232_RxIntEn()
*
* Description : Enable Rx interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : (1) The application should call this function to start communication.
*********************************************************************************************************
*/
void ProbeRS232_RxIntEn (void)
{
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
#endif
}
/*
*********************************************************************************************************
* ProbeRS232_TxISRHandler()
*
* Description : Handle Tx interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : This is an ISR.
*
* Note(s) : This function is empty because transmit interrupts are handled by ProbeRS232_RxTxISRHandler().
*********************************************************************************************************
*/
void ProbeRS232_TxISRHandler (void)
{
}
/*
*********************************************************************************************************
* ProbeRS232_Tx1()
*
* Description : Transmit one byte.
*
* Argument(s) : c The byte to transmit.
*
* Return(s) : none.
*
* Caller(s) : ProbeRS232_TxHandler().
*
* Note(s) : none.
*********************************************************************************************************
*/
void ProbeRS232_Tx1 (CPU_INT08U c)
{
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)
USART_SendData(USART1, c);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)
USART_SendData(USART2, c);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)
USART_SendData(USART3, c);
#endif
}
/*
*********************************************************************************************************
* ProbeRS232_TxIntDis()
*
* Description : Disable Tx interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : ProbeRS232_TxHandler().
*
* Note(s) : none.
*********************************************************************************************************
*/
void ProbeRS232_TxIntDis (void)
{
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)
USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
#endif
}
/*
*********************************************************************************************************
* ProbeRS232_TxIntEn()
*
* Description : Enable Tx interrupts.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : ProbeRS232_TxStart().
*
* Note(s) : none.
*********************************************************************************************************
*/
void ProbeRS232_TxIntEn (void)
{
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
#endif
#if (PROBE_RS232_CFG_COMM_SEL == PROBE_RS232_UART_3)
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
#endif
}
/*
*********************************************************************************************************
* ENABLE END
*
* Note(s) : See 'ENABLE Note #1'.
*********************************************************************************************************
*/
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?