2022-09-19 01:27 AM
I try to receive data with the USART1 in LIN mode using interrupts. Unfortunately I can't get it to work. This is the configuration of the USART1:
The signal on the LIN bus is composed of the LIN break (HAL_LIN_SendBreak(&huart1);), the sync part (HAL_UART_Transmit_IT(&huart1, 0x55, 1);) and an ID (HAL_UART_Transmit_IT(&huart1, 0x0A, 1);).
The signal looks proper on the oscilloscope. While debugging, I can observe that at least the LIN break is detected by the USART1 (LBDF is set). I expected, that at some point the HAL_UART_RxCpltCallback is called, but that never happens.
What am I doing wrong?
main.c:
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2022 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "cmsis_os.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "UART_DbgDef.h"
#include "stm32f7xx_ll_usart.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 ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
CAN_HandleTypeDef hcan3;
CRC_HandleTypeDef hcrc;
DMA2D_HandleTypeDef hdma2d;
I2C_HandleTypeDef hi2c3;
LTDC_HandleTypeDef hltdc;
QSPI_HandleTypeDef hqspi;
RTC_HandleTypeDef hrtc;
SAI_HandleTypeDef hsai_BlockA2;
TIM_HandleTypeDef htim4;
TIM_HandleTypeDef htim14;
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart6;
HCD_HandleTypeDef hhcd_USB_OTG_FS;
SDRAM_HandleTypeDef hsdram1;
osThreadId defaultTaskHandle;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void PeriphCommonClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_LTDC_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_CRC_Init(void);
static void MX_DMA2D_Init(void);
static void MX_FMC_Init(void);
static void MX_QUADSPI_Init(void);
static void MX_I2C3_Init(void);
static void MX_SAI2_Init(void);
static void MX_ADC1_Init(void);
static void MX_TIM14_Init(void);
static void MX_RTC_Init(void);
static void MX_CAN3_Init(void);
static void MX_USB_OTG_FS_HCD_Init(void);
static void MX_TIM4_Init(void);
static void MX_USART6_UART_Init(void);
void StartDefaultTask(void const * argument);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
UART_Debug("HAL_UART_RxCpltCallback");
}
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
{
UART_Debug("HAL_UART_RxHalfCpltCallback");
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
UART_Debug("HAL_UART_TxCpltCallback");
}
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart)
{
UART_Debug("HAL_UART_TxHalfCpltCallback");
}
/* 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();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LTDC_Init();
MX_USART1_UART_Init();
MX_CRC_Init();
MX_DMA2D_Init();
MX_FMC_Init();
MX_QUADSPI_Init();
MX_I2C3_Init();
MX_SAI2_Init();
MX_ADC1_Init();
MX_TIM14_Init();
MX_RTC_Init();
MX_CAN3_Init();
MX_USB_OTG_FS_HCD_Init();
MX_TIM4_Init();
MX_USART6_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* definition and creation of defaultTask */
// osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);
// defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* Start scheduler */
// osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
HAL_GPIO_WritePin(LIN__SLP_GPIO_Port, LIN__SLP_Pin, GPIO_PIN_SET); // Enable external LIN transceiver TJA1027T.
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(1000);
}
/* USER CODE END 3 */
}