AnsweredAssumed Answered

Receiving bad character through the USART

Question asked by mnem on Jul 10, 2015
Latest reply on Jul 13, 2015 by Clive One
Hi, I am working in a wired point to point communication system but I have a problem receiving characters.

I have two electronics communicating each other through USART. I want to send a char periodically from the transmitter (TX) to the receiver (RX) but RX does not read the same char sent from TX.

TX is the development kit STM32F4 Discovery. I have no problems sending chars through USART1 in this kit. For my tests I just send the same char periodically. 

RX is my own design where I use the microcontroller STM32F405. I use USART2 to receive the chars from TX.

The configuration of the USART is the same in TX (USART1) and RX (USART2). It is as follows:

void USART1_Config(){
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

    // Configure AF (Alternate Function) of pins PA0, PA1
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

    USART_InitStructure.USART_BaudRate = 2400;
    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;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

    // Configure USART Tx
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    // Configure USART Rx
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    USART_Init(USART1, &USART_InitStructure);
    USART_Cmd(USART1, ENABLE);

    // Config IT
    NVIC_InitTypeDef NVIC_InitStructure;
    // Enable the USARTx Interrupt RX
    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    // Config RX IT USARTx
    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
}

As I want to check all the characters received in RX I have my interrupt routine as it is indicated next:

void USART2_IRQHandler(void){
    if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
      {
        /* Read one byte from the receive data register */
        char rxchar = USART_ReceiveData(USART2);
        ...
      }
}

The problem is that the variable rxchar does not contain the same character sent from TX. I have checked the signal from RX and TX with an oscilloscope and they are the same (as it was expected since the system is wired point-to-point). At this point I suppose that the problem is related to the USART configuration but both have the same. I am completely getting stuck on this and I don't know what can I do.

Can anybody help me with this? Thank you very much in advance for your help.

Greetings!
mnem

Outcomes