[Atmel] 用ASF跑SAMD21程序(7)USART重映射

[复制链接]
3275|3
 楼主| ddllxxrr 发表于 2014-12-24 19:47 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2014-12-24 19:56 编辑

上一篇是USART利用板载的DEBG来输出的,这里我想用我从淘宝搞的中九下载线来完成串口输出的功能。

Atmel ASF,是靠MUX就是复用器来重新选则管脚功能的。

打开上个例子的程序可以得到:


  1. config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;

  2. 42.         config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;

  3. 43.         config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;

  4. 44.         config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;

  5. 45.         config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;

  6. 46.         while (usart_init(&usart_instance, EDBG_CDC_MODULE, &config_usart) != STATUS_OK)

  7. 47.          {    }

  8. 48.          usart_enable(&usart_instance);
config_usart.mux_setting = EXT3_UART_SERCOM_MUX_SETTING;
这一句就是选择USART的复用功能到哪个UART口。

而后边的

42.         config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;

43.         config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;

44.         config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;

45.         config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;

这些都在samd21_xplained_pro.h中定义好了。

所以我只要换,这几个命令行就可以了。我就可以把我的串口线用上了,呵呵!!!!

程序清单:


  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.         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. }



本帖子中包含更多资源

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

×
为何这般累 发表于 2017-11-15 16:28 | 显示全部楼层
如果选择USART的复用功能PB08 PB09上呢,PB08发,PB09收
 楼主| ddllxxrr 发表于 2017-11-15 20:41 | 显示全部楼层
为何这般累 发表于 2017-11-15 16:28
如果选择USART的复用功能PB08 PB09上呢,PB08发,PB09收

重新配置一下
为何这般累 发表于 2017-11-16 10:16 | 显示全部楼层
本帖最后由 为何这般累 于 2017-11-16 10:23 编辑

解决了,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

7001

帖子

68

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