|
使用Atmel Studio 7编程Arduino Uno开发板非常简单。Arduino Uno开发板是使用AVR微控制器的嵌入式应用开发的著名平台之一。 大多数人通常会使用Arduino自己的软件工具。然而,许多骨灰级的程序员仍然喜欢使用原生C语言来编写AVR的代码。这种方法提供了极大的灵活性、可配置性和可编辑性,这些优势Arduino软件框架都不具有。
Arduino Uno开发板基于ATmega328P AVR微控制器。 它有32KB的闪存、2KB的SRAM、1KB的EEPROM。 它具有丰富的片上外设(6个PWM通道、10位ADC、SPI、I2C、UART接口以及触摸库支持)。
任何集成开发环境的一个最重要的方面是能够编程特定的微控制器。 为了使用Atmel Studio编程Arduino Uno开发板,我们需要一个称为avrdude的简单工具。 您可以单独下载此工具,而不是下载Arduino软件。
如果仔细看,你就会看到Arduino Uno开发板有一个更小的微控制器(ATmega16U2)。 该控制器在一侧通过USB接口模拟虚拟串行端口,通过该虚拟串行端口接收编程命令和十六进制代码。 另一侧,它通过UART与ATmega328P上的Arduino引导加载程序(出厂时已编程)通信,并烧写接收到的十六进制代码。
所需的软件和工具: 1. Arduino Uno开发板 2. Atmel Studio(http://www.atmel.com/microsite/atmel-studio/) 3. Avrdude(下载并解压缩归档到合适的目录 - https://download.savannah.gnu.or ... ude-6.3-mingw32.zip ) 或者是Arduino 1.8.0(https://www.arduino.cc/en/Main/Software) - 该Arduino安装包含Avrdude工具。
配置Atmel Studio开发环境 1. 打开Atmel Studio,然后单击Tools > External Tools。 我们将添加从Atmel Studio启动avrdude所需的必要命令,并告诉Atmel Studio将所需的参数传递到avrdude。
2. 单击Add,添加一个新的外部工具,并提供以下信息: Title: UNO avrdude Command: I:\Softwares\Electronics\AVR\avrdude-6.3-mingw32\avrdude.exe 注意:如果使用不同的路径,请提供相同的路径。 Arguments: -v -P COM7 -c arduino -e -p m328p -U flash:w:$(TargetName).hex 说明: -v:启用详细输出。
-P:连接Arduino Uno的串行端口号(COM端口) -c:编程器硬件类型。 -e:在编程之前擦除目标MCU的闪存和EEPROM存储器。 这是强制性的。 -p:要编程的器件的短名称 -U:memtype:op:filename [:format]:将指定的十六进制文件的内容写入闪存 说明:以COM7为例,您需要提供正确的端口。 提示:如果您将同一Arduino Due开发板连接到计算机的同一USB端口,则COM端口号将始终相同! Initial Directory: $(TargetDir) 勾选复选框“Use Output Window” 你可以参考下面的截图:
3. 单击“OK”,然后单击“YES”以保存所做的更改。 现在你会在Tools菜单下发现新的外部编程器工具,叫做“UNO avrdude”。
下载代码 1. 构建您的解决方案(按F7) 2. 确保Arduino Uno开发板已连接到计算机的USB端口(请参阅下图),并且确保为工具Arguments指定的COM端口值正确。 3. 单击Tools > UNO avrdude 它应该会开始编程。 输出窗口将显示类似如下所示的日志:
- avrdude.exe: Version 6.3, compiled on Feb 17 2016 at 09:25:53
- Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
- Copyright (c) 2007-2014 Joerg Wunsch
- System wide configuration file is "I:\Softwares\Electronics\AVR\avrdude-6.3-mingw32\avrdude.conf"
- Using Port : COM7
- Using Programmer : arduino
- AVR Part : ATmega328P
- Chip Erase delay : 9000 us
- PAGEL : PD7
- BS2 : PC2
- RESET disposition : dedicated
- RETRY pulse : SCK
- serial program mode : yes
- parallel program mode : yes
- Timeout : 200
- StabDelay : 100
- CmdexeDelay : 25
- SyncLoops : 32
- ByteDelay : 0
- PollIndex : 3
- PollValue : 0x53
- Memory Detail :
- Block Poll Page Polled
- Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
- ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
- eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
- flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
- lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
- hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
- efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
- lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
- calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
- signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
- Programmer Type : Arduino
- Description : Arduino
- Hardware Version: 2
- Firmware Version: 1.16
- Vtarget : 0.0 V
- Varef : 0.0 V
- Oscillator : Off
- SCK period : 0.1 us
- avrdude.exe: AVR device initialized and ready to accept instructions
- Reading | ################################################## | 100% 0.01s
- avrdude.exe: Device signature = 0x1e950f (probably m328p)
- avrdude.exe: safemode: hfuse reads as 0
- avrdude.exe: safemode: efuse reads as 0
- avrdude.exe: erasing chip
- avrdude.exe: reading input file "My Project.hex"
- avrdude.exe: input file My Project.hex auto detected as Intel Hex
- avrdude.exe: writing flash (1906 bytes):
- Writing | ################################################## | 100% 0.41s
- avrdude.exe: 1906 bytes of flash written
- avrdude.exe: verifying flash memory against My Project.hex:
- avrdude.exe: load data flash data from input file My Project.hex:
- avrdude.exe: input file My Project.hex auto detected as Intel Hex
- avrdude.exe: input file My Project.hex contains 1906 bytes
- avrdude.exe: reading on-chip flash data:
- Reading | ################################################## | 100% 0.24s
- avrdude.exe: verifying ...
- avrdude.exe: 1906 bytes of flash verified
- avrdude.exe: safemode: hfuse reads as 0
- avrdude.exe: safemode: efuse reads as 0
- avrdude.exe: safemode: Fuses OK (E:00, H:00, L:00)
- avrdude.exe done. Thank you.
复制代码
好了,介绍就到这了。现在你可以充分使用Arduino Uno开发板和ATmega328微控制器的全部功能了。
参考链接: ■ 使用Atmel Studio 7编程Arduino Due开发板:http://www.yiboard.com/thread-640-1-1.html ■ Program / Flash Arduino Uno with Atmel Studio:http://www.elecrom.com/program-flash-arduino-uno-atmel-studio/ |