cancel
Showing results for 
Search instead for 
Did you mean: 

only 1 byte RS485 received on STM32L051

_alaBaster
Visitor

Hi there I am using STM32L051 to talk to a RS485 transceiver and I am having problem with the receive part.

System is as follow: laptop->FTDI USB converter-> Renesas transceiver -> STM32

I want to update the single byte buffer when a character is detected on the RX line by means of an interrupt.

Interrupt is detected the first time then microcontroller does not go into interrupt any longer on subsequent send of byte from the terminal. I can see that byte is on the uC pin with oscilloscope.

The main does nothing other than enabling the interrupt with __HAL_UART_ENABLE_IT, see below:

/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <string.h>
#include <stdio.h>
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart2;

/* USER CODE BEGIN PV */
uint8_t r;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/* MCU Configuration--------------------------------------------------------*/

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

/* USER CODE BEGIN Init */

/* USER CODE END Init */

/* Configure the system clock */
SystemClock_Config();

/* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();

/* USER CODE BEGIN 2 */
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);

HAL_GPIO_WritePin(RS485_DE_GPIO_Port, RS485_DE_Pin, GPIO_PIN_SET); //Pull DE high, enable transmit,

// The /RE pin is permanently low
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */

}
/* USER CODE END 3 */
}

 

The USART2_IRQHandler in stm32l0xx_it.c is modified, such that is actually receiving the byte:

void USART2_IRQHandler(void)
{
  /* USER CODE BEGIN USART2_IRQn 0 */
 
/* USER CODE END USART2_IRQn 0 */
  HAL_UART_IRQHandler(&huart2);
  /* USER CODE BEGIN USART2_IRQn 1 */
  HAL_UART_Receive_IT(&huart2, &r, 1);
  /* USER CODE END USART2_IRQn 1 */
}
 
Any hint, I appreciate! Thanx
2 REPLIES 2
Pavel A.
Evangelist III

Interrupt is detected the first time then microcontroller does not go into interrupt any longer on subsequent send of byte from the terminal.

Symptom of receiver overrun. Check for overrun and clear if it occurs.

 

TDK
Guru

You should be calling HAL_UART_Receive_IT before the main loop to start things off. Enabling RXNE interrupt isn't what HAL wants.

If you feel a post has answered your question, please click "Accept as Solution".