2012-07-04 04:52 PM
Hello.
I'm facing a problem when trying to send data with function USART_SendData(USART1, (uint16_t)resultat) (resultat is a int 32 bits).When i step by step debugged it, i discovered that my program just enters in an infite loop, due that the flag TC is never set to SET - my conclusion is that the data could not be sent.Testing with scope, discovered that the PA9 pin stays in a HIGH (or LOW) lvl constantly... void envoi_data(int resultat){ USART_SendData(USART1, (uint16_t)resultat); while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { } }Here you can find my inits....void my_gpio(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA , ENABLE); /* Configure the pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure);}void my_usart(){ USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); USART_ClockStructInit(&USART_ClockInitStructure); USART_ClockInit(USART1, &USART_ClockInitStructure); 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_Mode = USART_Mode_Rx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //Write USART1 parameters USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE); }I'm using IAR workbench....Thank you! #usart #stm32vl-usart-problem2012-07-04 08:00 PM
Isn't going to send anything with
USART_InitStructure.USART_Mode = USART_Mode_Rx; try USART_InitStructure.USART_Mode = USART_Mode_Tx;2012-07-04 08:45 PM
Thank you for helping me, Clive.
2012-07-04 09:27 PM
You're welcome.
You might want to do a test for TXE before sending a character, instead of TC afterward. Waiting for TC (ie last bit actually sent on wire) is the slowest possible method. Waiting for TXE lets you fill the holding register as soon as the first bit of the previous byte is sent.