AnsweredAssumed Answered

USART2 Configuration Problem

Question asked by carter.bob on Jan 7, 2013
Latest reply on Jan 18, 2013 by carter.bob
Hi,
I'm trying to read data from an external modem using USART2. PA2=RXD and PA3=TXD. The RXD only drives to about 1 volt.
which is why I can't read anything. Is the following code setting up the pins correctly or do they need to be swapped around.
I also have my suspicions about the interrupt handler so if someone could check.

Appreciate any help.
Regards
Bob

Here is my configuration...


void Usart2Init(void)
{        
  USART_InitTypeDef USART_InitStructure;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
 
  /* Enable GPIOA and DMA clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);
 
  /* Enable USART1 APB clock */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
 
  /* USART1 Pins configuration **************************************************/
  GPIO_DeInit(GPIOA);
 
  /* Connect pin to Periph */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);    
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
 
  /* Configure pins as AF pushpull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 
  /* USARTx configured as follow:
  - BaudRate = 19200 baud  
  - Word Length = 8 Bits
  - Stop Bit = 1 Stop Bit
  - Parity = No Parity
  - Hardware flow control disabled (RTS and CTS signals)
  - Receive and transmit enabled
  */
 
//  USART_DeInit(USART2);
  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 CO21 Receive interrupt: this interrupt is generated when the
//  COM1 receive data register is not empty */
  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
 
  /* USART1 IRQ Channel configuration */
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);        
    
    }



void USART2_IRQHandler(void)
{
char rx_byteb;    

    if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
         {
        rx_byteb = (char)USART_ReceiveData(USART2);
        printf("%c",rx_byteb);
         }

}

Outcomes