AnsweredAssumed Answered

Getting garbage over USART1

Question asked by mcdowell.daniel on Mar 29, 2011
Latest reply on May 31, 2011 by faure.christian
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

Outcomes