本帖最后由 ddllxxrr 于 2014-12-25 22:17 编辑
接上贴哈,上贴向串口发了一串字符串。我今天苦想了半天,就象发一个字符终于搞定哈
首先接着昨天的程序,我加了我要发的一个变量,把它赋值为0x55,为什么要用0x55,因为它是01准确间隔,用它的可以看出速率准不谁!!!!!
我加的只有两句:其它不变
uint8_t mystring = 0x55;
usart_write_buffer_wait(&usart_instance, string, sizeof(string));
我为什么这么做呢,我是想往printf上靠,究竟能不能实现,且听下回分解。
程序清单如下:
/**
* \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";
uint8_t mystring = 0x55;
usart_write_buffer_wait(&usart_instance, string, sizeof(string));
uint16_t temp;
while (true)
{
usart_write_buffer_wait(&usart_instance, &mystring, sizeof( mystring));
if (usart_read_wait(&usart_instance, &temp) == STATUS_OK)
{ while (usart_write_wait(&usart_instance, temp) != STATUS_OK)
{ }
}
}
}
|