Sercom serial ports on M0

Started by nielbd, August 27, 2018, 08:08:43 AM

nielbd

Hi Guys.

I'm a bit stuck. I've been using a Moteino R6 with Neoway M590 via software serial. All was well. I the got a Moteino M0 to use. The same sketch(TinyGSM - MQTT example) adapted for the hardware serail. When the code calls a function to connect to the MQTT server, the M0 freezes up. I then read on the documentation of the TinyGSM library that SAMD21 boards should use sercom UART ports instead of hardware serial ports. I then had a look in the variant.h file for the M0 but it seems that Serial and Serial1 already are sercom ports.

Any help here will be appreciated.

Niel

Felix

Quote from: nielbd on August 27, 2018, 08:08:43 AM
The same sketch(TinyGSM - MQTT example) adapted for the hardware serail. When the code calls a function to connect to the MQTT server, the M0 freezes up
Hi Niel,
Can you expand on the above?
And how exactly does it "freeze"?

nielbd

Hi Felix

The serial monitor stops. The program also stops running. I cannot even close the serial monitor before I press reset on the board. I just tried a different mqtt library and it does the same. It freezes as soon as the mqtt.connect command runs. Very weird...
The R6 works fine withe the same sketch.

Felix

I don't know what to say, I can bet this is one of those sercom mux/configuration rabbit holes, and it was probably not done very well in the Arduino Zero core (inherited) or not at all.
Do not assume that if something runs on AVR smoothly it will just port to ARM and just work, it's a very broad assumption, sometimes it works, sometimes not.

BUT I would personally definitely recommend using hardware ports that are already defined. There is no reason not to. There are 2 serial ports available on the M0 GPIO (Serial, and Serial1) in addition to the SerialUSB. Try those before messing with sercom muxing.

mwolter

Nielbd,
If you are using the USB serial port, I'd recommend switching to a FTDI adapter and using Serial0 or Serial1. The USB serial port (SerialUSB) behaves differently than the serial ports on a typical AVR based MCU and caused me several issues.

Recommend only using SerialUSB for uploading the sketch and using Serial0 or Serial1 for serial monitor debugging and all serial communication.

Hope this helps.

kwalkerk

How would your wire the M0 to an FTDI adapter.  I can find a DTR pin on the M0.

Thanks

Felix

You do not need FTDI for the M0 for uploading. The DTR pin was only used to reset AVR Moteinos for the purpose of entering the bootloader to receive a new sketch.
For M0 that all happens through the USB.

You can use an FTDI-Adapter to connect to the other serial ports that are available (Serial and Serial1). In that use case you only need to connect 3 pins: GND, FTDI-TX to M0-RX, and FTDI-RX to M0-TX.

I hope this makes sense.