Problems with UART Interrupt Receive
Hello, i have a STM32F407VET6 MCU and i have problems with UART3 and Interrupt Receive, it does not work.
UART3 is connected with a Display, my MCU sends every Second a "PING" and the Display answers with "PONG", that works fine.
Global Interrupt for UART3 is enabled, with Prio 1.
With a Serialadapter, i see the "PING", and the "PONG" answer, but the Interrupt is not working/fired.
What i do wrong? Is there a problem with RTOS?
UART_HandleTypeDef huart3;
uint8_t uartData[64];
/* Definitions for hmiTask */
osThreadId_t hmiTaskHandle;
const osThreadAttr_t hmiTask_attributes = {
.name = "hmiTask",
.stack_size = 1024 * 4,
.priority = (osPriority_t) osPriorityBelowNormal,
};
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart == &huart3)
{
HAL_UART_Receive_IT(&huart3, uartData, sizeof(uartData));
}
}
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_ADC1_Init();
MX_CAN1_Init();
MX_I2C1_Init();
MX_RTC_Init();
MX_SDIO_SD_Init();
MX_SPI1_Init();
MX_USART3_UART_Init();
MX_USART6_UART_Init();
MX_FATFS_Init();
MX_TIM2_Init();
MX_CRC_Init();
/* Initialize interrupts */
MX_NVIC_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start(&htim2);
HAL_ADC_Start(&hadc1);
initGpio();
HAL_UART_Receive_IT(&huart3, uartData, sizeof(uartData));
/* USER CODE END 2 */
/* Init scheduler */
osKernelInitialize();
/* 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) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of radioTask */
radioTaskHandle = osThreadNew(radioTaskFunc, NULL, &radioTask_attributes);
/* creation of hmiTask */
hmiTaskHandle = osThreadNew(hmiTaskFunc, NULL, &hmiTask_attributes);
/* creation of batteryMeas */
batteryMeasHandle = osThreadNew(battTask, NULL, &batteryMeas_attributes);
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_EVENTS */
/* add events, ... */
RFM23 *rfm23 = new RFM23();
if(!rfm23->init())
{
while(true)
{
HAL_GPIO_WritePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin, GPIO_PIN_SET);
delay_us(200);
HAL_GPIO_WritePin(LED_ERROR_GPIO_Port, LED_ERROR_Pin, GPIO_PIN_RESET);
}
}
HAL_GPIO_WritePin(LED_LINK_TX_GPIO_Port, LED_LINK_TX_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(LED_LINK_RX_GPIO_Port, LED_LINK_RX_Pin, GPIO_PIN_SET);
delay_us(350);
HAL_GPIO_WritePin(LED_LINK_TX_GPIO_Port, LED_LINK_TX_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(LED_LINK_RX_GPIO_Port, LED_LINK_RX_Pin, GPIO_PIN_RESET);
/* creation of radioTask */
radioTaskHandle = osThreadNew(radioTaskFunc, NULL, &radioTask_attributes);
/* USER CODE END RTOS_EVENTS */
/* Start scheduler */
osKernelStart();
/* We should never get here as control is now taken by the scheduler */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/**
* @brief USART3 Initialization Function
* @param None
* @retval None
*/
static void MX_USART3_UART_Init(void)
{
/* USER CODE BEGIN USART3_Init 0 */
/* USER CODE END USART3_Init 0 */
/* USER CODE BEGIN USART3_Init 1 */
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART3_Init 2 */
/* USER CODE END USART3_Init 2 */
}
/* USER CODE BEGIN Header_hmiTaskFunc */
/**
* @brief Function implementing the hmiTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_hmiTaskFunc */
void hmiTaskFunc(void *argument)
{
/* USER CODE BEGIN hmiTaskFunc */
/* Infinite loop */
while(true)
{
if(!displayPresent)
{
uint8_t data[] = "PING;;;;;";
HAL_UART_Transmit_IT(&huart3, data, sizeof(data));
osDelay(1000);
}
}
/* USER CODE END hmiTaskFunc */
}