[Atmel] 用ASF跑SAMD21程序(28) 管脚输出时钟

[复制链接]
2020|8
 楼主| ddllxxrr 发表于 2015-2-4 21:15 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2015-2-5 14:25 编辑

SAMD21的时钟可以通过管脚输出。

首先建立ASF工程,然后添加SYSTEM-I/O Pin Multiplexer模块。




然后添加程序代码。程序清单如下:


  1. <p> </p>
  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. /**
  30. * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
  31. */

  32. static void setup_clock_out_pin(void);
  33. #include <asf.h>
  34. #define CONF_CLOCK_PIN_OUT            PIN_PA28H_GCLK_IO0
  35. #define CONF_CLOCK_PIN_MUX            MUX_PA28H_GCLK_IO0
  36. static void setup_clock_out_pin(void)
  37. {
  38.         struct system_pinmux_config pin_mux;
  39.         system_pinmux_get_config_defaults(&pin_mux);

  40.         /* MUX out the system clock to a I/O pin of the device */
  41.         pin_mux.mux_position = CONF_CLOCK_PIN_MUX;
  42.         system_pinmux_pin_set_config(CONF_CLOCK_PIN_OUT, &pin_mux);
  43. }


  44. int main (void)
  45. {
  46.         system_init();
  47.         setup_clock_out_pin();
  48.         

  49.         // Insert application code here, after the board has been initialized.

  50.         // This skeleton code simply sets the LED to the state of the button.
  51.         while (1) {
  52.                 // Is button pressed?
  53.                 if (port_pin_get_input_level(BUTTON_0_PIN) == BUTTON_0_ACTIVE) {
  54.                         // Yes, so turn LED on.
  55.                         port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
  56.                 } else {
  57.                         // No, so turn LED off.
  58.                         port_pin_set_output_level(LED_0_PIN, !LED_0_ACTIVE);
  59.                 }
  60.         }
  61. }

至于运行结果,明天我用示波看一下,看看怎么样???

本帖子中包含更多资源

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

×
86269838 发表于 2017-3-11 19:23 | 显示全部楼层
你好,请问运行结果有输出吗?我按照你这个弄了但是没有波形,我用的XPLAINED PRO D21的板子
 楼主| ddllxxrr 发表于 2017-3-11 20:41 | 显示全部楼层
86269838 发表于 2017-3-11 19:23
你好,请问运行结果有输出吗?我按照你这个弄了但是没有波形,我用的XPLAINED PRO D21的板子 ...

额,我写出来的,都是验证过的
86269838 发表于 2017-3-12 09:37 | 显示全部楼层
跟ASF版本会有影响吗?我还试过你用TC toggle led的程序,我生成的和你的CODE有一点不同。稍微改改能用。这个pinmux的问题跟这个可能有关系吗?
 楼主| ddllxxrr 发表于 2017-3-12 10:34 | 显示全部楼层
86269838 发表于 2017-3-12 09:37
跟ASF版本会有影响吗?我还试过你用TC toggle led的程序,我生成的和你的CODE有一点不同。稍微改改能用。这 ...

应该不会
86269838 发表于 2017-3-12 14:06 | 显示全部楼层
好的,我再查查,另外题外问个问题,一般做实际的项目用ASF的库吗?还是自个编底层的。?
 楼主| ddllxxrr 发表于 2017-3-13 09:22 | 显示全部楼层
86269838 发表于 2017-3-12 14:06
好的,我再查查,另外题外问个问题,一般做实际的项目用ASF的库吗?还是自个编底层的。? ...

老的如MEGA6就不用了。新的尽量ASF吧,因为例程都是ASF的
86269838 发表于 2017-3-15 15:52 | 显示全部楼层
弄出来了,conf_clock.h里面相应clock generator的OUTPUT_ENABLE没有设成true。
 楼主| ddllxxrr 发表于 2017-3-15 15:57 | 显示全部楼层
86269838 发表于 2017-3-15 15:52
弄出来了,conf_clock.h里面相应clock generator的OUTPUT_ENABLE没有设成true。

祝贺你啊,祝贺你
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

2404

主题

7001

帖子

68

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