0
\$\begingroup\$

I am using a NUCLEO-F401RE board as a master and a B-L072CZ-LRWAN1 as a slave communicating over UART.

Slave is configured to receive in interrupt mode using HAL_UART_Receive_IT. Master is programmed to request data to the slave with a blocking function using HAL_UART_Transmit inside a timer interrupt callback.

Master is asking for data to slave every minute and the protocol is working fine, but I want the code to work no matter what happens with the boards, so I am turning off both boards (one at a time) to see if everything works fine when they turn on again (to recover from any sort of error in the system).

Communication between them stops working when I turn off the slave (let me explain). If master tries to communicate when slave is off, it gets stucked in HAL_UART_Transmit function so even when I turn on slave, communication never happens again.

Does anybody knows what is happening?

Here is pin configuration:

Master

/**USART1 GPIO Configuration
PA9      ------> USART1_TX
PA10     ------> USART1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP; 
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

Slave

/**USART1 GPIO Configuration
PB6     ------> USART1_TX
PA10     ------> USART1_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_6;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_USART1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP; 
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
\$\endgroup\$
  • 2
    \$\begingroup\$ "If master tries to communicate when slave is off, it gets stucked in HAL_UART_Transmit function" that makes no sense. First, it should not matter if anyone is listening or not. But even if it did, a debugging question would require that you document where it gets stuck. \$\endgroup\$ – Chris Stratton Apr 4 at 19:01
  • 1
    \$\begingroup\$ Share your UART send/receive code. \$\endgroup\$ – Bence Kaulics Apr 4 at 19:06
0
\$\begingroup\$

I finally found the problem. As I said, I was using HAL UART functions (HAL_UART_Transmit/HAL_UART_Receive) inside a timer interrupt callback.

This timer interrupt had higher priority than system's systick so the timeout of UART functions (that make use of systick) could not trigger.

In this case, timeout does not affect if slave is connected and communication can be done. However, if slave is disconnected and master tries to communicate, master gets stucked in UART functions because of timeout.

\$\endgroup\$
-2
\$\begingroup\$

Yes, the HAL_UART_Transmit is not robust; you either need to fix it, or work around the problem.

\$\endgroup\$
  • \$\begingroup\$ This does not provide any useful information to help ascertain why the function is not robust or how it should be fixed. \$\endgroup\$ – David Apr 4 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.