我是在 Atmel 工作室环境中开发的嵌入式系统的新手,我正在使用 Atxmega128a1 和 32MHz 系统时钟。我试图在每次定时器中断溢出(0.05 秒)时向 PC 发送一些字符,认为 RS232 模块,所以我在 ASF 上定义了 (tc)Timers,USART 驱动程序并在 main.c 文件中编写了以下代码,最后我调试了它没有任何错误,但没有成功通过串口传输任何东西。任何人都可以帮助我或给我一些建议。
#include <asf.h>
volatile int flag=0;
uint8_t received_byte;
uint8_t tx_buf[] = "\n\rHello AVR world ! : ";
uint8_t tx_length = 22;
uint8_t i;
static void my_callback(void)
{
flag =1;
}
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
board_init();
sysclk_init();
static usart_rs232_options_t USART_SERIAL_OPTIONS = {
.baudrate = 9600,
.charlength = 8,
.paritytype = USART_PMODE_DISABLED_gc,
.stopbits = false
};
usart_init_rs232(& USARTF0, &USART_SERIAL_OPTIONS);
//usart_set_baudrate_precalculated(& USARTF0,0x00017700,0x01E84800);
/* Insert application code here, after the board has been initialized. */
if (flag==1)
{
//received_byte = usart_getchar(& USARTF0);
//if (received_byte == '\r') {
for (i = 0; i < tx_length; i++)
{
usart_putchar(& USARTF0, tx_buf[i]);
}
}
else
usart_putchar(& USARTF0, received_byte);
flag=0;
}