Arduino Forum

Using Arduino => Programming Questions => Topic started by: Softfoot on Dec 16, 2018, 01:24 pm

Title: Problem with serial output ...
Post by: Softfoot on Dec 16, 2018, 01:24 pm
I need to be able to program my Mega2560 via a USBasp because I need to disconnect the CH340 USB device tio save power in a battery application.

My code works correctly if programmed via the USB port and I then see serial output at 115200 baud.

Replacing the USB connection with a TTY<->USB adapter also works correctly on TX0/RX0.

However, if I program the device via the ISP port with an USBasp the code appears to be running (bus and pin activity seems OK) but I get no serial output on TX0/RX0 !!

In programming it this way I have of course trashed the bootloader - is some init of the serial port done in the bootloader that I need to add to my setup code ???

At present I just have "Serial.begin(115200);"

Reburning the bootloader, I can then program via the USB port as normal.

What am I missing ?

Confused,
Dave
Title: Re: Problem with serial output ...
Post by: sterretje on Dec 16, 2018, 01:43 pm
The Serial.begin() should be sufficient if you don't have a bootloader. You haven't, by accident, (re)connected the TTL-to-USB incorrectly (e.g. RX and TX swapped)?

Other option might be that you might have set the fuses incorrectly and the baudrate is now incorrect.
Title: Re: Problem with serial output ...
Post by: Softfoot on Dec 20, 2018, 12:57 pm
Hmmm ... It doesnt even output over USB - so its not a pin swap issue.

It would appear that my comment about the code running was rubbish ... it isnt.

If I put "blinky" on the board via USB+bootloader it is OK.
But if I program it via my USBasp it doesnt run :-(

I have used the USBASP to load standalone code before so I know the USPASP is OK - and it programs without error.

The USBASP is clearly working as it is able to restore the bootloader.

What am I missing ??

Is there some secret tweak (init code/fuse setting/library) needed to load a standard sketch via a programmer ?

I am in the process of setting up my Atmel-ICE to try that as a programmer - I'll add the results later, but I suspect the outcome will be the same.

Baffled
Dave
Title: Re: Problem with serial output ...
Post by: Softfoot on Dec 20, 2018, 04:52 pm

OK after a bit more testing :-

On an UNO I can upload "blinky" via BOTH the USB port an the USBasp and it runns correctly.

But on 2 different Mega2560s I can only upload "blinky" via the USB port --- via the USBasp it appears to complete OK but it will NOT run.

In all cases the USBasp is able to restore the boot loader.

I did try the ATMEL-ICE but it needs the "auto-reset" being disabled - and I am loathe to do that at this stage.

PLEASE - someone must have hit this before ...
Dave
Title: Re: Problem with serial output ...
Post by: Softfoot on Dec 20, 2018, 07:28 pm

... they did - just a question of finding the blighter!!

http://forum.arduino.cc/index.php?topic=126160.msg1839526#msg1839526 (http://forum.arduino.cc/index.php?topic=126160.msg1839526#msg1839526)

It seems that the Mega2560 needs the BOOTRST fuse set to 1 (it would appear that the UNO doesnt).

I hope this helps someone else.

To me this should be documented in the arduino suite somewhere.

Regards,
Dave (Phew!!)