cancel
Showing results for 
Search instead for 
Did you mean: 

Doesn't Work Uart Interrupt

AlexanderKibarov
Associate III

I can transmit data in this code, but I cannot receive data with an interrupt. Can you help me?

Code:

#include "main.h"

#include "kibar_nextion.h"

#include <string.h>

 

UART_HandleTypeDef huart4;

UART_HandleTypeDef huart3;

 

uint8_t main_buffer[13];

uint8_t pure_buffer[13];

uint8_t rx_buffer[1];

volatile uint8_t address = 0;

 

int main(void)

{

HAL_Init();

 

SystemClock_Config();

 

MX_GPIO_Init();

MX_USART3_UART_Init();

MX_USB_OTG_FS_PCD_Init();

MX_UART4_Init();

 

__HAL_UART_ENABLE_IT(&huart4, UART_IT_RXNE);

KIBAR_NEXTION_ kibar_nextion = KIBAR_NEW_NEXTION();

kibar_basic_configuration_nextion(kibar_nextion, &huart4);

 

while (1)

{

for(int i = 0; i < 360; i++) {

uint8_t last_data[] = {255, 255, 255};

HAL_UART_Transmit(kibar_nextion->kibar_uart_, (uint8_t*)"main_screen.n0.val=", sizeof("main_screen.n0.val=") - 1, 100);

HAL_UART_Transmit(kibar_nextion->kibar_uart_, (uint8_t*)kibar_return_array_char_from_16_t(i), kibar_size_integer_data_16_t(i), 100);

HAL_UART_Transmit(kibar_nextion->kibar_uart_, last_data, 3, 100);

HAL_UART_Transmit(kibar_nextion->kibar_uart_, (uint8_t*)"main_screen.z0.val=", sizeof("main_screen.z0.val=") - 1, 100);

HAL_UART_Transmit(kibar_nextion->kibar_uart_, (uint8_t*)kibar_return_array_char_from_16_t(i), kibar_size_integer_data_16_t(i), 100);

HAL_UART_Transmit(kibar_nextion->kibar_uart_, last_data, 3, 100)

}

}

}

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

HAL_UART_Receive(&huart4, &rx_buffer[0], 1, 20);

main_buffer[address] = rx_buffer[0];

address++;

if(address == 14) {

address = 0;

for(int i = 0; i < 13; i++) {

pure_buffer[i] = main_buffer[i];

main_buffer[i] = 0;

}

}

}

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

You have to enable reception with a call to HAL_UART_Receive_IT or similar. You don't do that anywhere in the main loop. You can't use a blocking HAL_UART_Receive call if you're using blocking transmission calls.

There are plenty of CubeMX examples to go off of.

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

View solution in original post

1 REPLY 1
TDK
Guru

You have to enable reception with a call to HAL_UART_Receive_IT or similar. You don't do that anywhere in the main loop. You can't use a blocking HAL_UART_Receive call if you're using blocking transmission calls.

There are plenty of CubeMX examples to go off of.

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