2014-01-16 11:08 AM
Hi all,
the following code works fine if I comment the line 131: OutString(''In full\n'');But it doesn't give the echo character if a don't comment the line.I don't understand why.Your help is much appreciate.<code>/* Includes ------------------------------------------------------------------*/#include ''main.h''#include <string.h> // memcpy() /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f30x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f30x.c file */ // STM32 USART2 LOOP (Tx PA.2, Rx PA.3) STM32F3xx - sourcer32@gmail.com #include ''stm32f30x.h''volatile char StringLoop[] = ''Conta\r\n'';volatile int full = 0;volatile uint16_t ch; /**************************************************************************************/ void RCC_Configuration(void){ /* Enable GPIO clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Enable USART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);} /**************************************************************************************/ void GPIO_Configuration(void){GPIO_InitTypeDef GPIO_InitStructure;/*-------------------------- GPIO Configuration ----------------------------*/GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure);/* Connect USART pins to AF */ /* Configure Alternate Function pin muxing fabric to escape USART2 Rx and Tx */GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_7); //USART2_TXGPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_7); //USART2_RX} /**************************************************************************************/ void USART2_Configuration(void){USART_InitTypeDef USART_InitStructure;/* USARTx configuration ------------------------------------------------------*//* USARTx configured as follow: - BaudRate = 4800 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */USART_InitStructure.USART_BaudRate = 4800;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);USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); // Enable USART2 Receive Interrupt } /**************************************************************************************/ void NVIC_Configuration(void){ NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* Enable the USART3 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);} /**************************************************************************************/ void OutString(char *s){ while(*s) { while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART2, *s++); }}/**************************************************************************************/ void USART2_IRQHandler(void){ while(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET); // Wait for Char ch = USART_ReceiveData(USART2); // Collect Char7 full = 1; } /**************************************************************************************/int main(void){ RCC_Configuration(); GPIO_Configuration(); NVIC_Configuration(); USART2_Configuration(); OutString(''This is an echo test for USART interrupt\n''); while(1) { if(full) { OutString(''In full\n''); while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty USART_SendData(USART2, ch); // Echo Char full = 0; } } } /**************************************************************************************/ #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */void assert_failed(uint8_t* file, uint32_t line){ /* User can add his own implementation to report the file name and line number, ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */ /* Infinite loop */ while (1) { }}#endif<\code>
2014-01-16 11:11 AM
Here below the output with line uncommented:
<code>This is an echo test for USART interruptp //character from keyboardIn fullu //character from keyboardIn fully //character from keyboardIn full </code>