stm32f103系列和stm32g030系列处理不同:
stm32f103关于USART_TypeDef定义:
typedef struct
{
__IO uint32_t SR; /*!< USART Status register, Address offset: 0x00 */
__IO uint32_t DR; /*!< USART Data register, Address offset: 0x04 */
__IO uint32_t BRR; /*!< USART Baud rate register, Address offset: 0x08 */
__IO uint32_t CR1; /*!< USART Control register 1, Address offset: 0x0C */
__IO uint32_t CR2; /*!< USART Control register 2, Address offset: 0x10 */
__IO uint32_t CR3; /*!< USART Control register 3, Address offset: 0x14 */
__IO uint32_t GTPR; /*!< USART Guard time and prescaler register, Address offset: 0x18 */
} USART_TypeDef;
中断服务函数
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
uint32_t tmp_flag = 0;
uint32_t temp;
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
/* USER CODE BEGIN USART1_IRQn 1 */
tmp_flag = __HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE);
if(tmp_flag != RESET)
{
__HAL_UART_CLEAR_IDLEFLAG(&huart1);
temp = huart1.Instance->SR; //读取串口状态寄存器
temp = huart1.Instance->DR; //读取串口数据寄存器
HAL_UART_DMAStop(&huart1);
temp = hdma_usart1_rx.Instance->CNDTR; //读取DMA剩余传输数量
rx_len = 100- temp;
recv_end_flag = 1;
}
/* USER CODE END USART1_IRQn 1 */
}
stm32g030:寄存器比较细致
typedef struct
{
__IO uint32_t CR1; /*!< USART Control register 1, Address offset: 0x00 */
__IO uint32_t CR2; /*!< USART Control register 2, Address offset: 0x04 */
__IO uint32_t CR3; /*!< USART Control register 3, Address offset: 0x08 */
__IO uint32_t BRR; /*!< USART Baud rate register, Address offset: 0x0C */
__IO uint32_t GTPR; /*!< USART Guard time and prescaler register, Address offset: 0x10 */
__IO uint32_t RTOR; /*!< USART Receiver Time Out register, Address offset: 0x14 */
__IO uint32_t RQR; /*!< USART Request register, Address offset: 0x18 */
__IO uint32_t ISR; /*!< USART Interrupt and status register, Address offset: 0x1C */
__IO uint32_t ICR; /*!< USART Interrupt flag Clear register, Address offset: 0x20 */
__IO uint32_t RDR; /*!< USART Receive Data register, Address offset: 0x24 */
__IO uint32_t TDR; /*!< USART Transmit Data register, Address offset: 0x28 */
__IO uint32_t PRESC; /*!< USART Prescaler register, Address offset: 0x2C */
} USART_TypeDef;
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
uint32_t tmp_flag = 0;
uint32_t temp;
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
/* USER CODE BEGIN USART1_IRQn 1 */
tmp_flag = __HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE);
if(tmp_flag != RESET)
{
__HAL_UART_CLEAR_IDLEFLAG(&huart1);
temp = huart1.Instance->ISR; //读取串口状态寄存器
temp = huart1.Instance->RDR; //读取串口数据寄存器
HAL_UART_DMAStop(&huart1);
temp = hdma_usart1_rx.Instance->CNDTR; //读取DMA剩余传输数量
rx_len = 100- temp;
recv_end_flag = 1;
}
/* USER CODE END USART1_IRQn 1 */
}