/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / USART2 on Primer2 extension connector

Username:     
Password:     
             

Forum

# 1   2010-09-01 08:51:40 USART2 on Primer2 extension connector

exin
New member
Registered: 2010-08-03
Posts: 2

USART2 on Primer2 extension connector

Hi!

I'm trying to use the USART2 RX and TX pins on the extension connector for a project. I've got the serial connection up and running against my host and can receive data. When I call USART_ReceiveData(USART2); I get the same byte over and over again though. This is the last (or only byte) sent to the Primer2. Any idea why it might behave this way?

Here is the inititation of USART2:
      USART_InitTypeDef USART_InitStructure;
      GPIO_InitTypeDef GPIO_InitStructure;

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE);
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
      /* Enable USART2 clocks */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

      /* Configure USART2 Tx (PA.2) as alternate function push-pull */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
      GPIO_Init(GPIOA, &GPIO_InitStructure);

      /* Configure USART2 Rx (PA.3) as input floating */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
      //GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
      GPIO_Init(GPIOA, &GPIO_InitStructure);
     
      /*USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
      USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
      USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge;
      USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
      USART_ClockInit(USART2, &USART_ClockInitStructure);*/
     
      USART_InitStructure.USART_BaudRate = 19200;
      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);


      /* Enable the USART2 */
      USART_Cmd(USART2, ENABLE);

And although I'm sending "ABC123" from the host I only get "3" or whatever the last byte I sent was no matter how many times I call USART_ReceiveData(USART2);.

Regards,
Gustaf Lindström

Last edited by exin (2010-09-01 08:52:01)

Offline

 

# 2   2010-09-03 06:49:25 USART2 on Primer2 extension connector

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: USART2 on Primer2 extension connector

Hi,

How do you manage reception : polling, interrupt, DMA ?
Because USART_ReceiveData(USART2) gives you the last byte received, since the last function call (RXNE flag reset by the read) you should get the first byte received, and may be lost the following.
Take a look at the ST library examples.

Regards,
Yves

Offline

 

# 3   2010-09-03 11:23:07 USART2 on Primer2 extension connector

exin
New member
Registered: 2010-08-03
Posts: 2

Re: USART2 on Primer2 extension connector

Hi!

Thanks for your response. I realized the buffer only holds the last byte received and has rewritten my code according to this. I for some reason made the assumption that a larger buffer was set up.

Regards,
Gustaf Lindström

Last edited by exin (2010-09-03 11:23:51)

Offline

 

Board footer