用arduino mega2560通过isp给 arduino uno烧录程序

一直想通过最基本的方式来烧录arduino程序,没有bootloader,不使用arduino IDE,基于avr-libc库来写程序,再用avrdude来烧录。

  • 由于手上有两块arduino板,一块uno,一块mega2560。就想着用mega来做isp工具,来给uno烧录程序,就有了以下过程

  • mega做成isp烧录工具

    1. 在arduino IDE里写入isp程序:

    2. 首先选择工具档: Tools > Board > mega2560

    3. 再选择 File > Example > ArduinoISP

    4. 编译上传


  • 连接meag和uno

    1. 参考这篇文章

      Arduino as ISP and Arduino Bootloaders | Arduino Documentation

    2. 具体是这张图:

    3. 描述如下:

      The Arduino MEGA above is programming an Arduino UNO connecting D51-D11, D50-D12, D52-D13, GND-GND, 5V-5V and D10 to RESET. This type of board needs a 10µF electrolytic capacitor connected to RESET and GND with the positive (long leg) connected to RESET. The capacitor has to be placed after the programmer board has been loaded with the ISP sketch.

      The 10µF electrolytic capacitor connected to RESET and GND of the programming board is needed only for the boards that have an interface between the microcontroller and the computer's USB, like Mega, UNO, Mini, Nano. Boards like Leonardo, Esplora and Micro, with the USB directly managed by the microcontroller, don't need the capacitor.

      注意:reset引脚上要接一 个电容


  • 通过arduino IDE确认烧录命令

    1. 打开一个想烧录的例子程序,比如 Blink
    2. 选择目标板(uno):Tools > Board > Arduino Uno
    3. 选择工具板 (mega2560):Tools > Port > 选择mega2560 (来作为"Arduino as ISP")
    4. 选择 Tools > Programmer > Arduino as ISP
    5. 注意,选择 Sketch > Upload Using Programmer ;而不是点工具栏的 编译。
    6. 第5步之后,就会通过isp方式,擦除uno的flash,并烧录blink的程序。可以在arduino IDE后台的log里找到刚刚执行的烧录的命令:
      • 我的系统是arch linux,我的用户目录为 /home/suah,截取的log的第一行就是烧录的命令,后续我们自己修改目标文件,就可以随时烧录自己的程序了

        /home/suah/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/suah/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -P/dev/ttyACM0 -b19200 -Uflash:w:/tmp/arduino_build_456577/Blink.ino.hex:iavrdude: Version 6.3-20190619Copyright (c) 2000-2005 Brian Dean, <http://www.bdmicro.com/>Copyright (c) 2007-2014 Joerg WunschSystem wide configuration file is "/home/suah/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"User configuration file is "/home/suah/.avrduderc"User configuration file does not exist or is not a regular file, skippingUsing Port                    : /dev/ttyACM0Using Programmer              : stk500v1Overriding Baud Rate          : 19200AVR Part                      : ATmega328PChip Erase delay              : 9000 usPAGEL                         : PD7BS2                           : PC2RESET disposition             : dedicatedRETRY pulse                   : SCKserial program mode           : yesparallel program mode         : yesTimeout                       : 200StabDelay                     : 100CmdexeDelay                   : 25SyncLoops                     : 32ByteDelay                     : 0PollIndex                     : 3PollValue                     : 0x53Memory Detail                 :Block Poll               Page                       PolledMemory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xffflash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xfflfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00Programmer Type : STK500Description     : Atmel STK500 Version 1.x firmwareHardware Version: 2Firmware Version: 1.18Topcard         : UnknownVtarget         : 0.0 VVaref           : 0.0 VOscillator      : OffSCK period      : 0.1 usavrdude: AVR device initialized and ready to accept instructionsReading | ################################################## | 100% 0.02savrdude: Device signature = 0x1e950f (probably m328p)
        avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performedTo disable this feature, specify the -D option.
        avrdude: erasing chip
        avrdude: reading input file "/tmp/arduino_build_456577/Blink.ino.hex"
        avrdude: writing flash (922 bytes):Writing | ################################################## | 100% 1.11savrdude: 922 bytes of flash written
        avrdude: verifying flash memory against /tmp/arduino_build_456577/Blink.ino.hex:
        avrdude: load data flash data from input file /tmp/arduino_build_456577/Blink.ino.hex:
        avrdude: input file /tmp/arduino_build_456577/Blink.ino.hex contains 922 bytes
        avrdude: reading on-chip flash data:Reading | ################################################## | 100% 0.62savrdude: verifying ...
        avrdude: 922 bytes of flash verifiedavrdude done.  Thank you.
        

  • 写个程序,手动编译,烧录

    • 程序 main.c

      #include <avr/io.h>
      #include <util/delay.h>void Led_Config();
      void Led_On();
      void Led_Off();void main()
      {Led_Config();while(1) {Led_On();_delay_ms(500);Led_Off();_delay_ms(500);}
      }void Led_Config()
      {DDRB |= (1 << 5);
      }void Led_On()
      {PORTB |= (1 << 5);
      }void Led_Off()
      {PORTB &= ~(1 << 5);
      }
      
    • Makefile(注意修改 烧录时的变量 AVRDUDE,使其与上一大步确认过的烧录命令一样)

      # parameters (change this stuff accordingly)
      # project name
      PRJ = main
      # avr mcu
      MCU = atmega328p
      # mcu clock frequency
      CLK = 16000000
      # avr programmer (and port if necessary)
      # e.g. PRG = usbtiny -or- PRG = arduino -P /dev/tty.usbmodem411
      PRG =# fuse values for avr: low, high, and extended
      # these values are from an Arduino Uno (ATMega328P)
      # see <http://www.engbedded.com/fusecalc/> for other MCUs and options
      LFU = 0xFF
      HFU = 0xDE
      EFU = 0x05
      # program source files (not including external libraries)
      SRC = $(PRJ).c
      # where to look for external libraries (consisting of .c/.cpp files and .h files)
      # e.g. EXT = ../../EyeToSee ../../YouSART
      EXT =#################################################################################################
      # \\/ stuff nobody needs to worry about until such time that worrying about it is appropriate \\/ #
      ################################################################################################## include path
      INCLUDE := $(foreach dir, $(EXT), -I$(dir))
      # c flags
      CFLAGS    = -Wall -Os -DF_CPU=$(CLK) -mmcu=$(MCU) $(INCLUDE)
      # any aditional flags for c++
      CPPFLAGS =# executables
      AVRDUDE = avrdude -C ~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf  $(PRG) -v -p $(MCU) -cstk500v1 -P/dev/ttyACM0 -b19200
      OBJCOPY = avr-objcopy
      OBJDUMP = avr-objdump
      SIZE    = avr-size --format=avr --mcu=$(MCU)
      CC      = avr-gcc# generate list of objects
      CFILES    = $(filter %.c, $(SRC))
      EXTC     := $(foreach dir, $(EXT), $(wildcard $(dir)/*.c))
      CPPFILES  = $(filter %.cpp, $(SRC))
      EXTCPP   := $(foreach dir, $(EXT), $(wildcard $(dir)/*.cpp))
      OBJ       = $(CFILES:.c=.o) $(EXTC:.c=.o) $(CPPFILES:.cpp=.o) $(EXTCPP:.cpp=.o)# user targets
      # compile all files
      all: $(PRJ).hex# test programmer connectivity
      test:$(AVRDUDE) -v# flash program to mcu
      flash: all$(AVRDUDE) -U flash:w:$(PRJ).hex:i# write fuses to mcu
      fuse:$(AVRDUDE) -U lfuse:w:$(LFU):m -U hfuse:w:$(HFU):m -U efuse:w:$(EFU):m# generate disassembly files for debugging
      disasm: $(PRJ).elf$(OBJDUMP) -d $(PRJ).elf# remove compiled files
      clean:rm -f *.hex *.elf *.o$(foreach dir, $(EXT), rm -f $(dir)/*.o;)# other targets
      # objects from c files
      .c.o:$(CC) $(CFLAGS) -c $< -o $@# objects from c++ files
      .cpp.o:$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@# elf file
      $(PRJ).elf: $(OBJ)$(CC) $(CFLAGS) -o $(PRJ).elf $(OBJ)# hex file
      $(PRJ).hex: $(PRJ).elfrm -f $(PRJ).hex$(OBJCOPY) -j .text -j .data -O ihex $(PRJ).elf $(PRJ).hex$(SIZE) $(PRJ).elf
      
    • 把makefile和main.c放在同一目录下,先 执行make ,再make flash 直接烧录,如下log:(注意,提前安装好所需的工具链,如 :make,avr-gcc等 )

      > make
      avr-gcc -Wall -Os -DF_CPU=16000000 -mmcu=atmega328p  -c main.c -o main.o
      main.c:8:6: warning: return type of 'main' is not 'int' [-Wmain]8 | void main()|      ^~~~
      main.c: In function 'Led_Off':
      main.c:31:15: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds]31 |         PORTB &= ~(1 << 5);|               ^~
      avr-gcc -Wall -Os -DF_CPU=16000000 -mmcu=atmega328p  -o main.elf main.o
      rm -f main.hex
      avr-objcopy -j .text -j .data -O ihex main.elf main.hex
      avr-size --format=avr --mcu=atmega328p main.elf
      AVR Memory Usage
      ----------------
      Device: atmega328pProgram:     194 bytes (0.6% Full)
      (.text + .data + .bootloader)Data:          0 bytes (0.0% Full)
      (.data + .bss + .noinit)> make flash
      avrdude -C ~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf   -v -p atmega328p -cstk500v1 -P/dev/ttyACM0 -b19200 -U flash:w:main.hex:iavrdude: Version 7.0Copyright (c) Brian Dean, <http://www.bdmicro.com/>Copyright (c) Joerg WunschSystem wide configuration file is "/home/suah/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"User configuration file is "/home/suah/.avrduderc"User configuration file does not exist or is not a regular file, skippingUsing Port                    : /dev/ttyACM0Using Programmer              : stk500v1Overriding Baud Rate          : 19200AVR Part                      : ATmega328PChip Erase delay              : 9000 usPAGEL                         : PD7BS2                           : PC2RESET disposition             : dedicatedRETRY pulse                   : SCKSerial program mode           : yesParallel program mode         : yesTimeout                       : 200StabDelay                     : 100CmdexeDelay                   : 25SyncLoops                     : 32PollIndex                     : 3PollValue                     : 0x53Memory Detail                 :Block Poll               Page                       PolledMemory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------eeprom                 65    20     4    0 no       1024    4      0  3600  3600 0xff 0xffflash                  65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xfflfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00hfuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00efuse                   0     0     0    0 no          1    1      0  4500  4500 0x00 0x00lock                    0     0     0    0 no          1    1      0  4500  4500 0x00 0x00calibration             0     0     0    0 no          1    1      0     0     0 0x00 0x00signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00Programmer Type : STK500Description     : Atmel STK500 Version 1.x firmwareHardware Version: 2Firmware Version: 1.18Topcard         : UnknownVtarget         : 0.0 VVaref           : 0.0 VOscillator      : OffSCK period      : 0.1 usavrdude: AVR device initialized and ready to accept instructionsReading | ################################################## | 100% 0.02savrdude: Device signature = 0x1e950f (probably m328p)
      avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performedTo disable this feature, specify the -D option.
      avrdude: erasing chip
      avrdude: reading input file "main.hex"
      avrdude: writing flash (194 bytes):Writing | ################################################## | 100% 0.28savrdude: 194 bytes of flash written
      avrdude: verifying flash memory against main.hex:Reading | ################################################## | 100% 0.16savrdude: 194 bytes of flash verifiedavrdude done.  Thank you.
      

用arduino mega2560通过isp给 arduino uno烧录程序相关推荐

  1. Arduino通过USB转TTL无BootLoader烧录程序的两种办法

    Arduino通过USB转TTL无BootLoader(引导程序)烧录程序的两种办法 注意 (这个实验室基于stm32duino的,avr单片机并不直接通用,不过如果你准备尝试使用串口来给avr单片机 ...

  2. 关于Arduino Mega2560的最基本介绍

    Arduino Mega 2560是基于ATmega2560的主控开发板.Arduino Mega2560是采用USB接口的核心电路板.具有54路数字输入输出,适合需要大量IO接口的设计.处理器核心是 ...

  3. 利用Arduino Nano 对于另外的Arduino控制板下载Bootloader

    简 介: 测试了利用Nano板对于基于MEGA328的Arduino的Bootloader下载,在此基础之上,利用了FT232TL的USB-TTL UART模块对测试MEGA328下载执行程序. 关键 ...

  4. 利用AVR单片机 专用下载 USBtinyISP对Arduino UNO下载程序

    简 介: 测试了利用USBtinyISP对于Arduino UNO,也就是ATmega系列的单片机下载Bootloader的过程.通过测试可以看到,利用USBtinyISP可以更快的下载ATmega系 ...

  5. Arduino Mega2560简介

    Mega2560是采用USB接口的核心电路板,具有54路数字输入输出,适合需要大量IO接口的设计.可通过3种方式供电,而且能自动选择供电方式. 具有54路数字输入输出. 概述 Arduino Mega ...

  6. 基于atmega8的arduino最小系统制作(arduino uno作为下载器)

    我们在最小系统的制作过程中,常常会遇到下载器驱动安装不成功的问题,绝大多数原因是因为下载器驱动不兼容win10系统.而当用arduino uno作为下载器为最小系统烧录程序的话,不但解决了win10下 ...

  7. arduino运行java_调试在Arduino MKR1000上运行的Arduino Uno代码

    所以,我是Arduino的业余程序员,之前从未使用过Arduino MKR1000 . 我使用了Arduino Uno并使用Grove Ear夹心跳传感器和Grove温度传感器编写附加代码来检测心跳和 ...

  8. Arduino + RFID 读取 IC 卡 Arduino uno中获得RFID的UID 并通过串口转发RFID卡号

    RFID简介:射频识别即RFID(Radio Frequency IDentification)技术,又称无线射频识别,是一种通信技术,可通过无线电讯号识别特定目标并读写相关数据,而无需识别系统与特定 ...

  9. Arduino mega2560蓝牙遥控小车简介

    Arduino mega2560蓝牙遥控小车简介 小车一览 主要模块如下: 一.电源 (1)BOM表:18650电池两节(单节3.6v,6800mAh) 18650 电池盒(两节带开关) 二.电机驱动 ...

最新文章

  1. 四个Webix实例:生成多种类型的JavaScript列表
  2. 同时用引用和指针 int *a;
  3. [BZOJ3631][JLOI2014]松鼠的新家
  4. muduo之GzipFile
  5. Ocelot中使用Butterfly实践
  6. 我的SourceInsight配置(附图)
  7. JSP的三六九四七(三大指令、六大标签、九大内置对象、四大作用域、七个动作指令)
  8. HDU3788 ZOJ问题
  9. 使用母版頁是內容如何使用CSS和javascript
  10. java中对date的一些处理以及获取date
  11. GridView实战一:自定义分页、排序、修改、插入、删除
  12. 抹去阴影,搞定了Cyclone III
  13. 【Docker】使用介绍
  14. 运行出现 Multiple dex files define Landroid/support/annotation/AnimRes 解决方法
  15. 魔兽局域网协议UDP部分详细解释
  16. 安卓 多条通知_【安卓+苹果】石头阅读,全网小说、漫画免费看,最好用的追书神器!...
  17. Arduino IDE 烧录 ESP8266教程
  18. postman中变量设置
  19. Laravel文档阅读笔记-Adding a Markdown editor to Laravel
  20. APP自动化测试-Appium编写脚本并执行

热门文章

  1. Vue实践--V-for指令
  2. JS键盘事件—onkeydown,onkeyup
  3. 嵌入式Linux应用开发学习(一)—嵌入式编程基本知识
  4. js中的class解构
  5. 各种有意思的效应、法则、理论、逻辑、实验
  6. 五面拿下阿里飞猪offer,java电子书百度云
  7. 关于谢尔宾斯基三角(Sierpinski)的讲解
  8. 基于深度学习的图像超分辨率方法 总结
  9. 【SNS】什么是精英?什么是草根?为什么要SNS?
  10. 数值分析-题目3-龙贝格和高斯求解牛顿迭代节点