2024-07-19 12:35 PM
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;
}
}
}
Solved! Go to Solution.
2024-07-19 12:52 PM
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.
2024-07-19 12:52 PM
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.