cancel
Showing results for 
Search instead for 
Did you mean: 

UART PRBLEM with STM32F3

hilwan
Associate II
Posted on January 30, 2014 at 10:51

The original post was too long to process during our migration. Please click on the attachment to read the original post.
21 REPLIES 21
hilwan
Associate II
Posted on February 03, 2014 at 15:21

Why can't you use PA9/PA10 which are actually free? : even with this still have the same. But one thing, when i used the code like this:

int main(void)

{

 /* Initialize USART communication */

     USART1_Init2(115200);

     while(!(USART1->ISR & USART_FLAG_TXE));

     /* Put character on the serial line */

      USART1->TDR = 25; // '%'

        STM_EVAL_LEDOn(LED5);

         if ((USART1->ISR & USART_FLAG_RXNE))

     {

    /* Read one byte from the receive data register */

       rx= USART_ReceiveData(USART1) & 0x7F;

        STM_EVAL_LEDOff(LED5);

       }

    while(1){};

}

The bit ''RXNE'' never set because the value rx still has zéro.

And when i put sending and receiving stuff in while loop it works, the code is below :

/*****/

uint8_t rx;

uint8_t j=0,k=0;

int main(void)

{

  Init_Usart1(115200); 

 while(1)

{

    j++;

   while(!(USART1->ISR & USART_FLAG_TXE));

     /* Put character on the serial line */

     USART1->TDR = j; // '%'

     STM_EVAL_LEDOn(LED5);

   if ((USART1->ISR & USART_FLAG_RXNE))

   {

    /* Read one byte from the receive data register */

      rx= USART_ReceiveData(USART1);

   }

    

   if(j==200)

        j=0;

 }// end while loop

 } // end main

if make a breakpoint to while(!(USART1->ISR & USART_FLAG_TXE)) and starting debugging step one line i can see that RXNE never set.

I can't understand what would be the problem,it's frustrating, i spend a lot of time for a supposed easy stuff.

I would be grateful is someone has an idea.

Posted on February 03, 2014 at 17:42

It's not clear to me what development tools you're using, or if you've examined the signals on a scope.

I don't think you can just start up the USART and expect to see received data, it needs to be in a loop.

// STM32 USART1 (Tx PA.9, Rx PA.10) STM32F3 Discovery - sourcer32@gmail.com
#include ''stm32f3_discovery.h''
//****************************************************************************
void RCC_Configuration(void)
{
/* USART1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
/* GPIOA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
}
//****************************************************************************
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIO Configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect USART pins to AF */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_7); // USART1_TX
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_7); // USART1_RX
}
//****************************************************************************
void USART1_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
//****************************************************************************
int main(void)
{
uint16_t ch;
RCC_Configuration();
GPIO_Configuration();
USART1_Configuration();
ch = 0x49; // 'I'
while(1)
{
if (USART_GetFlagStatus(USART1, USART_FLAG_TXE) != RESET) // Check for Empty
USART_SendData(USART1, ch); // Send Character
if (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET) // Check for Full
ch = USART_ReceiveData(USART1);
}
while(1); // Don't want to exit
}
//****************************************************************************
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif

I'm not using USARTs on the F3-DISCO, currently I use SWV, and would perhaps have used a memory buffer where that wasn't available (F072-DISCO). Problems with USART on other STM32 platforms tend to occur when HSE_VALUE doesn't reflect the hardware on the board, and the timing gets jacked up. This is something that a few minutes on the scope could pin down.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hilwan
Associate II
Posted on February 04, 2014 at 11:41

I'm using keil µVision4, i tried your code, it's works fine but with Hyper terminal i can't show the correct data received, only the 'U' is correct

Posted on February 04, 2014 at 13:49

Well you'll want to inspect with a scope, check things like bit timing, and parity settings.

Consider is some pre-built hardware might suit your needs.

http://www.mikroe.com/stm32/stm32f3-discovery-shield/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
francois
Associate II
Posted on May 08, 2014 at 09:26

Hi, the following hardware setup is what i have:

STM32F3 discovery board connected to a usb to serial converter(converting to TTL level) and then connected to my windows8 pc running hyperterminal. The usb to serial converter is just fine(drivers installed and working). when i communicate from the discovery to my pc on hyperterminal i view strange character which i dont send. if i send a ''I'' then in hyperterminal i receive it as ''[''. attached is my main.c source file. The uart parameters are setup equal between hyperterminal and discovery board. any feedback would be really appreciated. also because hyperterminal receives weired values i tried opening up the uart1 serial window viewer in KEIL microvision while in run mode, the window is empty and not seeing anything- should i set something before i can view data?

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hza5&d=%2Fa%2F0X0000000bNq%2F6TWcBZW3VdbQLXllibKX42lm8wA3U_epj7duA3VI1wY&asPdf=false
Posted on May 08, 2014 at 13:04

Sounds like a timing problem..

''Problems with USART on other STM32 platforms tend to occur when HSE_VALUE doesn't reflect the hardware on the board, and the timing gets jacked up. This is something that a few minutes on the scope could pin down.''
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
francois
Associate II
Posted on May 10, 2014 at 14:52

Clive1 are you working for STM, it sounds like you know your stuff.

i dont have a scope. I know that the stm32f303vc has a clock of 8Mhz, and my HSE_VALUE in my header file is defined as 8 Mhz as well. so it is definitely matches up. The reason i am receiving garbage on hyper terminal side is because of a timing issue (thats what you and i also believe the issue is). So if i have it correct, upon setting up my USART setting in my main(baud rate etc) does micro controller use the baud rate setting along with my peripheral clock that is enabled and convert it to a clock that has an output = to my specified baud rate setting?

My main Question; why cant i see anything upon opening my serial windows viewer(UART1)? and which variable can i check to see that the peripheral clock is definitely set at 9600 bps which in my case is what i want the speed of the UART to work at
Posted on May 10, 2014 at 17:16

No, and the ST parts aren't the only thing I use.

Actually I suspect the USB-to-CMOS Serial, but in order to prove that you'd need to confirm the bit timing.

You can review the baud rate divider with respect to the APB clock by looking at USART1->BRR. The timing of the processor could be make by using a timer to toggle an LED in human discernible fashion, as 1 or 2 Hz.

As well as the HSE, you could check the PLL settings in system_stm32f3xx.c, or select the HSI source
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
francois
Associate II
Posted on May 13, 2014 at 12:07

Clive, i managed to test the actual buad rate at which the data gets transferred out of stm32f3 controller (pin-PA9) with a oscilloscope and it seems to be correct. if set up at 9600 i read 104uS per bit on the scope.  i am going to try a different usb to serial converter later today and see what i get.  Still when i am in the IDE(uVision) and i put the controller in debug mode while running, i click on the serial window viewer(Uart1) the window stays blank.. according to my knowledge that window should just work and all the data that gets send to USART1 TDR register must get displayed on this viewer window? Hope you can help! Thank you!

mahdi
Associate
Posted on July 24, 2016 at 23:28

hello clive1 

thank you for this code really it's so interesting for me 

but i have a problem with configuring the environment of keil ,can you send for me the project in a file .zip or .rar

thanks