关于建立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
然后再根据提示来组成程序:
程序清单如下:
- /**
- * \file
- *
- * \brief Empty user application template
- *
- */
- /**
- * \mainpage User Application template doxygen documentation
- *
- * \par Empty user application template
- *
- * This is a bare minimum user application template.
- *
- * For documentation of the board, go \ref group_common_boards "here" for a link
- * to the board-specific documentation.
- *
- * \par Content
- *
- * -# Include the ASF header files (through asf.h)
- * -# Minimal main function that starts with a call to system_init()
- * -# Basic usage of on-board LED and button
- * -# "Insert application code here" comment
- *
- */
- /*
- * Include header files for all drivers that have been imported from
- * Atmel Software Framework (ASF).
- */
- #include <asf.h>
- void configure_usart(void);
- struct usart_module usart_instance;
- void configure_usart(void)
- {
- struct usart_config config_usart;
- usart_get_config_defaults(&config_usart);
- config_usart.baudrate = 9600;
- config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
- config_usart.pinmux_pad0 = EDBG_CDC_SERCOM_PINMUX_PAD0;
- config_usart.pinmux_pad1 = EDBG_CDC_SERCOM_PINMUX_PAD1;
- config_usart.pinmux_pad2 = EDBG_CDC_SERCOM_PINMUX_PAD2;
- config_usart.pinmux_pad3 = EDBG_CDC_SERCOM_PINMUX_PAD3;
- while (usart_init(&usart_instance, EDBG_CDC_MODULE, &config_usart) != STATUS_OK)
- { }
- usart_enable(&usart_instance);
- }
- int main (void)
- {
- system_init();
- configure_usart();
- uint8_t string[] = "Hello World!\r\n";
- usart_write_buffer_wait(&usart_instance, string, sizeof(string));
- uint16_t temp;
- while (true)
- {
- if (usart_read_wait(&usart_instance, &temp) == STATUS_OK)
- { while (usart_write_wait(&usart_instance, temp) != STATUS_OK)
- { }
- }
- }
- }
|