cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to read UART and to hold on rx_data array. when I send "AT" to rf module it returns "OK" , but on my code I cannot receive anything from UART. and help appreciated

TPiri.1
Associate II

uint8_t tx_data[2] = "AT";

 uint8_t rx_data[10];

 HAL_Delay(1000);

 while (1)

 {

 HAL_UART_Transmit (&huart1, tx_data, sizeof(rx_data) , 250);

 HAL_Delay(500);

 HAL_UART_Receive(&huart1,rx_data, 20,1000);

 HAL_GPIO_TogglePin (GPIOA, LED_Pin);

 HAL_Delay(500);

}

37 REPLIES 37
MM..1
Chief II

add togle led and enable usart irq

I did like this , tried with both "AT" and "AT\r\n" same

uint8_t tx_data[4]="AT\r\n";

uint8_t rx_data[10];

/* USER CODE BEGIN 4 */

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

 HAL_UART_Receive_IT(&huart2, rx_data, 10);

}

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)

{

  HAL_UART_Transmit_IT(&huart2, tx_data, sizeof (tx_data));

}

int main(void)

{

 HAL_Init();

 /* Configure the system clock */

 SystemClock_Config();

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_USART2_UART_Init();

  

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 HAL_UART_Transmit_IT(&huart2, tx_data, 4);

 HAL_UART_Receive_IT (&huart2, rx_data, 10);

 HAL_GPIO_TogglePin (GPIOA, LD2_Pin);

 HAL_Delay (250);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}0693W00000HpgpkQAB.png

OK, back to really basic debugging:

  • Are you sure you the the UART configured to the pins that are actually connected radio?
  • Are you sure you have the correct baud rate
  • Do you have a scope so you can look at the TX and RX signals and see what they look like?
  • Is the radio expecting 3.3V signal levels? Or is it expecting RS/EIA-232 levels (unlikely, but never hurts to ask).
  • disconnect the radio and short your TX and RX pins together. You should see the "AT\n\n" echoed back to you. If not, you have a configuration issue.
MM..1
Chief II

No change to nonblocking IT code i say only enable IRQ nothing more.

Normal call isnt POLL but blocking .

IT and DMA is non blocking offload code.

Blink work?

And use

HAL_UART_Transmit (&huart2, "AT\r\n", 4 , 250);
HAL_UART_Receive(&huart2,rx_data, 10,1500);

  • pins are correct
  • baudrate correct
  • don't have scope
  • 3.3v signal level
  • shorted rx to tx, no data.

seems I have configuration issue. it was a good idea to short tx,rx, thanks. Could you instruct me top by step to re configure? I would really appreciate

TPiri.1
Associate II

now I tried to test other UART pins(uart1) , I shorted pins, now I receive only the first character of the data . how can I get all the transmitted data at once?0693W00000HpgymQAB.png

TPiri.1
Associate II

I changed the uart port it worked, thank you very much. don't know why on uncle uart2 , PA2,3 didn't work

TPiri.1
Associate II

code worked at Nucleo L476, but now I uploaded same code to custom board with STM32-L072KB chip, and shorted UART pins, I am sending "AT" from TX and receiving only 1st letter "A". anyone know why?

uint8_t tx_data[2]="AT";

uint8_t rx_data[10];

int main(void)

.......

while (1)

 {

  /* USER CODE END WHILE */

 HAL_UART_Transmit(&huart1,tx_data, sizeof (tx_data),1500);

 HAL_UART_Receive(&huart1,rx_data, 10,1500);

 HAL_Delay(1000);

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

note: UART baudrate 9600

Ahh
HAL_UART_Transmit(&huart1,tx_data, sizeof (tx_data),1500);
sends data out ... when ends all data is sended = no signals
now you call HAL_UART_Receive(&huart1,rx_data, sizeof (rx_data),1500);
receive for nothing ...
And A is received because receiver part is initialized when transmit is call and one byte is received by design.

I don't understand what you mean .

same code works fine on Nucleo-L476 board, but on L072 mcc I am running same code, having this issue