[Atmel] 用ASF跑SAMD21程序(8)USART发0x55

[复制链接]
1743|2
 楼主| ddllxxrr 发表于 2014-12-25 22:06 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2014-12-25 22:17 编辑

接上贴哈,上贴向串口发了一串字符串。我今天苦想了半天,就象发一个字符终于搞定哈

首先接着昨天的程序,我加了我要发的一个变量,把它赋值为0x55,为什么要用0x55,因为它是01准确间隔,用它的可以看出速率准不谁!!!!!

我加的只有两句:其它不变

uint8_t mystring = 0x55;
usart_write_buffer_wait(&usart_instance, string, sizeof(string));

我为什么这么做呢,我是想往printf上靠,究竟能不能实现,且听下回分解。

程序清单如下:

  1. /**
  2. * \file
  3. *
  4. * \brief Empty user application template
  5. *
  6. */

  7. /**
  8. * \mainpage User Application template doxygen documentation
  9. *
  10. * \par Empty user application template
  11. *
  12. * This is a bare minimum user application template.
  13. *
  14. * For documentation of the board, go \ref group_common_boards "here" for a link
  15. * to the board-specific documentation.
  16. *
  17. * \par Content
  18. *
  19. * -# Include the ASF header files (through asf.h)
  20. * -# Minimal main function that starts with a call to system_init()
  21. * -# Basic usage of on-board LED and button
  22. * -# "Insert application code here" comment
  23. *
  24. */

  25. /*
  26. * Include header files for all drivers that have been imported from
  27. * Atmel Software Framework (ASF).
  28. */
  29. #include <asf.h>

  30. void configure_usart(void);
  31. struct usart_module usart_instance;

  32. void configure_usart(void)
  33. {   
  34.          struct usart_config config_usart;
  35.          usart_get_config_defaults(&config_usart);
  36.          config_usart.baudrate    = 9600;
  37.          config_usart.mux_setting = EXT3_UART_SERCOM_MUX_SETTING;
  38.          config_usart.pinmux_pad0 = EXT3_UART_SERCOM_PINMUX_PAD0;
  39.          config_usart.pinmux_pad1 = EXT3_UART_SERCOM_PINMUX_PAD1;
  40.          config_usart.pinmux_pad2 = EXT3_UART_SERCOM_PINMUX_PAD2;
  41.          config_usart.pinmux_pad3 = EXT3_UART_SERCOM_PINMUX_PAD3;
  42.          while (usart_init(&usart_instance, EXT3_UART_MODULE, &config_usart) != STATUS_OK)
  43.           {    }
  44.           usart_enable(&usart_instance);
  45. }



  46. int main (void)
  47. {
  48.         system_init();
  49.         configure_usart();
  50.         uint8_t string[] = "Hello World!\r\n";
  51.         uint8_t mystring = 0x55;
  52.         usart_write_buffer_wait(&usart_instance, string, sizeof(string));
  53.         uint16_t temp;
  54.         while (true)
  55.         {
  56.                                 usart_write_buffer_wait(&usart_instance, &mystring, sizeof(        mystring));
  57.                                 if (usart_read_wait(&usart_instance, &temp) == STATUS_OK)
  58.                 {            while (usart_write_wait(&usart_instance, temp) != STATUS_OK)
  59.                                  {            }
  60.                 }
  61.         }
  62. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
yklstudent 发表于 2014-12-26 12:58 | 显示全部楼层
mark,支持下
huangxz 发表于 2014-12-26 13:48 | 显示全部楼层
波特率计算的应该差异不是很大的.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7001

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部