Can't program ATMEGA2560 from Arduino IDE (custom board)

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Long story short, I have an arduino mega-based custom board (…that directly copies the Atmega2560 and atmega16u2 configuration as on the Mega board.)

On my new board, I can put code in through ISP (using Arduino-as-ISP), but not through USB. I have flashed the atmega16U2 chip and it is working (and showing up in the IDE as a Mega 2560) However, programming via USB always times out. Using a scope I can see that the first byte from the IDE is getting all the way to the RX pin on the Atmega2560, but nothing is coming back out as a response. The Atmega2560 isn’t doing anything.

Also, importantly, pin13 does NOT toggle when the board is reset. This indicates that the bootloader is not running (I believe)

 

I looked at actual ‘good’ arduino mega board and used Nick Gammon’s ‘Atmega_Board_Detector’ sketch. Among the Fuses and bootloader there are only two things that did not match with my custom board

 

‘good’ Mega board:
Lock byte = 0xFF
Clock calibration = 0x8D

 

‘bad’ custom board:
Lock byte = 0xCF
Clock calibration = 0x82

 

From what can tell in the data sheet, the ‘clock calibration’ byte seems unrelated to bootloading.

My next step is to write the lock byte on the bad board to match the 0xFF seen on the good board. When I try to do THAT with avrdude, I keep getting a ‘failed’ message when it actually tries to write to the lock byte.

soo… Anyone have any idea how/why those two variables are causing my board to not be programmable from the IDE? I've spent days on this and I'm getting nowhere.

Last Edited: Tue. May 4, 2021 - 06:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You said "ISP". That could well mean you've accidentally erased the bootloader from the 2560.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do the chip erase using avrdude, I don't know what is the command for that, something along the lines avrdude -e .

Erasing the chip resets the fuse  lockbit's to 0xFF.

Last Edited: Tue. May 4, 2021 - 08:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heisen wrote:
Erasing the chip resets the fuse bit's to 0xFF.

No,  it does not.   The fuses are unchanged.   The LockBits are set to 0xFF

 

You say that you have copied the MEGA2560 schematic.   i.e. 16U2 + 16MHz XTAL.   2560 + 16MHz XTAL/Resonator.

 

Please quote the Fuse values.   The bootloader expects the 2560 to be running on the 16MHz XTAL.

 

I strongly advise you to connect an external Programmer to the 2560 3x2 SPI header.

Then use the Arduino IDE to select Board=Mega2560, Programmer=your_model.   "Burn Bootloader"

This will program Bootloader, Fuses and LockBits.

 

The 8MHz RC Calibration byte is not relevant when the Fuses are set for XTAL.

 

David.

Last Edited: Tue. May 4, 2021 - 08:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Erasing the chip resets the fuse bit's to 0xFF.

No,  it does not.   The fuses are unchanged.   The LockBits are set to 0xFF

Oops, I meant to say that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, I have done that already, a few times. The bootloader MD5 sum matches what I see in the good Arduino Mega I have, so the bootloader is burning correctly, and now the fuses match as well. I have multiple boards behaving this way.

 

Are there any other settings that can be different between the two boards?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kO1K7N9ZNo wrote:
Are there any other settings that can be different between the two boards?

 

If bootloader is same, all fuses and lockbits match. I don't think there is anything else left software wise.

Time to analyze hardware, maybe?

 

TX RX wiring? (TX connects to RX and RX connects to TX)

Crystal 16 MHz?

Capacitor on reset pin, like on arduino?