Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stm32f10x.h"
- #define RXUSART USART1
- #define RXUSART_GPIO GPIOA
- #define RXUSART_CLK RCC_APB2Periph_USART1
- #define RXUSART_GPIO_CLK RCC_APB2Periph_GPIOA
- #define RXUSART_RxPin GPIO_Pin_10
- #define RXUSART_IRQn USART1_IRQn
- #define RXUSART_Invert_Pin GPIO_Pin_11
- #define RXUSART_Invert_GPIO GPIOC
- #define RXUSART_Invert_GPIO_CLK RCC_APB2Periph_GPIOC
- int main(void)
- {
- /* Enable GPIO clock */
- RCC_APB2PeriphClockCmd(RXUSART_GPIO_CLK | RXUSART_Invert_GPIO_CLK , ENABLE);
- /* Enable USART Clock */
- RCC_APB2PeriphClockCmd(RXUSART_CLK, ENABLE);
- GPIO_InitTypeDef GPIO_InitStructure;
- /* Configure USART Rx as input floating */
- GPIO_InitStructure.GPIO_Pin = RXUSART_RxPin;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(RXUSART_GPIO, &GPIO_InitStructure);
- // configures the Inversion input
- GPIO_InitStructure.GPIO_Pin = RXUSART_Invert_Pin;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(RXUSART_Invert_GPIO, &GPIO_InitStructure);
- // Sets or reset the inversion Pin
- //GPIO_SetBits(RXUSART_Invert_GPIO, RXUSART_Invert_Pin);
- GPIO_ResetBits(RXUSART_Invert_GPIO, RXUSART_Invert_Pin);
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Enable the RXUSART Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = RXUSART_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- USART_InitTypeDef USART_InitStructure;
- USART_InitStructure.USART_BaudRate = 115200;
- //USART_InitStructure.USART_WordLength = USART_WordLength_9b;
- //USART_InitStructure.USART_StopBits = USART_StopBits_2;
- //USART_InitStructure.USART_Parity = USART_Parity_Even;
- USART_InitStructure.USART_WordLength = USART_WordLength_8b;
- USART_InitStructure.USART_StopBits = USART_StopBits_1;
- USART_InitStructure.USART_Parity = USART_Parity_No;
- // Configure the other fields
- USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART_InitStructure.USART_Mode = USART_Mode_Rx;
- USART_Init(RXUSART, &USART_InitStructure);
- USART_ITConfig(RXUSART, USART_IT_RXNE, ENABLE);
- USART_Cmd(RXUSART, ENABLE);
- while(1);
- }
- void USART1_IRQHandler(void)
- {
- if(USART_GetITStatus(RXUSART, USART_IT_RXNE) != RESET)
- {
- USART_ReceiveData(RXUSART);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_PE))
- {
- while (1);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_TC))
- {
- while (1);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_IDLE))
- {
- while (1);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_LBD))
- {
- while (1);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_CTS))
- {
- while (1);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_ERR))
- {
- while (1);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_ORE))
- {
- USART_ClearITPendingBit(USART2, USART_IT_ORE);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_FE))
- {
- while (1);
- }
- if (USART_GetITStatus(RXUSART, USART_IT_NE))
- {
- while (1);
- }
- if (USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
- {
- USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement