I cannot receive data while using USB to UART for NUCLEO-F411RE
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:

Can anyone help? Thank you so much.


