USART3 issue : weird characters received on PC

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

USART3 issue : weird characters received on PC

Post by Nemesis2065 »

Hello,

I am facing a issue concerning the serial USART3 on the STM32F4 discovery board. First I have searched a lot on the Internet and on the forum but without any success...
My goal is to control HerkuleX servo motors which need serial communication : http://www.dfrobot.com/wiki/index.php/Herkulex_DRS-0101_SKU:SER0032
I followed a lot of different solutions I found on the forum and Internet but I am still getting weird characters on my PC.
Normally this issue comes from a problem in the clock configuration, but as I am using the default configuration of ChibiOS, I guess the clock config is correct.

The "HAL driver system settings" in mcuconf.h remains the same as default.
Here is my usart configuration :

mcuconf :

Code: Select all

/*
 * SERIAL driver system settings.
 */
#define STM32_SERIAL_USE_USART1             TRUE
#define STM32_SERIAL_USE_USART2             FALSE
#define STM32_SERIAL_USE_USART3             TRUE
#define STM32_SERIAL_USE_UART4              FALSE
#define STM32_SERIAL_USE_UART5              FALSE
#define STM32_SERIAL_USE_USART6             FALSE


Serial config :

Code: Select all

const SerialConfig sd3_config =
{
    38400,   // bit rate
    0,      // CR1 register settings
    0,      // CR2 register settings
    0,      // CR3 register settings
};


Init code :

Code: Select all

/****************************************************************************************************
* Activates the serial driver 3 - baud rate : 38400
****************************************************************************************************/
sdStart(&SD3, &sd3_config);
palSetPadMode(GPIOD, 8, PAL_MODE_ALTERNATE(7));   //Tx
palSetPadMode(GPIOD, 9, PAL_MODE_ALTERNATE(7));   //Rx


main code :

Code: Select all

static const char message3[] = "STM32F4 - Discovery";

while(TRUE)
   {
      if (palReadPad(GPIOA, GPIOA_BUTTON))
      {
         sdWrite(&SD3, (uint8_t *) message3, strlen(message3));
         palSetPad(GPIOD, LED_BLUE);
      }
      else
      {
         palClearPad(GPIOD, LED_BLUE);
      }

   }


For testing purpose, I just want to send "STM32F4 - Discovery" by pressing the user button.
I configure the serial communication on the PC as : 38400-8-N-1, no flow control
I also connected RTS to CTS, to be sure.

Should I use Serial driver system settings or UART driver setting ? I tried both, but still not working...
Should I use a different function instead of sdWrite ?
Should I change the "HAL driver system settings" ?
I used several uart or usart config, pins config, all the same issue...

I also followed this example which seems to work : http://www.telecom-robotics.org/2013/08/robotics-101-transmitting-data-with-chibios-serial-driver/

I tried to change the PIN of usart on the board (GPIOB, 10 and GPIOB, 11) but this does not work better.
I checked my RS232 adapter, mine is using a ft232l, I used before this adapter and this component without any issue and the input signals are 3.3v compatible.

I suppose it could be a clock config error, because I had this character problem on another project. I have also difficulties with the accelerometer, that's why I am supposing a clock config issue.
But as I said before, the mcuconf is the default one.
I want to be sure that is not a software problem, before buying a new serial adapter ;)

I am completely stuck :(

Can anyone support me on this ?
Thanks in advance :D
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USART3 issue : weird characters received on PC

Post by Giovanni »

Hi,

Are you getting the problem with just USART3 or even other USARTs?

You should also verify the communication settings on the PC side.

Giovanni
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: USART3 issue : weird characters received on PC

Post by Nemesis2065 »

Hi Giovanni,

No, I am getting this problem with the others USARTs.
I tried SD1, SD3, UART2 and I have the same problem.

I verified my PC configuration and the USB Serial Port (COM4) on the PC is well configured to : 38400-8-N-1, no flow control.
It is the same configuration for putty.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USART3 issue : weird characters received on PC

Post by Giovanni »

Hi,

There should be something in you setup because the serial driver is well known. Please try to run the ./testhal/STM32F4xx/IRQ_STORM application, it produces an output on the serial port 2.

Also, what toolchain are you using? a lot of problems are often originated there.

Giovanni
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: USART3 issue : weird characters received on PC

Post by Nemesis2065 »

Hi,

I agree whit you, the serial driver should not be a problem.

I just tested the demo code located under : ./demos/ARMCM4-STM32F407-DISCOVERY, and flashed the .hex file
When I press the user button, the test is running but I still have the problem.

It means that my config is not the issue.
I will try this week to connect the stm32f4 board to my RaspberryPi uart input to see if I have the same issue with the demo code.

The toolchain I am using is :
yagarto-20121222
yagarto-tools-20121018

I followed the steps of : Getting started with the STM32F4-Discovery board and ChibiOS/RT
http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:stm32f4_discovery
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USART3 issue : weird characters received on PC

Post by Giovanni »

Hi,

Could you give a try to ChibiStudio? it is an pre-integrated Eclipse with everything required. This would allow to rule out toolchain problems. It already includes also the latest ChibiOS and demos.

Giovanni
User avatar
toxygen
Posts: 24
Joined: Tue Mar 13, 2012 9:54 pm

Re: USART3 issue : weird characters received on PC

Post by toxygen »

Have you tried serial console with different bitrates?
My guess is that your terminal is misconfigured, either in bitrate or in checksum bit or something similar.
User avatar
Nemesis2065
Posts: 20
Joined: Fri Nov 15, 2013 9:53 am

Re: USART3 issue : weird characters received on PC

Post by Nemesis2065 »

Hi,

Unfortunately, yes... that was the first think I have done. I tried with TeraTerm and putty with all possible baud-rate and configurations and even on 3 different computers...
Everything is configured like this : 38400-8-N-1, no flow control.
This is not the first time I use uart communication, I have done it before on PIC (18f/30f/32).

One possibility could be my serial adapter which looks like this one : http://www.electronics-lab.com/blog/wp-content/uploads/2008/05/usb-to-serial-rs232.jpg but with a ft232rl.
It could be a voltage level problem, but the ft232rl is 3.3vcompatible... so I don't know :(

The reason I want to test with the Raspberry Pi, is that it has a 3.3v gpio, So I would be able to plug the stm32f4 directly to the RaspPi and to know if it comes from the serial adapter.

Another possibility :
Does it exist different models of stm32f4 discovery board ? or just one type with an unique CortexM4 model ?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: USART3 issue : weird characters received on PC

Post by Giovanni »

There is the STM32F4-Discovery and the newer STM32F401C-Discovery. The demo is for the first one, the second would require small settings changes but I don't have one yet.

Try a simple max232 adapter if in doubt.

Giovanni
fractal
Posts: 16
Joined: Mon Oct 28, 2013 12:13 pm
Has thanked: 2 times
Been thanked: 5 times

Re: USART3 issue : weird characters received on PC

Post by fractal »

From my experience garbage characters most often come from mismatched clocks due to a clock system misconfiguration, wrong uart registers or a low quality clock source. With a devboard and example code this should not be the problem.
Try using a different terminal program (http://code.google.com/p/java-simple-se ... C_Terminal if you dont want to install one) and double check all settings, including the encoding. If that doesn't help modify an example code to spam a specific sequence of one or two chars and check which codes you receive. Eg, constantly send "dd2dd2dd2", which as decimal should be 100 100 50. What do you receive? Maybe the chars are being inverted (155 155 205) by your adapter (proper rs-232 has negative logic) or have some other operation applied to them?
Just my first ideas, hope it helps.
Thomas
Post Reply