I have a Atmega328P on a breadboard. I am using MKII to ISP program the chip with a bootloader. This works wonderfully. I can load blink this way also and that works.
I have usb connected using a "Breakout Board for FT232RL USB to Serial" from sparkfun. If I ISP load a sketch onto the Atmega328P I can get data to print out to the Serial Monitor so all is well there.
Here is where the problem is. If I burn a bootloader onto the chip and then try to upload a program via USB using the normal Arduino IDE I get the following error:
The funny thing is it worked ONE time, the first time, and no longer does. I have tried re-burning the bootloader but now it just does not work. It seems communication is fine since the Device Signature comes back ok. I have tried hitting reset right before it starts uploading and I get this message. I am using the optiboot bootloader.
During troubleshooting I did get the new Arduino 1.0.5 version (I was at 1.0.3).
This is driving me crazy, I've spend days on it and thought someone here might have some ideas.
What type of clocking are you using for the breadboard m328p? It needs to match the bootloader type and IDE board selection to get the right serial baud rate to match up.
Which optiboot file are you using? Are you burning bootloader from the IDE or from command line with avrdude?
I am using an external Crystal at 16 Mhz. I am using the Arduino IDE to upload and selecting "Arduino UNO" as the board. The optiboot file I am using is optiboot_atmega328.hex.
I am using the standard UNO fuse settings (in the output below). I read through the Gammon tutorial and loaded the board detector sketch. It worked just fine and here is the output:
Hiduino: I failed to answer your question correctly. I am using the Arduino IDE to upload the sketch, but I am using the Atmel Studio "Device Programming" to burn the bootloader.
After answering Hiduino's post and reading Nicks's I realized I should probably try to program the bootloader with an Arduino using Nicks Board Programmer option. Low and behold, it FAILED. I have no idea why. Here is the output in hoping it sparks an idea in someone:
Atmega chip programmer.
Written by Nick Gammon.
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xFF
HFuse = 0xDE
EFuse = 0xFD
Lock byte = 0xFF
Clock calibration = 0xA3
Bootloader address = 0x7E00
Bootloader length = 512 bytes.
Type 'L' to use Lilypad (8 MHz) loader, or 'U' for Uno (16 MHz) loader ...
Using Uno Optiboot 16 MHz loader.
Type 'V' to verify, or 'G' to program the chip with the bootloader ...
Erasing chip ...
Writing bootloader ...
Committing page starting at 0x7E00
Committing page starting at 0x7E80
Committing page starting at 0x7F00
Committing page starting at 0x7F80
Written.
Verifying ...
Verification error at address 7E00. Got: 0x00 Expected: 0x11
Verification error at address 7E01. Got: 0x00 Expected: 0x24
Verification error at address 7E02. Got: 0x00 Expected: 0x84
Verification error at address 7E03. Got: 0x00 Expected: 0xB7
Verification error at address 7E04. Got: 0x00 Expected: 0x14
Verification error at address 7E05. Got: 0x00 Expected: 0xBE
Verification error at address 7E06. Got: 0x00 Expected: 0x81
Verification error at address 7E07. Got: 0x00 Expected: 0xFF
Verification error at address 7E08. Got: 0x00 Expected: 0xF0
Verification error at address 7E09. Got: 0x00 Expected: 0xD0
Verification error at address 7E0A. Got: 0x00 Expected: 0x85
Verification error at address 7E0B. Got: 0x00 Expected: 0xE0
Verification error at address 7E0C. Got: 0x00 Expected: 0x80
Verification error at address 7E0D. Got: 0x00 Expected: 0x93
Verification error at address 7E0E. Got: 0x80 Expected: 0x81
Verification error at address 7E0F. Got: 0xC0 Expected: 0x00
Verification error at address 7E10. Got: 0x00 Expected: 0x82
Verification error at address 7E11. Got: 0x00 Expected: 0xE0
Verification error at address 7E12. Got: 0x00 Expected: 0x80
Verification error at address 7E13. Got: 0x00 Expected: 0x93
Verification error at address 7E14. Got: 0x00 Expected: 0xC0
Verification error at address 7E16. Got: 0x00 Expected: 0x88
Verification error at address 7E17. Got: 0xC0 Expected: 0xE1
Verification error at address 7E18. Got: 0x00 Expected: 0x80
Verification error at address 7E19. Got: 0x00 Expected: 0x93
Verification error at address 7E1A. Got: 0x80 Expected: 0xC1
Verification error at address 7E1B. Got: 0xC0 Expected: 0x00
Verification error at address 7E1C. Got: 0x80 Expected: 0x86
Verification error at address 7E1D. Got: 0xC0 Expected: 0xE0
Verification error at address 7E1E. Got: 0xE0 Expected: 0x80
Verification error at address 7E1F. Got: 0xE0 Expected: 0x93
Verification error at address 7E20. Got: 0x00 Expected: 0xC2
Verification error at address 7E22. Got: 0x00 Expected: 0x80
Verification error at address 7E23. Got: 0x00 Expected: 0xE1
Verification error at address 7E24. Got: 0x00 Expected: 0x80
Verification error at address 7E25. Got: 0x00 Expected: 0x93
Verification error at address 7E26. Got: 0x80 Expected: 0xC4
Verification error at address 7E27. Got: 0xC0 Expected: 0x00
Verification error at address 7E28. Got: 0x00 Expected: 0x8E
Verification error at address 7E29. Got: 0x00 Expected: 0xE0
Verification error at address 7E2A. Got: 0x80 Expected: 0xC9
Verification error at address 7E2B. Got: 0xC0 Expected: 0xD0
Verification error at address 7E2C. Got: 0x80 Expected: 0x25
Verification error at address 7E2D. Got: 0x80 Expected: 0x9A
Verification error at address 7E2E. Got: 0xC0 Expected: 0x86
Verification error at address 7E30. Got: 0x00 Expected: 0x20
Verification error at address 7E31. Got: 0x00 Expected: 0xE3
Verification error at address 7E32. Got: 0x80 Expected: 0x3C
Verification error at address 7E33. Got: 0x80 Expected: 0xEF
Verification error at address 7E34. Got: 0x80 Expected: 0x91
Verification error at address 7E35. Got: 0x80 Expected: 0xE0
Verification error at address 7E36. Got: 0xC0 Expected: 0x30
Verification error at address 7E37. Got: 0xE0 Expected: 0x93
Verification error at address 7E38. Got: 0x80 Expected: 0x85
Verification error at address 7E39. Got: 0x80 Expected: 0x00
Verification error at address 7E3A. Got: 0xC0 Expected: 0x20
Verification error at address 7E3B. Got: 0xE0 Expected: 0x93
Verification error at address 7E3C. Got: 0xC0 Expected: 0x84
Verification error at address 7E3D. Got: 0xE0 Expected: 0x00
Verification error at address 7E3E. Got: 0xF0 Expected: 0x96
Verification error at address 7E3F. Got: 0xF0 Expected: 0xBB
Verification error at address 7E40. Got: 0x00 Expected: 0xB0
Verification error at address 7E41. Got: 0x00 Expected: 0x9B
Verification error at address 7E42. Got: 0x00 Expected: 0xFE
Verification error at address 7E43. Got: 0x00 Expected: 0xCF
Verification error at address 7E44. Got: 0x00 Expected: 0x1D
Verification error at address 7E45. Got: 0x00 Expected: 0x9A
Verification error at address 7E46. Got: 0x80 Expected: 0xA8
Verification error at address 7E47. Got: 0xC0 Expected: 0x95
Verification error at address 7E48. Got: 0x00 Expected: 0x81
Verification error at address 7E49. Got: 0x00 Expected: 0x50
Verification error at address 7E4A. Got: 0x80 Expected: 0xA9
Verification error at address 7E4B. Got: 0xC0 Expected: 0xF7
Verification error at address 7E4C. Got: 0x80 Expected: 0xCC
Verification error at address 7E4D. Got: 0x80 Expected: 0x24
Verification error at address 7E4E. Got: 0xC0 Expected: 0xDD
Verification error at address 7E4F. Got: 0xE0 Expected: 0x24
Verification error at address 7E50. Got: 0x00 Expected: 0x88
Verification error at address 7E51. Got: 0x00 Expected: 0x24
Verification error at address 7E52. Got: 0x80 Expected: 0x83
Verification error at address 7E53. Got: 0x80 Expected: 0x94
Verification error at address 7E54. Got: 0x80 Expected: 0xB5
Verification error at address 7E55. Got: 0x80 Expected: 0xE0
Verification error at address 7E56. Got: 0xC0 Expected: 0xAB
Verification error at address 7E57. Got: 0xE0 Expected: 0x2E
Verification error at address 7E58. Got: 0x80 Expected: 0xA1
Verification error at address 7E59. Got: 0x80 Expected: 0xE1
Verification error at address 7E5A. Got: 0xC0 Expected: 0x9A
Verification error at address 7E5B. Got: 0xE0 Expected: 0x2E
Verification error at address 7E5C. Got: 0xC0 Expected: 0xF3
Verification error at address 7E5E. Got: 0x00 Expected: 0xBF
Verification error at address 7E5F. Got: 0xF0 Expected: 0x2E
Verification error at address 7E60. Got: 0x00 Expected: 0xA2
Verification error at address 7E61. Got: 0x00 Expected: 0xD0
Verification error at address 7E62. Got: 0x80 Expected: 0x81
Verification error at address 7E63. Got: 0x80 Expected: 0x34
Verification error at address 7E64. Got: 0x80 Expected: 0x61
Verification error at address 7E65. Got: 0x80 Expected: 0xF4
Verification error at address 7E66. Got: 0xC0 Expected: 0x9F
Verification error at address 7E67. Got: 0xE0 Expected: 0xD0
Verification error at address 7E68. Got: 0x80 Expected: 0x08
499 verification error(s).
First 100 shown.
Type 'C' when ready to continue with another chip ...
It looks like either bad wiring connections or possibly bad clocking. You should double check you wiring and make sure they are good connections. Also check your 16MHz crystal and 22pF capacitors that they are wired properly.
Do you have a picture of your breadboard you could attach?
OK, still having problems but have tried many more things. I DID have an SPI memory chip on the same connections so I have removed that. It did not help. I have replaced the clock crystal and capacitors (22pf). These are short runs just on the breadboard with no jumpers, just connected directly to ground. The capacitors are sitting on the far side of the clock crystal from the atmega chip.
The SPI.setClockDivider (SPI_CLOCK_DIV64); line is still in the sketches from Nick, and I have made no alteration to those sketchs.
Here is where I have some new information. If I load a hex file from the mkII onto the board it works perfectly. I can run it for hours and it continues to blink LEDs regularly and write information out to the Serial Monitor with no problems. I am writing a 50 character message every 301 milliseconds and according to the internal millis, it is writing every 302 milliseconds ( so the sketch loop takes about 1 to run ). I also read data and return back out. This continues to work perfectly.
So connected to USB sure appears to work just fine.
However it still cannot load a program with USB. I tried using the Atmega_Board_Detector, and did find some interesting behavior. when I reset the Arduino running the sketch, it pauses until I hit the reset button (as expected). However if I hold down the reset button for a long time it reads out the entire bootloader correctly. If on the other hand I press it very quickly, the faster I press it the LESS data it reads. If I do a rapid press, it only reads a few lines of code. If it reads the entire thing, I can compare it to the optiboot hex and it matches.
This combined with the fact that I get PARTWAY through the usb sketch loading (still getting to the same place as my previous post) sure make it seem like a clocking difference, but for the life of me and can't figure out what the problem should be. In Atmel Studio, when loading the bootloader with the Device Programming window, I can run it at 4 Mhz which should indicate it is indeed running at 16 Mhz (since Device Programming only works at 1/4 speed).
stephenholm:
However it still cannot load a program with USB. I tried using the Atmega_Board_Detector, and did find some interesting behavior. when I reset the Arduino running the sketch, it pauses until I hit the reset button (as expected). However if I hold down the reset button for a long time it reads out the entire bootloader correctly. If on the other hand I press it very quickly, the faster I press it the LESS data it reads. If I do a rapid press, it only reads a few lines of code. If it reads the entire thing, I can compare it to the optiboot hex and it matches.
Sound like the reset pin on the m328p is not connecting properly. You might have a bad contact position on your breadboard.
How are you connecting up to reset on the m328p? The programmers (AVRISPMKII and Atmega_Board_Detector) should go direct to the reset pin and have a 10K ohm pull-up resistor.
For the USB serial, the DTR should be going to a 0.1uF capacitor then to the reset pin on the m328p.
solution is quiete simple but very hard to find. I used it today with success.
You have to add a 10k resistor between pin 2(RX) and VCC, and an other one beetween pin 3 (TX) and VCC too.
I didn't beleive it before I tried it. It works now with an ATmega328P-PN (nearly same as PU) with optiboot on a breadboard.
I have a 10 Kohm pull up resistor on the reset pin of the atmega. The reset pins for the AVRISPMKII and Atmega_Board_Detector goes directly to the reset pin. Using the AVRISPMKII I do not have to do anything and it works. Using Atmega_Board_Detector I DO have to press the reset button for it to work.
I do NOT have a 0.1uF from the DTR pin to the reset pin. Is this needed? I thought/hoped I could just hit reset before it started programming.
Nick: As far as decoupling capacitors, I am using a lithium polymer battery to power the board and am NOT using a regulator. The battery is fully charged and running between 4 and 4.1 volts. I have one 4.7 uF capacitor between the power leg and ground right next to the input from the battery.
The blue capacitors are the decoupling capacitors. They are required for reliable operation. In fact they should be closer than I showed there. Directly adjacent to the chip legs, not a couple of centimeters away.
I should have cut those blue and red wires shorter and put the capacitors next to the pins. However this particular setup worked.
Using Atmega_Board_Detector I DO have to press the reset button for it to work.
That's odd. Can you post a picture? I never have to press reset. Something is seriously wrong if you do. I should point out that the Atmega_Board_Detector holds /Reset low during programming (that's how you enter programming mode). However it does it programmatically. If you have to do it yourself there is something major wrong.
stephenholm:
I have a 10 Kohm pull up resistor on the reset pin of the atmega. The reset pins for the AVRISPMKII and Atmega_Board_Detector goes directly to the reset pin. Using the AVRISPMKII I do not have to do anything and it works. Using Atmega_Board_Detector I DO have to press the reset button for it to work.
Ahh, For the Atmega_Board_Detector, you need to use pin D10 to the reset on the m328p.(Not reset to reset)
stephenholm:
I do NOT have a 0.1uF from the DTR pin to the reset pin. Is this needed? I thought/hoped I could just hit reset before it started programming.
That is fine, you don't need the reset capacitor. You just need to time when you hit the reset button.
nbenm: It worked ... do you happen to know why? I put the two 10 Kohm pull up resistors on the two communication pins between the USB controller and the atmega chip. Did that and bingo! it works! Is still am not using the .1 uF on the DTR pin, I'm just hitting reset instead.
Nick: I do have a 10 uF capacitor on the analog power circuit and it is right next to the pin. On the power side I have the 4.7 uF I mentioned but it is closer to the power supply. So you believe I should have the .1 uFs right next to the chip also?
hiduino: Understood, I had it wired incorrectly for the Atmega_Board_Detector.
stephenholm:
Nick: I do have a 10 uF capacitor on the analog power circuit and it is right next to the pin. On the power side I have the 4.7 uF I mentioned but it is closer to the power supply. So you believe I should have the .1 uFs right next to the chip also?
Yes I do. The 0.1 uF filter a different frequency than the 4.7 uF.
stephenholm:
I put the two 10 Kohm pull up resistors on the two communication pins between the USB controller and the atmega chip. Did that and bingo! it works!
After reviewing the FT232RL breakout board from SparkFun, it turns out that it is running at default of 3.3v i/o levels which explains why the serial was not working correctly. You have a mismatch of i/o voltage level interfacing to the m328P. The 10K pull-up is probably biasing the level enough to work, but not the recommended way to do level conversion.