Hi all,
I have an arduino-compatible board whose USB port fell out (I tried, but failed to solder it back on due to lack of skills), so I am now resorting to programming that board via the ISP interface instead (I do not need the USB interface for my application).
Unfortunately, I am facing a strange problem that I’m not sure how to solve. Basically, I am trying to program (using the AVRISP mkII) that Arduino-compatible board equipped with ATmega168, but the codes that I download into the ATmega168 only runs if the board’s ISP socket is connected to the AVRISP mkII (which is connected & powered by USB).
I have tried 2 ways to compile my codes into hex files:
- using Arduino IDE (via shift + compile)'s temporary hex file, after compiling their sample code (e.g. servo)
- using AVR Studio 4 (below is an example code):
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRD = 0xFF;
int onState=1;
while(1)
{
if(onState)
{
PORTD = 0x04;
}
else
{
PORTD = 0x00;
}
onState = 1 - onState;
_delay_ms(5000);
}
return 1;
}
I’ve verified that the above code works using a multimeter (when the board is connected to the AVRISP mkII, pin D2 fluctuates between 0V and 5V, and other pins stay at 0V). But the moment I remove the AVRISP mkII from the USB port, the above code no longer runs (pin D2 just remains at 0V, but pin D1 stays at 3V, whereas pin D0 stays at 5V, where pin D0 & D1 are Serial TX & RX respectively). The schematics of this arduino-compatible board is uploaded at (Just a moment...) if it helps.
I have no idea why this happens, hence I have no idea how to fix this problem. I believe that once the hex file is downloaded into the ATmega168, it should remain there forever, and start running once it is powered? But this isn’t the case for me…
I am sincerely hoping for any suggestions on what might be the cause of this weird behavior…
After consulting from other forums, I realize that I am also not so sure how to check if my board’s original arduino bootloader was erased when I downloaded the hex file into my ATmega168. All that I can describe is that whenever I program a new hex file into my board’s ATmega168’s Flash memory, I enabled (by default) both “Erase device before programming” and “verify device after programming”. And the screenshots below show the current settings read by the AVRISP mkII programmer:
Are my fuse & lock bits correct? Unfortunately, I am lacking in knowledge & understanding regarding all these fuse & lock bits…
but I did observe (according to http://www.arduino.cc/playground/Learning/Burn168), that my ATmega168’s fuse-settings are correct (for ATmega168 Arduino’s bootloader) but my LockBits are wrong (my ATmega168 did not have “LPM and SPM prohibited in Boot Loader Section”).
Is it possible to “erase the Arduino bootloader” but still be able to download the Arduino IDE (via shift + compile)'s temporary hex file into my ATmega168 using the AVRISP mkII programmer, and make my code run? If yes, what should my fuse & lock bits settings be? I am most worried that I will “brick” my board by choosing the wrong settings…
I am hoping that it is the Arduino bootloader that is causing all these problems, since the moment I remove the AVRISP mkII from the USB port, pin D0 (Serial TX) stays at 5V, whereas pin D1 (Serial RX) stays at 3V. But I am unsure why/how the no-longer soldered USB port is responsible for this (if at all). All I know is that according to http://arduino.cc/en/Tutorial/Bootloader :
It’s possible to “confuse” the bootloader so that it never starts your sketch. In particular, if you send serial data to the board just after it resets (when the bootloader is running), it may think you’re talking to it and never quit.
This is my current guess, but I’m not sure how to check/test if this is true, or even how to correct it, due to my lack of knowledge & understanding…
Sincerely hoping for any advice