本帖最后由 ddllxxrr 于 2014-12-24 19:56 编辑
上一篇是USART利用板载的DEBG来输出的,这里我想用我从淘宝搞的中九下载线来完成串口输出的功能。
Atmel ASF,是靠MUX就是复用器来重新选则管脚功能的。
打开上个例子的程序可以得到:
config_usart.mux_setting = EDBG_CDC_SERCOM_MUX_SETTING;
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;
46. while (usart_init(&usart_instance, EDBG_CDC_MODULE, &config_usart) != STATUS_OK)
47. { }
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中定义好了。
所以我只要换,这几个命令行就可以了。我就可以把我的串口线用上了,呵呵!!!!
程序清单:
/**
* \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 = EXT3_UART_SERCOM_MUX_SETTING;
config_usart.pinmux_pad0 = EXT3_UART_SERCOM_PINMUX_PAD0;
config_usart.pinmux_pad1 = EXT3_UART_SERCOM_PINMUX_PAD1;
config_usart.pinmux_pad2 = EXT3_UART_SERCOM_PINMUX_PAD2;
config_usart.pinmux_pad3 = EXT3_UART_SERCOM_PINMUX_PAD3;
while (usart_init(&usart_instance, EXT3_UART_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)
{ }
}
}
}
|