115200 Baud Serial1 to Serial Passthrough on ATmega2560V

Hello!

My application uses an ATmega2560V talking to a uBlox cellular modem (LARA-R6 series) via UART. Specifically, it's a rotary cell phone. If you're wondering which rotary cell phone, yes, it's the main one that pops up on Google.

Previously I was using an older cell modem series from that manufacturer (the TOBY-R2 series) that did autobauding. These modems take Hayes (AT) commands, and I expose the messages going between the cell modem and the 2560V to a serial console using Erik Nyquist's serial passthrough function. Naturally this is absolutely necessary for debugging:

void serialPassthrough(){
	if (Serial.available()) {     //Pass anything entered in Serial off to the cell modem
		Serial1.write(Serial.read());   
	}
	if (Serial1.available()) {     // Pass anything received from the cell modem to the serial console
		Serial.write(Serial1.read()); 
	}
}

I couldn't communicate in anything but garbled text with the previous (TOBY) modem at 115200, but found that 57600 worked well and the TOBY's one-shot autobauding picked it right up.

The TOBY series reached EOL and I just switched to the uBlox LARA-R6 series. Mindbogglingly to me, the LARA-R6 slowest supported baud rate is 115,200, and it doesn't have auto baud rate detection. So now I find myself in the same bad situation, with only having garbled text to work with in my serial monitor with Serial1 running at 115200.

Communication directly from the 2560V to the uBlox LARA seems reliable, as I at least know I can send the power-down AT command and have it power down, and one or two other commands produce an expected result, but I can't see any messages the LARA sends back or echoes on Serial.

The 2560V is running at 8MHz, but even at that speed, the datasheet shows that 115200 should be just fine. To be honest, I can't even really imagine a software solution here, but I suppose I'm grasping at straws. The thing that gets to me is, again, that communication to/from the LARA directly from the 2560V seems consistent, but that I'm unable to expose this to my PC serial monitor. I could connect a logic analyzer, but it's an untenable permanent solution.

FWIW, the UART lines from Serial1 to the LARA have to logic shift to 1.8V, which is done via a TXB0108. For the USB bridge off Serial, I'm using an ATmega16U2.

Things I tried:

  • Ran Serial (not Serial1) at various baud rates to see if that was bottlenecking the flow somehow. Behavior seems unchanged whether Serial is at 9600, 115200, or 256000.
  • Tried sticking chars received from Serial1 in a buffer and printing them to Serial well after the communication. I think I messed this up somehow because it generally just comes out blank (note to self: re-try this after posting this).
  • If I type into the serial console to send AT commands manually, the length of the garbled text responses looks consistent with what I'd expect for the commands I'm sending.
  • The garbled text is generally consistent. Like, I'm pretty sure ?j5 means "OK". Haha? Uff.

I'm somewhat convinced that the issue is in how the serial passthrough function handles things, despite trying to run both Serial and Serial1 at 115200.

Schematics/layout available, but it seems to me not to be a layout problem.

Any advice?

~Justine

The 2560V is running at 8MHz

but garbled text with the previous (TOBY) modem at 115200, but found that 57600 worked well

The 2560 clock speed may be your issue. It sounds like you can use 57600 with the LARA-6. Can you set the baud rate of the 2560 to 230400?

Can you run the Mega at 16MHz to test the communication with the modem?

I was afraid to do that as I didn't want to risk losing communication entirely (the baud rate setting gets saved to NVM on the LARA), but just tried it. Indeed, I successfully increased the baud rate to 230400, but the 2560V is totally unresponsive at that speed so I can't even change it back. I'll either populate another board or figure out more direct access to switch it back. In any case, I'm pulling my hair out.

Tempted to drop in an ATmega1280 and run it at 16MHz to see if that makes a difference. Going to the non-low-voltage variant of the 2560 would be a harder pill to swallow as it's powered by a LiPo,

What core are you using with this chips?

MegaCore

AHH! 57600 is the highest MegaCore goes with an 8Mhz crystal! Thank you!

It's heartening to have a reason for the failure, but now I need to decide how to move forward. The 1280 may still be the way to go. Unless you, or anyone, knows of a way I could run the 8MHz 2560V and still get 115200 baud.

Then don't use MegaCore?

Eh the standard core doesn't work with the V-variant of the 2560. I'm looking at editing the upload speed in boards.txt to get around it.

The 57.6K is not just a limit from the core being used. Look at the data sheet for the 2560 and the error rates for baud rates at 8MHz.
Table 22-11 in the version of the data sheet I have.

You can also see a calculator here which shows the same thing.

There are two sweet spots above 57.6 at 250K and 500K so you might try those if you can work around the core restrictions on baud rate.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.