cancel
Showing results for 
Search instead for 
Did you mean: 

Can usart break? stm32f0Discovery

stivcrc
Associate
Posted on July 30, 2013 at 10:23

I connect USART1 or 2 via adapter Usb2Com but the terminal displays strange symbols....

&sharpinclude ''stm32f0xx.h''

&sharpinclude ''stm32f0xx_rcc.h''

&sharpinclude ''stm32f0xx_gpio.h''

&sharpinclude ''stm32f0xx_usart.h''

 

 

 

 

int main(void)

     USART_InitTypeDef USART_InitStructure;

      GPIO_InitTypeDef GPIO_InitStructure;

 

      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  

      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);

    

      GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);

      GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);

 

 

      //Configure USART2 pins:  Tx and Rx ----------------------------

      GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2 | GPIO_Pin_3;

      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

      GPIO_Init(GPIOA, &GPIO_InitStructure);

 

 

      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_Rx | USART_Mode_Tx;

      USART_Init(USART2, &USART_InitStructure);

 

 

      USART_Cmd(USART2,ENABLE);

  

 

      while(1)

      { 

 

       while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); // Wait for Empty

 

 

           USART_SendData(USART2, '3'); // Send 'I'

      }

      return 0;

    }

#stm32 #discovery
4 REPLIES 4
crt2
Associate II
Posted on July 30, 2013 at 12:03

First hint: baudRate, second hint - encoding.

What bothers me is this comment: USART_SendData(USART2, '3'); // Send 'I' <---????

Care to explain?

stivcrc
Associate
Posted on July 30, 2013 at 12:31

Yes, there is not erased the comment, I tried to bring other characters... 

crt2
Associate II
Posted on July 30, 2013 at 14:44

So is receiving part of terminal set properly? You are trying to send '3' ASCII (hopefully) and you should receive anything like 51 0x33 or something - really dependent how you set your receiving terminal.

Posted on July 30, 2013 at 17:20

Is your adapter expecting RS232 levels? That's not what the STM32 emits.

Have you looked at the signal with a scope, and confirmed the bit timings?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..