/**
* \file
*
* \brief Empty user application template
*
*/
/**
* \mainpage User Application template doxygen documentation
*
* \par Empty user application template
*
* Bare minimum empty user application template
*
* \par Content
*
* -# Include the ASF header files (through asf.h)
* -# Minimal main function that starts with a call to system_init()
* -# "Insert application code here" comment
*
*/
/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
/*
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/
#include <asf.h>
#include <stdio.h>
//#include <NskBMD.h>
#define LED 91 //定义LED所使用的IO口为 PC27
#define KEY 65 //定义KEY所使用的IO口为 PC01
void port_init(void);
void configure_usart(void);
//! [setup_config]
struct usart_module usart_instance;
//! [setup_config]
/***********************************************/
//串口初始化
/**********************************************/
void configure_usart(void)
{
//! [setup_config]
struct usart_config config_usart;
//! [setup_config]
//! [setup_config_defaults]
usart_get_config_defaults(&config_usart);
//! [setup_config_defaults]
//! [setup_change_config]
//USART PORT PA12 PA13.
config_usart.baudrate = 9600;
config_usart.mux_setting = USART_RX_3_TX_2_XCK_3;
config_usart.pinmux_pad0 = PINMUX_UNUSED;//PINMUX_PA12D_SERCOM3_PAD0;
config_usart.pinmux_pad1 = PINMUX_UNUSED;//PINMUX_PA13D_SERCOM3_PAD1;
config_usart.pinmux_pad2 = PINMUX_PC24D_SERCOM4_PAD2;//PINMUX_UNUSED;
config_usart.pinmux_pad3 = PINMUX_PC25D_SERCOM4_PAD3;//PINMUX_UNUSED;
//! [setup_change_config]
//! [setup_set_config]
while (usart_init(&usart_instance,
SERCOM4, &config_usart) != STATUS_OK) {
}
//! [setup_set_config]
//! [setup_enable]
usart_enable(&usart_instance);
//! [setup_enable]
}
/******************************************************/
// # IO口初始化
/******************************************************/
void port_init(void)
{
struct port_config config_port_pin;
port_get_config_defaults(&config_port_pin);
config_port_pin.direction = PORT_PIN_DIR_OUTPUT; //配置IO口为输出模式;
port_pin_set_config(LED,&config_port_pin); //初始化LED对应的IO口;
config_port_pin.direction = PORT_PIN_DIR_INPUT; //配置IO口为输入模式;
config_port_pin.input_pull = PORT_PIN_PULL_UP; //配置IO口为PULL 上拉;
port_pin_set_config(KEY,&config_port_pin);
}
int main(void)
{
system_init();
port_init(); //端口初始化;
//! [setup_init]
configure_usart();
//! [setup_init]
//! [main_send_string]
uint8_t string[] = "Hello World!\r\n";
usart_write_buffer_wait(&usart_instance, string, sizeof(string));
//printf("data is %ld",(usart_instance->hw->USART.DATA->reg)); //添加这块代码就会报警出错。
//! [main_send_string]
uint16_t temp;
//! [main_loop]
while (1) {
if (usart_read_wait(&usart_instance, &temp) == STATUS_OK) {
//! [main_read]
//! [main_write]
while (usart_write_wait(&usart_instance, temp) != STATUS_OK) {
}
//! [main_write]
}
}
//! [main]
}
版主认为我缺哪块?并且查询方式的话,我串口终端接受到的数据有丢包. |