Arduino as ISP 下载器烧录BootLoader的细节详解

前言

        关于Arduino as ISP,之前弄过几次,但是每次开搞前都要重新温习一遍官方英文文档,略显麻烦,现在自己全部重新解析一下,记录下来后效率明显提升:一是变成中文方便阅读,二是把重要细节全部暴露出来,比原版文档更加丰富。所以有这一篇就够了,欢迎收藏和转载,也欢迎提出补充修正建议。

1、要让一块芯片成为“Arduino”,需要有一个“Arduino Bootloader”的基因;

2、给Arduino进行ISP烧录,使用的是SPI接口,而每种板子的SPI引脚并不相同,所以有了下图:最经典的当然还是11、12、13啦。

3、ICSP的引脚图如下:注意比照就行,不要用万用表去测出正负极。因为我就这样先入为主了一次,看到5V就以为找到了VCC和GND,误导自己半天。

4、nano icsp引脚需要特别说明一下,我是吃过亏栽过跟头的。我一直以为1号引脚是第二行左边第一脚,有三角形指示的那个,结果却不是………………最终发现是右上角那个,居然还写了一个“1”,焊了排针之后哪里看得到,尤其是第一次买nano的人。

       看看这张我还没有焊接的粉色版,原来如此清晰,可细节总是让人容易忽视。

       后来我知道了。那个与众不同的正方形焊盘就是用来标记第1脚的,这也是PCB设计常用的技巧。

5、这些SPI引脚和ICSP上面的是直通的,但不能直接偷懒直接连接两块板子的ICSP接口来进行编程,因为reset引脚不是那样工作的。

6、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.板子和计算机之间有一个专门处理USB的芯片的,需要加10µF电容,比如Mega, UNO, Mini, Nano;那种微控制器直接管理USB的,不需要加,比如Leonardo, Esplora and Micro。这也就是说,我们一般人使用的常见的应该都是要加,尤其是我们本土大把的ch340改进版。

7、3.3V和5V的设备如何兼容?将3.3V插到5V的插孔里,反过来就不要想了。我查了电路图,左边的3.3V设备的红色线是3.3V。

8、在Arduino ISP的源代码里也有很多有用的知识

// ArduinoISP
// Copyright (c) 2008-2011 Randall Bohn
// If you require a license, see
// https://opensource.org/licenses/bsd-license.php
//
// This sketch turns the Arduino into a AVRISP using the following Arduino pins:
//
// Pin 10 is used to reset the target microcontroller.
//
// By default, the hardware SPI pins MISO, MOSI and SCK are used to communicate
// with the target. On all Arduinos, these pins can be found
// on the ICSP/SPI header:
//
//               MISO °. . 5V (!) Avoid this pin on Due, Zero...
//               SCK   . . MOSI
//                     . . GND
//
// On some Arduinos (Uno,...), pins MOSI, MISO and SCK are the same pins as
// digital pin 11, 12 and 13, respectively. That is why many tutorials instruct
// you to hook up the target to these pins. If you find this wiring more
// practical, have a define USE_OLD_STYLE_WIRING. This will work even when not
// using an Uno. (On an Uno this is not needed).
//
// Alternatively you can use any other digital pin by configuring
// software ('BitBanged') SPI and having appropriate defines for PIN_MOSI,
// PIN_MISO and PIN_SCK.
//
// IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...) as
// the programmer, make sure to not expose any of the programmer's pins to 5V.
// A simple way to accomplish this is to power the complete system (programmer
// and target) at 3V3.
//
// Put an LED (with resistor) on the following pins:
// 9: Heartbeat   - shows the programmer is running
// 8: Error       - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the target

源代码还实现了3个LED的功能,但是可能用的人很少。

#define LED_HB 9

#define LED_ERR 8

#define LED_PMODE 7

       待我焊一块原型版,来把它永远固化下来,我不想反反复复学了又忘,忘了又学,永无止境,没完没了…...(二〇二三年二月二十一日)搞定,有了这块下载器扩展板,妈妈再也不担心我搞错引脚了,烧写效率拉到满。绿色LED就是心跳呼吸灯。

  1. 然后要在“工具”菜单选择“开发板”类型为目标板,目标板,目标板。

  2. 继续选择“工具”菜单中的“编程器”为“Arduino as ISP”,一个字都不要错。

  3. 最后一步,还是“工具”菜单,“烧录引导程序(Burn BootLoader)”!

  4. 另外,也可以靠这个硬件连接直接用Arduino给目标板编写代码、编译并烧录到目标板:选择“项目(sketch)”——“使用编程器上传”,这个相貌平平的IDE其实功能非常强大。

  5. 但是这里又有一个坑,如果使用“编程器上传”功能的话,那么它会覆盖掉里面的BootLoader……我好几次搞好之后,立刻测试了一下软件功能,结果又凉凉,一直迷惑,直到后来确认了这条知识……

  6. 底层一点的东西:熔丝位

NANOUNO
UNLOCK3F3F
LOCK0F0F
EFDFD
HDADE
LFFFF
ID

1E950F(328)

1E9406(168)

9、烧录NANO的命令行

  • (328p oldBootLoader:ATmegaBOOT_168_atmega328.hex)C:\Users\Administrator\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\Administrator\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM8 -b19200 -Uflash:w:C:\Users\Administrator\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:i -Ulock:w:0x0F:m 

  • (328p newBootloaer:optiboot_atmega328.hex)C:\Users\Administrator\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -cstk500v1 -PCOM8 -b19200 -Uflash:w:C:\Users\Administrator\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6/bootloaders/optiboot/optiboot_atmega328.hex:i -Ulock:w:0x0F:m

10、最终,最终,我还是把蓝板Nano救活了,所有的过程都经历了一遍……甚至包括这里

https://support.arduino.cc/hc/en-us/articles/4401874331410--Error-avrdude-when-uploading#avrdude-stk500_recv-and-stk500_getsyncicon-default.png?t=N7T8https://support.arduino.cc/hc/en-us/articles/4401874331410--Error-avrdude-when-uploading#avrdude-stk500_recv-and-stk500_getsync一条一条地看过了。

11、最后记录一个东西:我买的Nano不是用Oldbootloader,不是用Oldbootloader,不是用Oldbootloader。哪怕卖家这么说,宝贝详情里这么写,我的用的是新的BootLoader!

12、对于168和328的区分,其实在烧录的时候是有提示的。

avrdude: Device signature = 0x1e9406 (probably m168)
avrdude: reading input file "F:\Temp\arduino-sketch-9F68FE81888A761378D9D0B4950016EC/Blink.ino.hex"
avrdude: writing flash (922 bytes):

13、原版总结:

Recap: burn the Bootloader in 8 steps

Open the ArduinoISP firmware (in Examples) to your Arduino board.

Note for Arduino 1.0: you need to make one small change to the ArduinoISP code. Find the line in the heartbeat() function that says "delay(40);" and change it to "delay(20);".

Select the items in the Tools > Board and Serial Port menus that correspond to the board you are using as the programmer (not the board being programmed).

Upload the ArduinoISP sketch.

Wire your Arduino boards..

Select the item in the Tools > Board menu that corresponds to the board on which you want to burn the bootloader (not the board that you're using as the programmer). See the board descriptions on the environment page for details.

Select the Arduino as ISP in the Tools>Programmer menu.

Use the Burn Bootloader command.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

safirst

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值