cancel
Showing results for 
Search instead for 
Did you mean: 

Getting garbage over USART1

mcdowell
Associate
Posted on March 29, 2011 at 19:03

Hi All,

I have taken some of the sample code that comes with the stm8l-discovery eval board to try and talk to hyperterm on from stm8.  when i try to send anything all I see is garbage on the hyperterm screen...  I have verified both side have the same settings, 115200, no polarity, 1 stop bit, 8 bit word length - butstill it does not work.

Can I get some help to get this working?  My sample code snippet is as follows - can someone explain what I am doing wrong?

&sharpdefine DBG_COM1                   USART1

&sharpdefine DBG_COM1_GPIO              GPIOC

&sharpdefine DBG_COM1_CLK               CLK_Peripheral_USART1

&sharpdefine DBG_COM1_RxPin             GPIO_Pin_2

&sharpdefine DBG_COM1_TxPin             GPIO_Pin_3

&sharpdefine DBG_COM1_ClkPin            GPIO_Pin_4

typedef enum

{

   COM1 = 0

} COM_TypeDef;

USART_TypeDef* COM_USART[COMn] =

{

    DBG_COM1

};

 

GPIO_TypeDef* COM_PORT[COMn] =

{

    DBG_COM1_GPIO

};

const uint8_t COM_USART_CLK[COMn] =

{

    DBG_COM1_CLK

};

const uint8_t COM_TX_PIN[COMn] =

{

    DBG_COM1_TxPin

};

const uint8_t COM_RX_PIN[COMn] =

{

    DBG_COM1_RxPin

};

const uint8_t COM_CLK_PIN[COMn] =

{

    DBG_COM1_ClkPin

};

static void COMInit(COM_TypeDef COM, uint32_t USART_BaudRate,

                       USART_WordLength_TypeDef USART_WordLength,

                       USART_StopBits_TypeDef USART_StopBits,

                       USART_Parity_TypeDef USART_Parity,

                       USART_Mode_TypeDef USART_Mode)

{

 

  USART_DeInit(COM_USART[COM]);

   /* Enable USART clock */

   CLK_PeripheralClockConfig((CLK_Peripheral_TypeDef)COM_USART_CLK[COM], ENABLE);

 

   /* Configure USART Tx as alternate function push-pull  (software pull up)*/

   GPIO_ExternalPullUpConfig(COM_PORT[COM], COM_TX_PIN[COM] | COM_RX_PIN[COM] , ENABLE);

 

   /* USART configuration */

   USART_Init(COM_USART[COM], USART_BaudRate,

              USART_WordLength,

              USART_StopBits,

              USART_Parity,

              USART_Mode);

}

main()

{

...

   COMInit(COM1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1,

                    USART_Parity_No, USART_Mode_Tx | USART_Mode_Rx);

          

  USART_Cmd(COM_USART[COM1], ENABLE);

 

   //try to send a few bytes to hyperterm

   USART_SendData8(DBG_COM1, 0x41);

   while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET);

   USART_SendData8(DBG_COM1, 0x42);

   while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET);

...

when i do these writes all I see is garbage on PC hyperterm screen...

My h/w setup is as follows:

PC2 pin jumpered to TX on DB9 connector

PC3 pin jumpered to RX on DB9 connector

#usart-rs232
2 REPLIES 2
vincent.philippe
Associate II
Posted on April 06, 2011 at 10:24

Hi,

If you see garbage, I think that you have perhaps baud rate problems. In first I will check the baud rate initialization.

In fact, if you check in the driver functions the baud rate frequency depends of CPU clock frequency. I can suggest to you to check if these points:

> Check which clock is used in your application (LSI, HSI, ...);

> Check the CPU clock frequency;

> Check in USART register the values setted;

This is the first way ....

Other points, questions:

> In you application do you send the caracters one by one (place one break point after the first caracter is sent ( line: while( ....) ) and check it.?

> Have you try the reception from hyperterminal?

I hope that these points can help you.

Best regards

Philippe

Hi All,

I have taken some of the sample code that comes with the stm8l-discovery eval board to try and talk to hyperterm on from stm8.  when i try to send anything all I see is garbage on the hyperterm screen...  I have verified both side have the same settings, 115200, no polarity, 1 stop bit, 8 bit word length - butstill it does not work.

Can I get some help to get this working?  My sample code snippet is as follows - can someone explain what I am doing wrong?

#define DBG_COM1                   USART1

#define DBG_COM1_GPIO              GPIOC

#define DBG_COM1_CLK               CLK_Peripheral_USART1

#define DBG_COM1_RxPin             GPIO_Pin_2

#define DBG_COM1_TxPin             GPIO_Pin_3

#define DBG_COM1_ClkPin            GPIO_Pin_4

typedef enum

{

   COM1 = 0

} COM_TypeDef;

USART_TypeDef* COM_USART[COMn] =

{

    DBG_COM1

};

 

GPIO_TypeDef* COM_PORT[COMn] =

{

    DBG_COM1_GPIO

};

const uint8_t COM_USART_CLK[COMn] =

{

    DBG_COM1_CLK

};

const uint8_t COM_TX_PIN[COMn] =

{

    DBG_COM1_TxPin

};

const uint8_t COM_RX_PIN[COMn] =

{

    DBG_COM1_RxPin

};

const uint8_t COM_CLK_PIN[COMn] =

{

    DBG_COM1_ClkPin

};

static void COMInit(COM_TypeDef COM, uint32_t USART_BaudRate,

                       USART_WordLength_TypeDef USART_WordLength,

                       USART_StopBits_TypeDef USART_StopBits,

                       USART_Parity_TypeDef USART_Parity,

                       USART_Mode_TypeDef USART_Mode)

{

 

  USART_DeInit(COM_USART[COM]);

   /* Enable USART clock */

   CLK_PeripheralClockConfig((CLK_Peripheral_TypeDef)COM_USART_CLK[COM], ENABLE);

 

   /* Configure USART Tx as alternate function push-pull  (software pull up)*/

   GPIO_ExternalPullUpConfig(COM_PORT[COM], COM_TX_PIN[COM] | COM_RX_PIN[COM] , ENABLE);

 

   /* USART configuration */

   USART_Init(COM_USART[COM], USART_BaudRate,

              USART_WordLength,

              USART_StopBits,

              USART_Parity,

              USART_Mode);

}

main()

{

...

   COMInit(COM1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1,

                    USART_Parity_No, USART_Mode_Tx | USART_Mode_Rx);

          

  USART_Cmd(COM_USART[COM1], ENABLE);

 

   //try to send a few bytes to hyperterm

   USART_SendData8(DBG_COM1, 0x41);

   while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET);

   USART_SendData8(DBG_COM1, 0x42);

   while (USART_GetFlagStatus(DBG_COM1, USART_FLAG_TC) == RESET);

...

when i do these writes all I see is garbage on PC hyperterm screen...

My h/w setup is as follows:

PC2 pin jumpered to TX on DB9 connector

PC3 pin jumpered to RX on DB9 connector

Posted on May 31, 2011 at 15:38

Hi,

i'm not sure, but you may need a level shifter between  stm8l-discovery and PC port?