基于ATxmega128的ASF串口应用
Posted fzlgyz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于ATxmega128的ASF串口应用相关的知识,希望对你有一定的参考价值。
1、编辑串口的配置参数,一般将这些参数放在conf_usart.h配置头文件中,本程序将这些参数放在user_board.h头文件中
#define USART_SERIAL &USARTD0 //使用USARTD0作为串口
#define USART_SERIAL_BAUDRATE 9600 //波特率设置为9600
#define USART_SERIAL_CHAR_LENGTH USART_CHSIZE_8BIT_gc //字符长度8位
#define USART_SERIAL_PARITY USART_PMODE_DISABLED_gc //无校验位
#define USART_SERIAL_STOP_BIT false //1位停止位
2、发送一个字符a;
int main (void)
sysclk_init(); //系统时钟初始化,默认主时钟;
board_init(); //板卡初始化,打开IO时钟,初始化引脚等
static usart_rs232_options_t USART_SERIAL_OPTIONS =
.baudrate = USART_SERIAL_BAUDRATE,
.charlength = USART_SERIAL_CHAR_LENGTH,
.paritytype = USART_SERIAL_PARITY,
.stopbits = USART_SERIAL_STOP_BIT
;
sysclk_enable_module(SYSCLK_PORT_D,PR_USART0_bm);
usart_init_rs232(USART_SERIAL, &USART_SERIAL_OPTIONS); //串口初始化
usart_putchar(USART_SERIAL,‘a‘);//通过串口发送一个字符
3、接收一个字符,并回传
int main (void)
/* Insert system clock initialization code here (sysclk_init()). */
sysclk_init(); //系统时钟初始化,默认主时钟;
board_init(); //板卡初始化,打开IO时钟,初始化引脚等
static usart_rs232_options_t USART_SERIAL_OPTIONS =
.baudrate = USART_SERIAL_BAUDRATE,
.charlength = USART_SERIAL_CHAR_LENGTH,
.paritytype = USART_SERIAL_PARITY,
.stopbits = USART_SERIAL_STOP_BIT
;
sysclk_enable_module(SYSCLK_PORT_D,PR_USART0_bm);
usart_init_rs232(USART_SERIAL, &USART_SERIAL_OPTIONS); //串口初始化
received_byte = usart_getchar(USART_SERIAL);//接收一个字符
usart_putchar(USART_SERIAL,received_byte);//将接收的字符发出
/* Insert application code here, after the board has been initialized. */
以上是关于基于ATxmega128的ASF串口应用的主要内容,如果未能解决你的问题,请参考以下文章
物联网无线串口WiFi模块,智能生活无线应用,无线WiFi模组技术
STC32G单片机驱动1.8寸TFT LCD128X160 ST7735S SPI串口驱动示例