本帖最后由 袁胜富 于 2023-10-21 18:59 编辑
一、概述 
在日常开发中经常使用USART开发,这篇文章一起来学习AT32F423的USART配置及使用吧。
二、AT32_Work_Bench配置

1.配置外设时钟
2.配置USART
3.时钟配置
4.生成工程配置
三、代码配置

1.串口中断服务函数代码。
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] this function handles USART1 handler.
- * @param none
- * @retval none
- */
- void USART1_IRQHandler(void)
- {
- /* add user code begin USART1_IRQ 0 */
- if(usart_flag_get(USART1, USART_RDBF_FLAG) != RESET)
- {
- usart_data_transmit(USART1,usart_data_receive(USART1));
- usart_flag_clear(USART1,USART_RDBF_FLAG);
- }
- /* add user code end USART1_IRQ 0 */
- /* add user code begin USART1_IRQ 1 */
- /* add user code end USART1_IRQ 1 */
- }
2.main函数代码。
- /**
- * [url=home.php?mod=space&uid=247401]@brief[/url] main function.
- * @param none
- * @retval none
- */
- int main(void)
- {
- /* add user code begin 1 */
- /* add user code end 1 */
- /* add a necessary delay to ensure that Vdd is higher than the operating
- voltage of battery powered domain (2.57V) when the battery powered
- domain is powered on for the first time and being operated. */
- wk_wait_for_power_stable();
-
- /* system clock config. */
- wk_system_clock_config();
- /* config periph clock. */
- wk_periph_clock_config();
- /* nvic config. */
- wk_nvic_config();
- /* init usart1 function. */
- wk_usart1_init();
- /* add user code begin 2 */
- /* enable usart2 and usart3 interrupt */
-
- usart_interrupt_enable(USART1, USART_RDBF_INT, TRUE);
-
- printf("USART Demo\r\n");
- /* add user code end 2 */
- while(1)
- {
- /* add user code begin 3 */
- /* add user code end 3 */
- }
- }
四、效果

|