AnsweredAssumed Answered

Built in USART functions putting incorrect values into registers

Question asked by Melissa on Feb 13, 2014
Latest reply on Feb 14, 2014 by Jack Peacock
Hello, I am working on the STM32F429 with Keil uVision version 5, and am trying to get the USART1 module working. In attempting to use the functions provided in the stm32f4xx USART library files, I am getting very odd behavior, specifically values being put into the registers that shouldn't be getting put into them. I can manually set the registers in order to get the USART module working, but am curious as to the reason behind this behavior. Following is my transcribing of the issues happening:

--------------------------------------------------------------------------
Function call: USART_ClockInit:

CR2 starting value: 0x000

1.) tmpreg = 0x000
2.) ~0x0F00, Result: 0xF0FF
3.) tmpreg &= 0xF0FF, Result: 0x0000
4.) tmpreg |= Possible values: (0x0800/0x0400/0x0200/0x0100), Current value: 0x0000
5.) CR2 = tmpreg (0x0000)

Final result of CR2: 0x0040

--------------------------------------------------------------------------

Function call: USART_Init:

CR2 Initialization section:
CR2 Starting Value: 0x0040

1.) tmpreg = 0x0040
2.) ~0x3000, Result: 0xCFFF
3.) tmpreg &= 0xCFFF, Result: 0x0040
4.) tmpreg |= Possible values: (0x0000/0x1000/0x2000/0x3000), Current value: 0x0000
5.) CR2 = tmpreg (0x0040)

Final result of CR2: 0x0840

--------------------------------------------------------------------------

CR1 Initialization section:
CR1 Starting Value: 0x0000

1.) tmpreg = 0x0000
2.) ~0x160C, Result: 0xE9F3
3.) tmpreg &= 0xE9F3, Result: 0x0000
4.) tmpreg |= Possible values: (0x1000/0x0400/0x0600/0x0004/0x0008), Current value: 0x000C
5.) CR1 = tmpreg (0x000C)

Final result CR1: 0x09DD

--------------------------------------------------------------------------

CR3 Initialization section:
CR3 Starting Value: 0x0000

1.) tmpreg = 0x0000
2.) ~0x0300, Result: 0xFCFF
3.) tmpreg &= 0xFCFF, Result: 0x0000
4.) tmpreg |= Possible values: (0x0100/0x0200/0x0300), Current value: 0x0000
5.) C3 = tmpreg (0x0000)

Final Result CR3: 0x0431

--------------------------------------------------------------------------

BRR setting:
A set of math to create a floating value out of a int am not going to transcribe, final result is: 0x0000. 

--------------------------------------------------------------------------

Again, I can use manually determine the correct register values and set them, but that gets tedious over time and is error prone, and don't want to write my own library functions to do it for me, so if I could get the given ones working that would be great. 

Outcomes