1、初遇[size=1em]Curiosity Nano
[size=1em] 很荣幸能够参加21ic的活动,并有幸体验AVR64DD32 Curiosity Nano 评估工具包(部件编号:EV72Y42A)。开发板如图所示:
图1 近景
图2 远景--正面
图3远景--背面
图4 焊接之后
开发板有几点很神奇:1、使用的错位孔,焊接不焊接差别不大,就是DIP针脚很难插件去;2、CPU是24 MHZ的速度,使用的是24MHZ的晶振,不知道这样设计有什么特别的好处。
图5 开发板外接资源
2、开发环境搭建
2.1 开发环境(github推荐)
- [color=var(--color-accent-fg)]MPLAB® X IDE 6.00 or newer
- [color=var(--color-accent-fg)]MPLAB® XC8 2.36 or a newer compiler
- [color=var(--color-accent-fg)]AVR-Dx Series Device Pack v2.1.152 or newer
- [color=var(--color-accent-fg)]MPLAB® Code Configurator Melody core 2.1.13 or newer
- [color=var(--color-accent-fg)]MPLAB® Code Configurator Melody Drivers
- [color=var(--color-accent-fg)]MPLAB® Data Visualizer v1.2.1160 or newer
2.2 开发环境安装
1、开发环境一路无脑NEXT就好,安装好之后,用USB-type B 线插上板子会自动识别;
2、建议安装好之后建议先观看官方快速上手指南:https://www.microchip.com/en-us/product/AVR64DD32;
3、开发板有大量例程可以参考,参见:https://github.com/microchip-pic-avr-examples?q=AVR64DD32;
图6 部分官方例程
3、LED呼吸灯
3.1 例程下载
首先,下载官方历程:microchip-pic-avr-examples/avr64dd32-getting-started-with-gpio-mplabx-mcc。在该例程里有使用GPIO控制LED0的程序,并附有详细的说明和程序。
1. Blink LED
This project shows how to blink the on-board LED on the Curiosity Nano Development Board. The LED is connected to a GPIO pin and it spends 500 ms in ON state and 500 ms in OFF state.
1.1 Setup
The following configurations must be made for this project:
CPU clock frequency is 4 MHz
Pin Configuration
PF5 Digital Output
1.2 Demo
The image below shows the waveform of the pin connected to the LED. The pin spends 500 ms in a high state and 500 ms in a low state.
<blockquote>#define F_CPU 4000000UL
3.2 加载程序加载程序的步骤如下
Step1:打开mplab软件
Step2:文件——>打开工程
Step3:打开文件夹
Step4:找到工程->加载工程
Step5:选中工程——>右键清除并编译
Step6:连接开发板——>下载工程
编译已成功 (总时间: 753ms)
* Load symbols when building or programming for production is enabled. Loading from: D:/project/AVR64DD32/avr64dd32-getting-started-with-gpio-mplabx-master1/avr64dd32-getting-started-with-gpio-mplabx-master/Blink_LED.X/dist/free/production/Blink_LED.X.production.elf...
正在加载代码D:/project/AVR64DD32/avr64dd32-getting-started-with-gpio-mplabx-master1/avr64dd32-getting-started-with-gpio-mplabx-master/Blink_LED.X/dist/free/production/Blink_LED.X.production.hex...
Program loaded with pack,AVR-Dx_DFP,2.2.159,Microchip
加载完成
3.3 修改程序
官方给的Blink_LED.X程序实现了LED等1秒内实现亮灭。通过简单修改就可以实现不同亮灭的对比。程序如下:
#define F_CPU 4000000UL
#include <avr/io.h>
#include <util/delay.h>
/* Default fuses configuration:
- BOD disabled
- Oscillator in High-Frequency Mode
- UPDI pin active (WARNING: DO NOT CHANGE!)
- RESET pin used as GPIO
- CRC disabled
- MVIO enabled for dual supply
- Watchdog Timer disabled
*/
FUSES =
{
.BODCFG = ACTIVE_DISABLE_gc | LVL_BODLEVEL0_gc | SAMPFREQ_128Hz_gc | SLEEP_DISABLE_gc,
.BOOTSIZE = 0x0,
.CODESIZE = 0x0,
.OSCCFG = CLKSEL_OSCHF_gc,
.SYSCFG0 = CRCSEL_CRC16_gc | CRCSRC_NOCRC_gc | RSTPINCFG_GPIO_gc | UPDIPINCFG_UPDI_gc,
.SYSCFG1 = MVSYSCFG_DUAL_gc | SUT_0MS_gc,
.WDTCFG = PERIOD_OFF_gc | WINDOW_OFF_gc,
};
#define LED_init() do { PORTF.OUTSET = PIN5_bm; PORTF.DIRSET = PIN5_bm; } while (0) //初始化LED
#define LED_turnOn() do { PORTF.OUTCLR = PIN5_bm; } while (0) //开启LED
#define LED_turnOff() do { PORTF.OUTSET = PIN5_bm; } while (0)//开启LED
int main(void)
{
LED_init();
while (1)
{
_delay_us(50);; //延时20u秒
LED_turnOn(); //开启LED
_delay_us(1);;//延时4u秒
LED_turnOff();//关闭LED
}
}
此时,亮度较低。效果如下:
[size=1em]通过修改程序的延时函数,可以提高亮、暗比。修改程序如下:
#define F_CPU 4000000UL
#include <avr/io.h>
#include <util/delay.h>
/* Default fuses configuration:
- BOD disabled
- Oscillator in High-Frequency Mode
- UPDI pin active (WARNING: DO NOT CHANGE!)
- RESET pin used as GPIO
- CRC disabled
- MVIO enabled for dual supply
- Watchdog Timer disabled
*/
FUSES =
{
.BODCFG = ACTIVE_DISABLE_gc | LVL_BODLEVEL0_gc | SAMPFREQ_128Hz_gc | SLEEP_DISABLE_gc,
.BOOTSIZE = 0x0,
.CODESIZE = 0x0,
.OSCCFG = CLKSEL_OSCHF_gc,
.SYSCFG0 = CRCSEL_CRC16_gc | CRCSRC_NOCRC_gc | RSTPINCFG_GPIO_gc | UPDIPINCFG_UPDI_gc,
.SYSCFG1 = MVSYSCFG_DUAL_gc | SUT_0MS_gc,
.WDTCFG = PERIOD_OFF_gc | WINDOW_OFF_gc,
};
#define LED_init() do { PORTF.OUTSET = PIN5_bm; PORTF.DIRSET = PIN5_bm; } while (0) //初始化LED
#define LED_turnOn() do { PORTF.OUTCLR = PIN5_bm; } while (0) //开启LED
#define LED_turnOff() do { PORTF.OUTSET = PIN5_bm; } while (0)//开启LED
int main(void)
{
LED_init();
while (1)
{
_delay_us(1);; //延时20u秒
LED_turnOn(); //开启LED
_delay_us(50);;//延时4u秒
LED_turnOff();//关闭LED
}
}
效果如下:可以通过绿灯的亮度分辨出二者的差异。
附心得:
1、平台太大,安装完成之后的平台使用了十几个G的空间。
2、官方函数对新手不是很友好。在编程的过程中,想通过官方函数_delay_us()快速实现呼吸灯效果,最后发现该函数只接受常数(__builtin_avr_delay_cycles expects a compile time integer constant __builtin_avr_delay_cycles(__ticks_dc);)。
|