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.

<think>嗯,用户之前已经询问过烧录器的基本概念和常见类型,现在又具体问到了Arduino as ISP,也就是如何将Arduino开发板改造成简易烧录器。这说明用户可能正在尝试自己动手做一些嵌入式开发或者DIY项目,想要了解如何利用手头的Arduino板子来烧录其他芯片,比如AVR单片机。 首先,我需要确定用户的需求层次。用户可能已经知道烧录器是什么,但需要具体的步骤和方法来使用Arduino作为ISP。他们可能希望有一个成本低、易于操作的解决方案,可能是在个人项目或教育环境中使用,比如在学校里或者自己的创客项目里。 接下来,我需要整理关于Arduino as ISP的相关信息。这包括它的定义、适用场景、所需材料、配置步骤、具体操作流程以及注意事项。用户可能需要详细的步骤说明,包括代码上传、硬件连接、烧录软件的使用等。同时,用户可能不太熟悉技术细节,所以需要用简单明了的语言,避免专业术语过多,或者在必要时解释术语。 还要考虑到用户可能遇到的问题,比如驱动程序安装、接线错误、电压不匹配等,所以在注意事项部分需要特别强调这些点,帮助用户避免常见错误。此外,用户可能想知道Arduino as ISP的优缺点,比如低成本但速度较慢,适合小规模使用,不适合量产,这些也需要提及。 需要确保回答结构清晰,分步骤说明,让用户能够一步步跟随操作。同时,可能需要推荐一些常用的烧录软件,比如AVRDUDE,并说明如何配置参数。用户可能对命令行工具不太熟悉,所以需要给出具体的命令示例,并解释每个参数的作用。 最后,用户可能有后续问题,比如如何处理特定型号的芯片,或者遇到错误时如何调试,因此应该在结尾邀请用户提供更多细节以便进一步帮助,这能增加互动性和用户满意度。</think>以下是关于 **Arduino as ISP** 的详细介绍: --- ### 什么是 Arduino as ISP? **Arduino as ISP** 是一种通过软件配置,将普通 Arduino 开发板(如 Uno、Nano)改造成 **AVR 芯片烧录器** 的低成本方案。它利用 Arduino 自带的 SPI 通信接口,配合特定固件,实现对其他 AVR 单片机(如 ATmega328P、ATtiny85)的编程和擦除。 --- ### 适用场景 - **低成本开发**:无需购买专用烧录器(如 USBasp)。 - **教育/实验**:学习 AVR 芯片烧录原理及 SPI 通信机制。 - **维修与调试**:修复 Arduino 引导程序(Bootloader)损坏的芯片。 - **DIY 项目**:为独立 ATmega 芯片烧录自定义程序。 --- ### 所需材料 1. **主控 Arduino**:作为烧录器的 Arduino 板(如 Uno、Nano)。 2. **目标芯片**:待烧录的 AVR 单片机(如 ATmega328P)。 3. **连接线**:杜邦线(至少 6 根)。 4. **外围电路**:根据目标芯片需求,可能需外接晶振、电容等。 --- ### 配置步骤(以 Arduino Uno 为例) #### 1. **上传 ArduinoISP 固件** - 打开 Arduino IDE,选择 **文件 > 示例 > 11.ArduinoISP > ArduinoISP**。 - 选择开发板型号(如 Arduino Uno)及端口,点击 **“上传”**。 - 上传成功后,Arduino 变为 ISP 烧录器。 #### 2. **硬件连接** 将主控 Arduino 与目标芯片按以下方式连接: | 主控 Arduino | 目标芯片引脚 | |--------------|--------------| | 13 (SCK) | SCK | | 12 (MISO) | MISO | | 11 (MOSI) | MOSI | | 10 (SS) | RESET | | 5V | VCC | | GND | GND | ⚠️ **注意**: - 若目标芯片需外部晶振,需额外连接晶振电路(如 16MHz 晶振 + 22pF 电容)。 - 部分低电压芯片(如 ATtiny85)需将 VCC 改为 3.3V。 --- ### 烧录操作(以烧录 ATmega328P 为例) #### 1. **配置 Arduino IDE** - 安装目标芯片支持包(如通过 **工具 > 开发板 > 开发板管理器** 添加 ATmega328P)。 - 选择目标芯片型号:**工具 > 开发板 > ATmega328P**。 - 选择编程器:**工具 > 编程器 > Arduino as ISP**。 #### 2. **烧录引导程序(Bootloader)** - 点击 **工具 > 烧录引导程序**,IDE 将通过主控 ArduinoBootloader 写入目标芯片。 - 成功提示后,目标芯片即可通过串口接收程序。 #### 3. **直接烧录程序(可选)** - 编写程序并编译(生成 `.hex` 文件)。 - 使用命令行工具(如 `avrdude`)执行烧录: ```bash avrdude -p atmega328p -c arduino -P COM3 -b 19200 -U flash:w:program.hex ``` --- ### 优缺点对比 | **优点** | **缺点** | |------------------------------|---------------------------| | 成本极低(仅需 Arduino 板) | 烧录速度较慢 | | 支持常见 AVR 芯片 | 仅支持 SPI 接口芯片 | | 适合小批量实验 | 稳定性不如专业烧录器 | --- ### 注意事项 1. **电压匹配**:确认目标芯片工作电压(5V/3.3V),必要时加装电平转换模块。 2. **接线检查**:SPI 引脚连接错误会导致烧录失败。 3. **驱动安装**:若使用旧版 IDE,需手动安装 `libusb` 驱动(Windows 系统)。 4. **芯片保护**:操作前断开电源,避免短路或反接。 --- 如果需要具体芯片的接线图或故障排查,请补充以下信息: - **目标芯片型号**(如 ATtiny13、ATmega2560)。 - **遇到的问题**(如无法识别设备、校验错误等)。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

safirst

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

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

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

打赏作者

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

抵扣说明:

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

余额充值