cancel
Showing results for 
Search instead for 
Did you mean: 

I cannot receive data while using USB to UART for NUCLEO-F411RE

deta
Associate II

Hello everyone, sorry if this is too easy of a task but I am quite frustrated. Can anyone help? I want to use CP2102 USB to UART bridge to send data from my PC to my Nucleo, then send the exact same data from my Nucleo to the PC so I know that the data has been received successfully. I have connected the Tx of CP2102 to the Rx of UART2 and Rx of CP2102 to the Tx of UART2, then connected the grounds and VCCs of the chip and board together (I am using 3.3V for this project. The baudrate I am currently using is 115200 but I have used 9600 with no changes to the result. I have also changed the UART ports I have used, to no avail: Did both receiver and transmitter on UART1, the receiver on UART1 with the transmitter on UART2, the receiver on UART2 with the transmitter on UART1... I thought maybe my CP2102 was faulty but when I short TX and RX I do get the echo of my typing back so that was not it either.

The CP2102's transmitter's LED is blinking when I type, which is a good sign, but the receiver's LED is not. I thought the problem was my code so I used an ST-link to verify if this is a valid code. The code works perfectly fine with an ST-link. This is the code I have:

 

 

uint8_t rx_indx;

uint8_t rx_data[1];

uint8_t rx_buffer[100];

uint8_t transfer_cplt;

int main(void)

{

HAL_Init();

MX_GPIO_Init();

MX_USART2_UART_Init();

HAL_UART_Receive_IT(&huart2, rx_data, 1);

while (1)

{

if(HAL_OK == HAL_UART_Receive(&huart2,rx_data,1,10)){

HAL_UART_Transmit(&huart2,rx_data,1,10);}

/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}

}



void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

/* Prevent unused argument(s) compilation warning */

UNUSED(huart);

uint8_t i;

if(huart->Instance == USART2) {

if(rx_indx == 0) {

for(i=0;i<100;i++) {

rx_buffer[i] = 0;

}

HAL_UART_Transmit(&huart2, "", 1,100);

HAL_UART_Transmit(&huart2,rx_data,1,100);

if(rx_data[0] != 13) {

rx_buffer[rx_indx] = rx_data[0];

}

else {

transfer_cplt = 1;

HAL_UART_Transmit(&huart2,"\n\r",2,100);

if(!strcmp(rx_buffer,"LED ON")) {

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 1);

}

}

HAL_UART_Receive_IT(&huart2, rx_data, 1);

HAL_UART_Transmit(&huart2, strlen(rx_data), 1, 100);

}

}

}

 

And the screenshot of the pin-out diagram:

deta_0-1719387732743.png

 

 

Can anyone help? Thank you so much.

1 ACCEPTED SOLUTION

Accepted Solutions

@deta wrote:

 I have connected the Tx of CP2102 to the Rx of UART2 and Rx of CP2102 to the Tx of UART2, Can anyone help? Thank you so much.


The on-board ST-Link's USB-to-UART ("VCP") is already connected to UART2:

AndrewNeil_0-1719390357327.png

https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf 

so you're going to have to disconnect the ST-Link VCP for the external CP2102 to work:

AndrewNeil_1-1719390536458.png

Or use a different UART.

See also:

https://community.st.com/t5/stm32-mcus-products/uart-in-stm32-l432kc/m-p/687848/highlight/true#M252756

And:

https://community.st.com/t5/stm32-mcus-boards-and-hardware/uart-not-receiving-data-when-sent-through-putty/td-p/687406

 

#STLinkVCP #VCPconflict #DisconnectVCP

 

View solution in original post

5 REPLIES 5
gbm
Lead III

Start with simple echo in a while loop, no interrupts, then move to something more ambitious. Your interrupt code contains many errors.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
deta
Associate II

Thank you for your reply, may I ask what exactly the errors are? It works fine with an ST-link so I thought that it was fine, even if not ideal. I would love to learn what I can improve.


@deta wrote:

 I have connected the Tx of CP2102 to the Rx of UART2 and Rx of CP2102 to the Tx of UART2, Can anyone help? Thank you so much.


The on-board ST-Link's USB-to-UART ("VCP") is already connected to UART2:

AndrewNeil_0-1719390357327.png

https://www.st.com/resource/en/user_manual/um1724-stm32-nucleo64-boards-mb1136-stmicroelectronics.pdf 

so you're going to have to disconnect the ST-Link VCP for the external CP2102 to work:

AndrewNeil_1-1719390536458.png

Or use a different UART.

See also:

https://community.st.com/t5/stm32-mcus-products/uart-in-stm32-l432kc/m-p/687848/highlight/true#M252756

And:

https://community.st.com/t5/stm32-mcus-boards-and-hardware/uart-not-receiving-data-when-sent-through-putty/td-p/687406

 

#STLinkVCP #VCPconflict #DisconnectVCP

 

Thank you! Thanks to the reply above you as well as your kind reply (I never thought to disconnect the ST-link, I thought that it'd be fine as long as it was not connected), I was able to finally communicate using the external usb-uart bridge. Thank you for the additional sources as well.

You're welcome - please mark the solution.

 


@deta wrote:

I never thought to disconnect the ST-link, I thought that it'd be fine as long as it was not connected.


The physical connection from the ST-Link's UART to the Target MCU's UART is hard-wired on the board - it's there whether or not the USB is active.

This is the same reason that NRST needs to be isolated when powering the target, but not powering the ST-Link; eg,

https://community.st.com/t5/stm32-mcus-products/3-3v-power-supply-for-nucleof103/m-p/657540/highlight/true#M239954