Noob question, I am trying to design a custom board based on a Atmega328P-AU SMD chip, including an I2C interfaced IMU and an HC-05 Bluetooth module for a wearable device. However, I get confused trying to understand how I could bootload and subsequently program my custom board.
My understanding is that to burn the bootloader, I can simply use an Arduino Uno with the ArdionoISP sketch and connect its VCC, GND, D11, D12 and D13 Reset pins to the 6 ICSP pins that I'm including in my custom board, correct?
If so, my main question is: can I upload sketches to my custom board in the same exact way? I am confused since I do't really understand whether a USB to Serial module such as the CH340G is strictly necessary to program my custom board after burning the bootloader, or I can avoid including one in my custom PCB and just use the ICSP pins for both bootloading and programming.
I would prefer to avoid using Serial to USB since my custom board won't include a USB port, but also because the TX and RX pins will be taken up by the HC-05 Bluetooth module that connects directly to them. Will the HC-05 being connected to TX/RX cause problems in any way or prevent me from flashing code to my board properly? I'm asking this because currently, with my breadboard prototype (using an Arduino Nano), I'm having to disconnect RX and TX every time I flash code to the Arduino. How do I avoid this in my final PCB design where the Bluetooth module will be hard-soldered to the TX/RX pins of the Atmega? If possible, will flashing code via the ICSP pins bypass this issue completely?
Apologies for the long text, hopefully someone will be patient enough to clarify this for me!
Vcc, Gnd, SCK, MOSI, MISO and pin 10 of arduino running Arduino as ISP go to Vcc, Gnd, SCK, MOSI, MISO, and Reset of target.
Depending on the version of Arduino IDE being used, you may need a 10uF cap between reset and ground on the programmer as well (after uploading Arduino as ISP to it)
You may use ICSP programming to program the chip - this will erase the bootloader (though not unset the fuses) which it sounds like is appropriate for your application.
I would recommend using MiniCore if you go this route, as it will let you use the 512 bytes that the bootloader would normally take up for the sketch.
DrAzzy:
Vcc, Gnd, SCK, MOSI, MISO and pin 10 of arduino running Arduino as ISP go to Vcc, Gnd, SCK, MOSI, MISO, and Reset of target.
Depending on the version of Arduino IDE being used, you may need a 10uF cap between reset and ground on the programmer as well (after uploading Arduino as ISP to it)
You may use ICSP programming to program the chip - this will erase the bootloader (though not unset the fuses) which it sounds like is appropriate for your application.
I would recommend using MiniCore if you go this route, as it will let you use the 512 bytes that the bootloader would normally take up for the sketch.
Thanks for your quick reply! That's all clear, so if I understood properly, I might need to put a 10uF cap between reset and ground of the Arduino Uno I'm using as a programmer and that's it. Do I still need to burn the bootloader even if it'll be erased when programming my chip via ISP?
And how about TX/RX of my chip being connected to the Bluetooth module causing interference with flashing code via ICSP? It shouldn't be an issue since I'm only using cc, Gnd, SCK, MOSI, MISO, and Reset of the target chip if I'm not mistaken?
Yes, you still need to burn bootloader - it also sets the fuses
(note that if you switch to MiniCore in "no bootloader" mode for the extra flash, you do need to burn bootloader again, to unset BOOTRST fuse, which tells it to jump to the bootloader; this isn't a problem if the bootloader is erased - blank flash is 0xFF, and 0xFFFF is a no-op in AVR and you keep using a board def that does have the bootloader. But if you were to change to minicore (no bootloader) option, but not reburn bootloader, if your sketch reached the last 512 bytes of flash, the sketch wouldn't run and/or would misbehave)
No problem from TX/RX being connected to the bluetooth module if you're not using the bootloader.
Long term, it would a good idea to spend $5 on a dedicated ISP programmer rather than using a repurposed Uno. That’s doable for a one-off, but it’s a pain for anything more than that. Check eBay for usbasp which is available with a translucent blue cover and a six pin adapter that plugs directly onto the ISP header pins. Compact and easy to use. The cheap ones are about $2 but they have no cover, it’s just a small bare board with an atmega8 on it, pre-programmed with the software. Look for the units with the cover for better reliability.
If this project will be something you produce multiple copies of, you’ll find you can set the fuses and load your program with a command line batch file rather than setting the fuses indirectly by burning the bootloader (which is then earased when you load your program). If and when that comes about and you’ve not comfortable with command line tools, just post here and ask for help.