Question
STM32F072 discovery board USART to hyperterminal communication problem
Posted on November 11, 2015 at 20:08
Hi,
I don't know why this code doesn't work. I have following simple code to check USART and the code is running on STM32F072 discovery board. But when I check PA2 pin with scope, it shows nothing. I also connect the board to PC serial port and check with hyperterminal and no luck. *******************************************static void USART_Config(void);
static void GPIO_Config(void); static void RCC_Config(void);/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program. * @param None * @retval None */ int main(void) { /* RCC configuration */ RCC_Config(); /* GPIO configuration */ GPIO_Config();/* USART configuration */
USART_Config();while(1)
{ while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); USART_SendData(USART2, 10);}
}/**
* @brief Configure the USART1 Device * @param None * @retval None */ static void USART_Config(void) { USART_InitTypeDef USART_InitStructure; /* USART1 configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - Two Stop Bit - Odd parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART2, &USART_InitStructure); USART_Cmd(USART2, ENABLE); }/**
* @brief Configure the GPIO Device * @param None * @retval None */ static void GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure;/* Connect PXx to USART2_Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);/* Connect PXx to USART2_Rx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1); /* Configure USART2 Tx/Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; // GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOA, &GPIO_InitStructure); }/**
* @brief Configure the RCC * @param None * @retval None */ static void RCC_Config(void) { RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //enable GPIOA clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //enable USART2 clock}
#rtfm