2014-08-15 07:30 PM
I'm trying to simply send a character over and over to my computer using a USB to TTL adapter and USART2 on the STM32F4 discovery board. I have USART2 configured for 9600 baud which would give 104us bit pulses.
After getting junk characters on the computer, I looked at the TX signal on my scope and saw the bit widths were about 160us, or a baud rate of ~6250 bps. In my program if I set the baud rate to 9600*1.5 I actually get 9600 baud.All of my reading seems to suggest this is an issue with a clock setting somewhere. Most commonly I see people having an incorrect value of HSE_VALUE. My HSE_VALUE is indeed set to 8000000 for the 8MHz crystal. I also even added -DHSE_VALUE=8000000 into my CFLAGS. Here are some of my other clock settings from system_stm32f4xx.c:PLL_M: 8PLL_Q: 7PLL_N: 336PLL_P: 2These all seemed correct to me, but I could be missing something. I'm really at a loss here for what's going on. I'm hoping someone can figure it out. Let me know if you need any additional information. Thanks!2014-08-15 09:42 PM
Use the MCO pin (PA8) and configure it to output internal clocks, and measure those on a scope.
2014-08-16 12:09 AM
I first added code to the program to output RCC_MCO1Source_HSE. It showed the correct 8 MHz on the scope. I then checked RCC_MCO1Source_PLLCLK on MCO1 and it was 168 MHz.
I also looked at RCC_MCO2Source_SYSCLK with MCO2 and it was 168 MHz also.Any of these results seem out of the ordinary to you? Thanks.2014-08-16 08:11 PM
The maximum output for pins is about 90 MHz, so normally you'd need to divide down the 168 MHz.
Discrepancies between measured and desired baud rates stems from a difference between the actual clock being used, and the value the software believe is being used. The HSE_VALUE of 25 MHz v 8 MHz typically results in a 1:3.125 distortion, not 1.5, which is more indicative of something running at 12 MHz. You could print out HSE_VALUE and inspect it's value in various object files. 9600 baud should have a bit time of ~104.2 us2014-08-16 08:12 PM
Suggest you attach a complete project for whatever tool chain you are using.