mega2560 factory fresh, set up, connection ok

I soldered one mega2560 (factory fresh) to a protoboard and connected it via usbbasp (using the crystal, resistors,etc.) It seems that the connection is fine, and it's detected properly by avrdude/arduino-upload via programmer. I can upload a hex file into it, and everything seems fine (other than the "warning cannot set skt period". The device signature is fine as well.

Except that the code is not working, I can realize that because I am doing a simple digitalWrite(10,HIGH) and the voltage is still 0 (it goes to 30mv when the code is uploading). (My debugger hasn't arrived)

I assume I need to set up something regarding the fuses. Any help would be most appreciated,

I just noticed that the problem seems to be that the power goes to 0 after the program finishes uploading. In particular, the voltage is 4.4v when the program uploads, but then goes to zero inmediately after the program finishes uploading (I have a cap between grd - 5v so the voltage drop takes 5secs; if I remove the cap, the drop is immediate)

With no wires connected, measure between +5 and Gnd, Do you get a really low reading, or something in the 10s of K-ohms?
If low, you may have a Vcc pin shorted to Gnd that you need to find & fix.

I get a very high resistance>200kohms

Where is the power coming from? My USB power from a PC for example doesn't drop out like that.
Did you use a Programmer and Burn a bootloader into it? That sets the fuses to use the external crystal and stuff. You may see odd results if you did not, such as seeming to run really slow.

I tried two approaches: A) using Arduino IDE and "upload via programmer"
B) uploading it via "avrdude -p m2560 -c usbasp -U flash::sketch_jun09b.hex"
C) burning the bootloader via Arduino IDE

All approaches seem to work, but the voltage stays above 4v only during the "uploading" phase, it then goes to zero immediately.

Both upload correctly (I think), I do get avrdude:1350 bytes of flash verified for (B).

I am powering it via the USBASP. Should I do something different? In fact disregarding the programming part, if I connect the USbbasp with the ATMEGA to the port I get 0v.

I am using a 16mhz crystal. I also tried burning the fuses with

"-U lfuse:w:0x77:m -U hfuse:w:0x99:m -U efuse:w:0xff:m" which I got from the avr fuse calc.

I do get the warning "cannot set skt period", but since I am using a cheap chinese usbbasp, Ive been told that was fine.

Are you sure you're measuring the VCC pin and not SCK, or MOSI? Those would also go low when programming stopped.

If yes, power the board with a 3xAA battery pack, see if that makes a difference.

Ricardito:
I tried two approaches: A) using Arduino IDE and "upload via programmer"
B) uploading it via "avrdude -p m2560 -c usbasp -U flash::sketch_jun09b.hex"

The voltage issue sounds like a separate issue but FYI:
Doing an Upload Using Programmer on ATmega2560 with the stock USBasp firmware and the standard fuse settings in the Arduino IDE the sketch will never run, see: Program doesn't run after Upload Using Programmer with USBasp (Mega2560) · Issue #246 · arduino/ArduinoCore-avr · GitHub. You will have the same problem with B with the same fuse settings. You can make Upload Using Programmer work by changing the high fuse setting to 0xD9 but you have to use 0xD8 if you want to use a bootloader. There is a new version of the USBasp firmware in development that has this issue fixed: GitHub - PeterVH/usbasp: My repo for experimenting with the usbasp firmware from www.fischl.de.

If you want to set the fuses with the Arduino IDE then you need to do a Tools > Burn Bootloader, even if you aren't going to use the bootloader because Upload Using Programmer doesn't set the fuses.

You were right (as always)! I had a miss-connected cable to the USBBASp. Now the voltage is stable 4.5V, and the program runs successfully by writing the pinmode(HIGH) as I had specified. The problem was that 5v and MISO were wrongly put in the USBAsp. I uploaded the program via usbbasp command line.

Also thanks Pert, I will look into that.

Thanks again, you saved my day