[Atmel] 用ASF跑SAMD21程序(6)USART-BASIC

[复制链接]
2999|11
 楼主| ddllxxrr 发表于 2014-12-22 22:46 | 显示全部楼层 |阅读模式
关于建立ASF的工程:这里不重述,具体请看《用ASF跑SAMD21程序(3)(2)(1)》:


用ASF跑SAMD21程序(1)8位定时器点LED
https://bbs.21ic.com/forum.php?mod=viewthread&tid=850511&extra=page%3D1%26filter%3Dtypeid%

26typeid%3D380%26typeid%3D380


用ASF跑SAMD21程序(2)TCC-BASIC
https://bbs.21ic.com/forum.php?mod=viewthread&tid=850813&extra=page%3D1%26filter%3Dtypeid%

26typeid%3D380%26typeid%3D380


用ASF跑SAMD21程序(3)TCC - Double Buffering & Circular
https://bbs.21ic.com/forum.php?mod=viewthread&tid=851403&extra=page%3D1%26filter%3Dtypeid%

26typeid%3D380%26typeid%3D380



这里选择SERCOM USART


然后点开ASF EXPLOER 选择USARTBASE

然后再根据提示来组成程序:


程序清单如下:


  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 = EDBG_CDC_SERCOM_MUX_SETTING;
  38.          config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
  39.          config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
  40.          config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
  41.          config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
  42.          while (usart_init(&usart_instance, EDBG_CDC_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.         usart_write_buffer_wait(&usart_instance, string, sizeof(string));
  52.         uint16_t temp;
  53.         while (true)
  54.         {
  55.                 if (usart_read_wait(&usart_instance, &temp) == STATUS_OK)
  56.                 {            while (usart_write_wait(&usart_instance, temp) != STATUS_OK)
  57.                                  {            }
  58.                 }
  59.         }
  60. }

本帖子中包含更多资源

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

×
86269838 发表于 2017-3-18 12:05 | 显示全部楼层
问个白痴问题,这个程序有没有办法看到结果呢?
 楼主| ddllxxrr 发表于 2017-3-18 18:39 | 显示全部楼层
86269838 发表于 2017-3-18 12:05
问个白痴问题,这个程序有没有办法看到结果呢?

因为发的时候也许有事就没有拍结果,不过我发出的一定是正常运行的,如假包换
86269838 发表于 2017-3-19 07:33 | 显示全部楼层
我肯定相信版大能运行。我的意思是,这个光是把程序烧进去,我怎么验证它对不对。总要有个跟人能够交互的界面吧,像前面的例子至少有个灯,而且我可以拿示波器测灯的引脚。这个就不太清楚怎么弄了。
本人初学,最近问了好几个问题,见谅啊。
86269838 发表于 2017-3-19 13:09 | 显示全部楼层
这个问题解决了,用EDBG的虚拟COM可以用atmel studio的data visualizer读回来
 楼主| ddllxxrr 发表于 2017-3-19 20:31 | 显示全部楼层
86269838 发表于 2017-3-19 13:09
这个问题解决了,用EDBG的虚拟COM可以用atmel studio的data visualizer读回来

用别的串口软件也可以
lklklkj 发表于 2017-7-18 14:24 | 显示全部楼层
EDBG_CDC_SERCOM_MUX_SETTING;
EDBG_CDC_SERCOM_PINMUX_PAD0;
EDBG_CDC_SERCOM_PINMUX_PAD1;
EDBG_CDC_SERCOM_PINMUX_PAD2;
EDBG_CDC_SERCOM_PINMUX_PAD3;为什么这些都是未定义阿??????
lklklkj 发表于 2017-7-18 14:25 | 显示全部楼层
EDBG_CDC_SERCOM_MUX_SETTING;
EDBG_CDC_SERCOM_PINMUX_PAD0;
EDBG_CDC_SERCOM_PINMUX_PAD1;
EDBG_CDC_SERCOM_PINMUX_PAD2;
EDBG_CDC_SERCOM_PINMUX_PAD3;为什么这些都是未定义阿??????
为何这般累 发表于 2017-11-8 11:10 | 显示全部楼层
ddllxxrr 发表于 2017-3-19 20:31
用别的串口软件也可以

为什么我读出来是乱码呢?显示不出 hello world
 楼主| ddllxxrr 发表于 2017-11-8 17:35 | 显示全部楼层
为何这般累 发表于 2017-11-8 11:10
为什么我读出来是乱码呢?显示不出 hello world

波特率不对
为何这般累 发表于 2017-11-9 09:47 | 显示全部楼层

设置了9600啊
为何这般累 发表于 2017-11-13 14:28 | 显示全部楼层
删除其他模块的代码,只留下串口代码就可以显示hello world了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

7001

帖子

68

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