Atmel工作室采用Xmega Timer / USART

时间:2016-05-08 19:38:52

标签: c microcontroller avr atmelstudio

我在Atmel工作室环境中开发的嵌入式系统的新功能, 我使用的是具有32MHz系统clk的Atxmega128a1。 我尝试向PC发送一些字符,认为RS232模块在每个定时器中断溢出(0.05s), 所以我在ASF上定义了(tc)定时器,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;
   } 

1 个答案:

答案 0 :(得分:0)

我相信你错过了相关系统时钟模块的初始化:

Country_Info