📄 probe_rs232c.c
字号:
BSP_PeriphEn(BSP_PERIPH_ID_IOPD);
BSP_PeriphEn(BSP_PERIPH_ID_AFIO);
GPIO_PinRemapConfig(GPIO_FullRemap_USART3, ENABLE);
/* 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.
*
* Note(s) : (1) This ISR handler handles the interrupt entrance/exit as expected by
* by uC/OS-II v2.85. If you are using a different RTOS (or no RTOS), then this
* procedure may need to be modified or eliminated. However, the logic in the handler
* need not be changed.
*********************************************************************************************************
*/
void ProbeRS232_RxTxISRHandler (void)
{
USART_TypeDef *usart;
CPU_INT08U rx_data;
CPU_SR cpu_sr;
CPU_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */
OSIntNesting++;
CPU_CRITICAL_EXIT();
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
usart = USART1;
#elif (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
usart = USART2;
#elif (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_3)
usart = USART3;
#else
OSIntExit();
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 */
}
OSIntExit(); /* Tell uC/OS-II that we are leaving the ISR */
}
/*
*********************************************************************************************************
* ProbeRS232_RxISRHandler()
*
* Description: Handle Rx interrupts.
*
* Argument(s): none.
*
* Return(s) : none.
*
* Note(s) : This function is empty because Rx interrupts are handled by ProbeRS232_RxTxISRHandler()
*********************************************************************************************************
*/
void ProbeRS232_RxISRHandler (void)
{
}
/*
*********************************************************************************************************
* ProbeRS232_RxIntDis()
*
* Description: Disable Rx interrupts.
*
* Argument(s): none.
*
* Return(s) : none.
*********************************************************************************************************
*/
void ProbeRS232_RxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
#endif
#if (PROBE_RS232_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.
*********************************************************************************************************
*/
void ProbeRS232_RxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
#endif
#if (PROBE_RS232_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.
*
* Note(s) : This function is empty because Tx 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.
*********************************************************************************************************
*/
void ProbeRS232_Tx1 (CPU_INT08U c)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
USART_SendData(USART1, c);
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
USART_SendData(USART2, c);
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_3)
USART_SendData(USART3, c);
#endif
}
/*
*********************************************************************************************************
* ProbeRS232_TxIntDis()
*
* Description: Disable Tx interrupts.
*
* Argument(s): none.
*
* Return(s) : none.
*********************************************************************************************************
*/
void ProbeRS232_TxIntDis (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
#endif
#if (PROBE_RS232_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.
*********************************************************************************************************
*/
void ProbeRS232_TxIntEn (void)
{
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_1)
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_2)
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
#endif
#if (PROBE_RS232_COMM_SEL == PROBE_RS232_UART_3)
USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -