I'm currently getting into AVR programming, and I'm talking not just the Arduino way, but also the good ol' C way.
Even though I'm not really a hardware guy, getting baremetal has been what I've wanted. It's just that there hasn't been much chance. Fortunately, working from home gave me some of that.
Equiped with an ATMega on a breadboard, I started my journey. Now, the Arduino Uno itself probably has some stories to tell, but that's probably for next time.
I started by putting together an Arduino clone on a breadboard to get that AVR running. I'm not going to get into detail on this because the Arduino site got some nice instruction on it.
After the hardware was set up, I tried burning the bootloader and uploading some demo program to get some LED blinking. The LED was blinking.
Time to get into the core of it.
Hackaday got some nice tutorial on it. All I needed was a Linux computer running avrdude. However, with the fact that it's been ten years since written, adjustments had to be made (details follow).
Now, you're probably wondering what the BusPirate is doing in that picture. I was trying to use it to program the AVR. In fact, I've been using it as one up to this point. Turned out the MISO line wasn't working properly for some reason. Found out about it after countless attempt to flash the C code. I did manage to flash the bootloader and all on the previous step, which is why I didn't find it sooner.
Thankfully, I got a spare Arduino Uno. The Arduino people are kind enough to have sample code that turns the board into an ISP programmer. There's even a tutorial on it! Onward with that!
After numerous more failures, I found out that using 'arduino' as the programmer option on the avrdude (avrdude -c arduino . . . .
) would flash the C code into the Arduino instead of whatever it's connected to. No wonder the LED was blinking on it and not the breadboard instead...
I found out about it after unsuccessfully trying to burn bootloader into the breadboard. Tried it again after reuploading the Arduino as ISP sketch and it worked.
The next hour was spent searching online for the right -c
option. A StackOverflow post told me to use -c avrisp
. This turned out to be the right answer.
The last but not least gotcha was the baudrate. It had to be set properly as well otherwise the serial connection would be garbage. After I got that fixed, the C code was finally uploaded, and the LED was once again blinking on the breadboard.
The next part would be on dealing with the C code itself.