STM32 : can't get the UART3 working

hi ,

i need to use the hyperterminal to interface with my application

i configured the uart3 as folowing :

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_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode =  USART_Mode_Tx | USART_Mode_Rx;
  USART_Init(USART3, &USART_InitStructure);

then i tryed to send the two characters “ab” using these code lines :

  TxData="ab";
  while(1){
  USART_SendData(USART3,TxData);
}

the whole project compiled with no errors,but when i connect my board to the pc,the hyperterminal window is full of “0ù” instead of “ab” !!!

i think it’s a baud rate problem,but i can’t resolve it :frowning:

any suggestions?

I am assuming you have correctly enabled the clocks and configured GPIO for the USART. If that’s the case, what’s missing seems to be the wait for the TXE flag to clear before sending the next byte.

TxData="ab";
while(1){
  USART_SendData(USART3,TxData);
  while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
}

yes the clock is enabled and the GPIO are well configured.

i tryed also to use the wait procedure (as mentioned in the st lib exemple),but it does not work : the code enter an infinite loop the (TXE flag is never set)

Since you have only the USART stuff set in the while(1) loop, I assume that your program might not be doing much right now ?

Did you check with a debugger that the TxData is correctly initialized ? A problem that I face once was that initial data where not correctly … well, initialized, stuffing my char * with random characters.

Another thing, when you change the “ab” to “bc” for example, does that change what the term is displaying ?

yes my primary goal is to achieve a connection via the uart to the PC .

it may be a initialisation problem ,what is the right way to initialise the TxData ?

ps:yes changing “ab” to another value also change the values displayed in the hyperterminal window .

Try transmitting ‘U’ continuously and check the signal with a scope. You should see a square wave at the bit rate, enabling you to check the timing.

Leon

i’m planing to do this test to check if the baud rate is really 9600 or not (i dont have the primer at home …)

about the way to initialise the TxData,is it as simple as TxData = “U” ?

and what type shoud i use ? (i’m using the u16 for instance)

any one have a working code that use the USART3 to communicate with hyperterminal ?