UART4 on STM32F407 not receiving data
static void MX_UART4_Init(void)
{
huart4.Instance = UART4;
huart4.Init.BaudRate = 9600;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}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_UART4_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
int x = 0;
unsigned char mydata[24];
HAL_UART_Receive_IT(&huart4, mydata, 2);
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if (x % 10000 == 0) {
HAL_UART_Transmit_IT(&huart4, (unsigned char*)"/1Q\r", 4);
//HAL_UART_Receive_IT(&huart4, mydata, 2);
}
++x;
}
/* USER CODE END 3 */
}void UART4_IRQHandler(void)
{
/* USER CODE BEGIN UART4_IRQn 0 */
/* USER CODE END UART4_IRQn 0 */
HAL_UART_IRQHandler(&huart4);
/* USER CODE BEGIN UART4_IRQn 1 */
/* USER CODE END UART4_IRQn 1 */
}Hello,
I'm trying to receive data on UART4 but cannot get it using either a call to HAL_UART_Receive_IT(&huart4, mydata, 2); or HAL_UART_Receive(&huart4, mydata, 2, 0xffff);
This code was generated using the STM32CubeMX program with only UART4 being enabled (and the system clock). Transmitting data works fine and I can see incoming data on the receive line. I can see the interrupt is enabled in Keil toolchain and all the bits seem to be set correctly in the UART registers. Also, I can get USART2 to work correctly.
Wonder if anyone might have an idea?
Many thanks,
Gary
P.S. I haven't included all the code because most of it is boilerplate from the Cube utility.
