#include "uart.h" #include "main.h" #include #include #include uint8_t * uart_tx_buf; uint8_t uart_tx_busy=0; uint16_t uart_tx_counter=0; uint16_t uart_tx_len=0; uint8_t * uart_rx_buf; uint8_t uart_rx_busy=0; uint16_t uart_rx_counter=0; uint16_t uart_rx_len=0; extern uint16_t last_rx_time; extern UART_HandleTypeDef huart1; #define TXEN_ON HAL_GPIO_WritePin(TXEN_GPIO_Port, TXEN_Pin, GPIO_PIN_SET) #define TXEN_OFF HAL_GPIO_WritePin(TXEN_GPIO_Port, TXEN_Pin, GPIO_PIN_RESET) void USER_UART1_IRQHandler(UART_HandleTypeDef *huart) { uint8_t data; if((huart1.Instance->ISR & USART_ISR_RXNE) != RESET) { last_rx_time = 0; data = (uint8_t)(huart1.Instance->RDR & (uint8_t)0x00FF); // читает байт из регистра if(uart_rx_busy) { uart_rx_buf[uart_rx_counter]=data; if(++uart_rx_counter == uart_rx_len) { uart_rx_busy = 0; UART_RxCpltCallback(); } } } if((uart_tx_busy)&&((huart1.Instance->ISR & USART_ISR_TC) != RESET)) { if(++uart_tx_counter == uart_tx_len) { TXEN_OFF; uart_tx_busy = 0; UART_TxCpltCallback(); __HAL_UART_DISABLE_IT(&huart1, UART_IT_TC); } else //putchar(uart_tx_buf[uart_tx_counter]); huart->Instance->TDR=uart_tx_buf[uart_tx_counter]; } huart->Instance->ICR=0xFFFFFFFF; } uint8_t UART_Receive_IT(uint8_t * data, uint16_t len, uint16_t timeout) { uint16_t i; //if(len>UART_RX_LEN)return RET_OVERFLOW; for(i=0;iTDR=uart_tx_buf[0]; //putchar(uart_tx_buf[0]); __HAL_UART_ENABLE_IT(&huart1, UART_IT_TC); return RET_OK; }