风筝
发表于: 2017-1-18 16:33:45 | 显示全部楼层

使用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引导加载程序(出厂时已编程)通信,并烧写接收到的十六进制代码。

program-arduino-uno-with-atmel-studio-03-mega16u2.jpg


所需的软件和工具:

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

你可以参考下面的截图:

program-arduino-uno-with-atmel-studio-02-external-tool.png


3.  单击“OK”,然后单击“YES”以保存所做的更改。

现在你会在Tools菜单下发现新的外部编程器工具,叫做“UNO avrdude”。

program-arduino-uno-with-atmel-studio-01-added-tool.png


下载代码

1.  构建您的解决方案(按F7)

2.  确保Arduino Uno开发板已连接到计算机的USB端口(请参阅下图),并且确保为工具Arguments指定的COM端口值正确。

3.  单击Tools > UNO avrdude

它应该会开始编程。 输出窗口将显示类似如下所示的日志:

  1. avrdude.exe: Version 6.3, compiled on Feb 17 2016 at 09:25:53
  2.              Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
  3.              Copyright (c) 2007-2014 Joerg Wunsch

  4.              System wide configuration file is "I:\Softwares\Electronics\AVR\avrdude-6.3-mingw32\avrdude.conf"

  5.              Using Port                    : COM7
  6.              Using Programmer              : arduino
  7.              AVR Part                      : ATmega328P
  8.              Chip Erase delay              : 9000 us
  9.              PAGEL                         : PD7
  10.              BS2                           : PC2
  11.              RESET disposition             : dedicated
  12.              RETRY pulse                   : SCK
  13.              serial program mode           : yes
  14.              parallel program mode         : yes
  15.              Timeout                       : 200
  16.              StabDelay                     : 100
  17.              CmdexeDelay                   : 25
  18.              SyncLoops                     : 32
  19.              ByteDelay                     : 0
  20.              PollIndex                     : 3
  21.              PollValue                     : 0x53
  22.              Memory Detail                 :

  23.                                       Block Poll               Page                       Polled
  24.                Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
  25.                ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
  26.                eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
  27.                flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
  28.                lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
  29.                hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
  30.                efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
  31.                lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
  32.                calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
  33.                signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

  34.              Programmer Type : Arduino
  35.              Description     : Arduino
  36.              Hardware Version: 2
  37.              Firmware Version: 1.16
  38.              Vtarget         : 0.0 V
  39.              Varef           : 0.0 V
  40.              Oscillator      : Off
  41.              SCK period      : 0.1 us

  42. avrdude.exe: AVR device initialized and ready to accept instructions

  43. Reading | ################################################## | 100% 0.01s

  44. avrdude.exe: Device signature = 0x1e950f (probably m328p)
  45. avrdude.exe: safemode: hfuse reads as 0
  46. avrdude.exe: safemode: efuse reads as 0
  47. avrdude.exe: erasing chip
  48. avrdude.exe: reading input file "My Project.hex"
  49. avrdude.exe: input file My Project.hex auto detected as Intel Hex
  50. avrdude.exe: writing flash (1906 bytes):

  51. Writing | ################################################## | 100% 0.41s

  52. avrdude.exe: 1906 bytes of flash written
  53. avrdude.exe: verifying flash memory against My Project.hex:
  54. avrdude.exe: load data flash data from input file My Project.hex:
  55. avrdude.exe: input file My Project.hex auto detected as Intel Hex
  56. avrdude.exe: input file My Project.hex contains 1906 bytes
  57. avrdude.exe: reading on-chip flash data:

  58. Reading | ################################################## | 100% 0.24s

  59. avrdude.exe: verifying ...
  60. avrdude.exe: 1906 bytes of flash verified

  61. avrdude.exe: safemode: hfuse reads as 0
  62. avrdude.exe: safemode: efuse reads as 0
  63. avrdude.exe: safemode: Fuses OK (E:00, H:00, L:00)

  64. 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/

跳转到指定楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题 700 | 回复: 1480



手机版|

GMT+8, 2024-4-26 11:38 , Processed in 0.034557 second(s), 6 queries , Gzip On, MemCache On. Powered by Discuz! X3.5

YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )

快速回复 返回顶部 返回列表