cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401RE-Nucleo USART2 Communication Problem

nikosapostolakis94
Associate
Posted on August 27, 2016 at 23:19

I am developing a project on STM32F401RE-Nucleo which is about UART Communication.

In order to know how UART works out, I have implemented my first project.

I have connected D0 to D1 (USART2 RX to TX ) , so that I want to receive what I just sent.

Here is my configuration:

void uart_init() {

    USART_InitTypeDef usart2_init_struct;

    GPIO_InitTypeDef gpioa_init_struct;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);

    gpioa_init_struct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;

    gpioa_init_struct.GPIO_Speed = GPIO_Speed_2MHz;

    gpioa_init_struct.GPIO_Mode = GPIO_Mode_AF;

    gpioa_init_struct.GPIO_OType = GPIO_OType_PP;

    gpioa_init_struct.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_Init(GPIOA, &gpioa_init_struct);

    usart2_init_struct.USART_BaudRate = 9600;

    usart2_init_struct.USART_WordLength = USART_WordLength_8b;

    usart2_init_struct.USART_StopBits = USART_StopBits_1;

    usart2_init_struct.USART_Parity = USART_Parity_No;

    usart2_init_struct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

    usart2_init_struct.USART_HardwareFlowControl =

    USART_HardwareFlowControl_None;

    USART_Init(USART2, &usart2_init_struct);

    USART_Cmd(USART2, ENABLE);

    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

    NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable the USARTx Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    NVIC_EnableIRQ(USART2_IRQn);

}

and my main func:

int main(void) {

    uart_init();

    while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) != RESET) {

        USART_SendData(USART2, (uint16_t) 0x00ff);

    }

    while (1)

        ;

}

USART_SendData gets called.

I have also set an USART2_IRQHandler() which however never gets triggered.

That is my problem.

My question is whether it is a software problem or not.

I dont believe it is a hardware problem, because it is just a connection between D0 and D1 ( RX <-> TX )
3 REPLIES 3
Posted on August 28, 2016 at 00:54

USART2 is primarily connected to the ST-LINK VCP, to get it functioning properly on the Arduino shield socket you're probably going to need to tinker with some of the solder bridges. Review the User Manual for the Nucleo 64 board.It is also likely to blow through the first while() loop, you'd want to code this differently if you want to send a stream of characters.

https://community.st.com/my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/USART%20example%20code%20for%20Nucleo%20F401RE&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=2938

https://community.st.com/0D50X00009XkgXFSAZ

 

Edit: Fixed DEAD LINK, original post from August 27, 2016

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nikosapostolakis94
Associate
Posted on August 28, 2016 at 01:30

Excuse me for further questions, but I am beginner with this board.

Why D0/D1 cannot be used for RX/TX? I have read a manual and it says that there are used for USART2 RX/TX.

Posted on August 28, 2016 at 04:16

I'd surmise the primary use case is for mbed debugging and interaction, the secondary as a stand-alone Arduino. The number of USARTs is limited on a number of STM32 parts. The Nucleo-144 has more pins and options. The

http://www.st.com/content/ccc/resource/technical/document/user_manual/98/2e/fa/4b/e0/82/43/b7/DM00105823.pdf/files/DM00105823.pdf/jcr:content/translations/en.DM00105823.pdf

describes the need to change the solder bridges, or use jumper/patch wires to get the functionality desired.

6.8 USART communication

The USART2 interface available on PA2 and PA3 of the STM32 microcontroller can be connected to ST-LINK MCU, ST morpho connector or to Arduino connector. The choice can be changed by setting the related solder bridges. By default the USART2 communication between the target MCU and ST-LINK MCU is enabled, in order to support Virtual Com Port for mbed (SB13 and SB14 ON, SB62 and SB63 OFF). If the communication between the target MCU PA2 (D1) or PA3 (D0) and shield or extension board is required, SB62 and SB63 should be ON, SB13 and SB14 should be OFF. In such case it is possible to connect another USART to ST-LINK MCU using flying wires between ST morpho connector and CN3. For instance on NUCLEO-F103RB it is possible to use USART3 available on PC10 (TX) and PC11 (RX). Two flying wires need to be connected as follow:

• PC10 (USART3_TX) available on CN7 pin 1 to CN3 pin RX

• PC11 (USART3_RX) available on CN7 pin 2 to CN3 pin TX

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