今天跑一下ADC。方法还是老一套,首先打开上次的工程,我主要想用里边的Printf。
然后,加入ADC模块,加完后点ASF EXPLORER 点开快速指导。
按里边的说明把程序考到自己的工程序里:
那么快速指导里说的是哪个管脚呢?大家可以查数据手册,我查到是PA02。那么为了方便我直接用一根导线短接地和PA02。
然后编译,通过后我本想用串口看一下,发现打断点也可以观察。
以下是我把导线接到GND时的情景:
以下是我的导线悬空时的情景
可见ACD转换成功。我就不用串口看了。
以下是程序清单,时钟配置没有什么特别的
/**
* \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>
#include <stdio_serial.h>
bool volatile callback_status = false;
void configure_usart(void);
void configure_adc(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)
{ }
stdio_serial_init(&usart_instance, EXT3_UART_MODULE, &config_usart);
usart_enable(&usart_instance);
}
struct adc_module adc_instance;
void configure_adc(void)
{
struct adc_config config_adc;
adc_get_config_defaults(&config_adc);
adc_init(&adc_instance, ADC, &config_adc);
adc_enable(&adc_instance);
}
int main (void)
{
system_init();
configure_usart();
configure_adc();
adc_start_conversion(&adc_instance);
uint16_t result;
do { /* Wait for conversion to be done and read out result */ }
while (adc_read(&adc_instance, &result) == STATUS_BUSY);
printf("the ADC result is %d",result);
while (true)
{
;
}
}
|