2010-11-16 12:41 PM
Hi, I've managed to get the example program working which transfers a buffer of text from usart2 to usart3. When I try and output on usart2 to a PC however it seems as if the baud rate is wrong. I just get garbage.
The GPIO config is /* Configure USARTy Rx as input floating */ GPIO_InitStructure.GPIO_Pin = USARTy_RxPin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(USARTy_GPIO, &GPIO_InitStructure); /* Configure USARTy Tx as push-pull */ GPIO_InitStructure.GPIO_Pin = USARTy_TxPin; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(USARTy_GPIO, &GPIO_InitStructure); The RCC config is RCC_APB2PeriphClockCmd(USARTy_GPIO_CLK, ENABLE); RCC_APB1PeriphClockCmd(USARTy_CLK, ENABLE); The defines are #define USARTy USART2 #define USARTy_GPIO GPIOA #define USARTy_CLK RCC_APB1Periph_USART2 #define USARTy_GPIO_CLK RCC_APB2Periph_GPIOA #define USARTy_RxPin GPIO_Pin_3 #define USARTy_TxPin GPIO_Pin_2 and the code is 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_Even; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* Configure USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE) do{ while(TxCounter < TxBufferSize) { /* Send one byte from USARTy */ USART_SendData(USARTy, TxBuffer[TxCounter++]); /* Loop until USARTy DR register is empty */ while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } } Any help would be appreciated Alastair2010-11-16 01:13 PM
I think you need to enable clock to AFIO too
2010-11-16 01:44 PM
I think you need to enable clock to AFIO too
Nothing is being remapped. GPIOA and USART2 should suffice. Would start by confirming you can see data on the PA.2 pin with a scope. Measure the bit timing to confirm the baud rate. If the bit timing is wrong check the clock and the PLL settings. Then checking your CMOS-to-RS232 voltage conversion circuit. PA.2/PA.3 are not 5V tolerant pins, so verify any USB or RS232 serial conversion is using a supply in common with the STM32VL Send out repetitive characters in a tight loop so the burst length is not limited to your output string while debugging.
2010-11-17 01:29 AM
2010-11-17 06:32 AM
Can you answer something else for me. The peripheral routines have the GPIO clock set at 50MHZ but the board is running at 24MHz.
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
The defines in the GPIO header file only have 50, 10 and 2. What effect does this have? It is slew rate control, ie how strongly/rapidly it drives the lines high and low. 50 MHz will provide very fast/sharp edges, and more overshoot/undershoot and ringing, depending on how they are terminated. For a USART output, 2 MHz would more than suffice.
2010-11-17 12:55 PM