MKR Zero + Eth + RS485 shield: RS232 connection and diff. bauds possible?

Hey guys,

I've just ordered a MKR zero + MKR Eth Shield + MKR RS485 shield as I want to implement an ModBus TCP to ModbBus RTU gateway.

I have two main questions at the moment though:

  • Can I use in addition to RS485 + Eth (ModBus TCP) the RS232? Or are the pins/connection blocken by RS485?

  • Can (or should) I connect to my RTU slaves via different baud rates? I have to do this as I have 3 slaves on my RTU bus but each of them support only one baud rate which are not the same...

Thanks heaps in advance!
Soko

Can I use in addition to RS485 + Eth (ModBus TCP) the RS232? Or are the pins/connection blocken by RS485?

Your hardware combo doesn't have an RS232 interface. If you mean just a standard UART interface, the M0 can have almost every pin made available as a hardware serial interface.

Can (or should) I connect to my RTU slaves via different baud rates? I have to do this as I have 3 slaves on my RTU bus but each of them support only one baud rate which are not the same...

No, you cannot. Every device on one Modbus must have the same baudrate configured otherwise it won't recognize it's own traffic and get confused by the misaligned traffic for the other devices.

Hello Pylon (does your name come from PylonTech :wink: ) and thanks for the reply and helping a newbie out here thumbup

ad RS232:

I've got to the same conclusion just a view hours ago: I need a third shield (RS232).
Sounds simple but it turns out it isnt :frowning:
I need a shield which takes 3.3V signals (TTL). All I've found so far are for the Uno and therefore 5V. Most of them use the MAX232 chip...

Do you know any working RS232 Shield for the M0?

ad ModbusRTU diff. baud rates:

I've found this interesting discussion about this topic: https://modbus.control.com/thread/1446116644
It turns out it might work!
All I have to do is to change the baud-rate every time I change the slave I'm talking to. This should be a problem with the Arduino (or should it).
Important: Speed is not an issue for me. I will ask each slave for a couple a registers every 5 seconds.

What do you think?

thx heaps!
Soko

I've got to the same conclusion just a view hours ago: I need a third shield (RS232).

What do you need RS232 for in your project?

It turns out it might work!

It might work in some cases but such a system will never be reliable. There are many reasons why this system may fail. Inter-message pause time depends on the baud rate to name just one. Sure the slave will ignore traffic not recognized as it's own traffic but if it doesn't detect the start of a message correctly it may also ignore traffic targeted to itself. As I wrote, many ways to produce race conditions.

If you can live with a system where some slaves won't communicate for a few minutes, you can try that setup. Otherwise I suggest to use one bus per baud rate/parity setting.

I have 3 devices/slaves I need to communicate with:

  • 1 real ModBus device with 9600/8/N/1
  • 1 proprietary RS485 device with is kinda ModBus but uses its own CeckSum algorithm: 56000/8/N/1
  • 1 RS232 device: 1200/8/N/1

The Arduino should talk to all three, logging the data its collects to an SD card and also be a ModBusTCP server for external devices in the LAN.

What I've figured out so far:

  • I pop both shields on the the M0
  • I use the Serial1 (UART) for the RS485
  • I use SoftwareSerial on other pins for RS232 as its the slowest

What is missing:

  • How to get RS232 with the M0
  • Do I have to cut of pins or something similar to get no conflict between the SD-Card slot in the M0 and the ETH shield?

Everything else should be a piece of cake :slight_smile:

thx
Soko

I use SoftwareSerial on other pins for RS232 as its the slowest

Don't use SoftwareSerial, it's crippled by design. The M0 can have many hardware serial interfaces.

How to get RS232 with the M0

How is your system powered? The MAX232 needs 5V as it's power supply but accepts 2V as a HIGH level on it's inputs. The outputs can be leveled by a voltage divider.

Do I have to cut of pins or something similar to get no conflict between the SD-Card slot in the M0 and the ETH shield?

It doesn't look like that, I cannot find any pin conflicts. On the ETH shield you have an additional SD card reader if necessary which doesn't conflicts for sure.

pylon:
Don't use SoftwareSerial, it's crippled by design. The M0 can have many hardware serial interfaces.

Hmm... than I didn't understand the difference between SW- and HW-Serial. Arduino - Compare says it only has one UART on Pin 13+14 which is used by https://www.arduino.cc/en/Guide/MKR485Shield.
So how can I do more than one HW-Serial without a 2nd UART?

pylon:
How is your system powered? The MAX232 needs 5V as it's power supply but accepts 2V as a HIGH level on it's inputs. The outputs can be leveled by a voltage divider.

I will power the boards with an 5V power supply on the Vin Pins.

pylon:
It doesn't look like that, I cannot find any pin conflicts. On the ETH shield you have an additional SD card reader if necessary which doesn't conflicts for sure.

https://www.arduino.cc/en/Guide/MKRETHShield: It says "It is obvious that any MKR board that has an SD slot on board may conflict with the one on this shield."
Thats why I thought I have to cut PIN4.

Hmm… than I didn’t understand the difference between SW- and HW-Serial. Arduino - Compare says it only has one UART on Pin 13+14 which is used by https://www.arduino.cc/en/Guide/MKR485Shield.
So how can I do more than one HW-Serial without a 2nd UART?

The Arduino IDE libraries define only one hardware serial for that variant but the processor may have several of them. The processor datasheet gives you details about that. It’s not very intuitive to define an additional serial interface but once you got that one cryptic line of code you can use the second serial as the first one.

I will power the boards with an 5V power supply on the Vin Pins.

So you have the 5V you need for the MAX232. Connect the MAX’s input directly to the MKR Zero’s TX pin and the output to the RX pin by a voltage divider (p.e. 2k2/3k3Ω).

https://www.arduino.cc/en/Guide/MKRETHShield: It says “It is obvious that any MKR board that has an SD slot on board may conflict with the one on this shield.”

The SD card of the MKR Zero is connected (according to the schematics) to pin PA14 while the interface of the Ethernet Shield is connected to PB10. I don’t see a conflict.

HW-Serial:
I found the datasheet (hopefully the correct one) here: https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/Atmel-42181-SAM-D21_Datasheet.pdf
It seems there are up to 6 serial communication interfaces.
But everything else is way over my head. Im not able to read this document to find out the pins of the processor of the 6 serial interfaces...

RS232:
Reading between the lines I may have already fried my M0. So when I power the board with 5V, which is the only possibility bdw, the RS232 shield (MAX232) gets also powered with that voltage and therefore uses 5V for an output. Getting 5V to the Rx-pin of my 3.3V processor is no good idea...

SDcard:
So that means I could use both slots?

I should get the hardware by beginning next week and start to tinker immiately :slight_smile:

sokofromnz:
So how can I do more than one HW-Serial without a 2nd UART?

This tutorial should be helpful:

sokofromnz:
etting 5V to the Rx-pin of my 3.3V processor is no good idea...

Correct.

pert:
This tutorial should be helpful:
https://www.arduino.cc/en/Tutorial/SamdSercom

Wow, thats perfect! Thx!

pert:
Correct.

I found the datasheet of the MAX232 (https://datasheets.maximintegrated.com/en/ds/MAX220-MAX249.pdf) but I’m not able to read it probperly :confused:

Where does it say it takes 3.3V signals as High when using 5V as VCC.

It says it takes -0.3 to 6.0V as VCC.
Would it even work without a voltage divider if I power a standard RS232 Arduino Shield (which uses a MAX232) with 3.3V instead of 5V?

thx heaps guys!

sokofromnz:
Wow, thats perfect! Thx!

You’re welcome.

sokofromnz:
Where does it say it takes 3.3V signals as High when using 5V as VCC.

In the table “Electrical Characteristics—MAX220/222/232A/233A/242/243”:

PARAMETER | MIN TYP MAX | UNITS

Input Logic-High Voltage | 2 1.4 | V

Now I don’t understand why the TYP (typical) value is lower than MIN (minimum). I would expect TYP to be greater than MIN. Maybe it’s a typo?

Regardless, you know that 3.3 V is greater than the minimum value for a HIGH logic signal.

sokofromnz:
It says it takes -0.3 to 6.0V as VCC.

No, it says those are the “Absolute Maximum Ratings”. That just tells you that anything outside those values will damage the chip. It doesn’t mean that the chip will run correctly anywhere within the maximum ratings. If you want to know the Vcc voltages that will allow the chip to run correctly, you need to look at the “Supply Voltage Range” in the “Electrical Characteristics—MAX220/222/232A/233A/242/243” table, which says the minimum is 4.5 V and the maximum is 5.5 V.

OK, so you look at the "RS232-Transmitter" section. Wasn't sure there as there is a "Receiver" section as well with different voltages for input-logic-high-voltage.
Got it with the VCC, thx.

Applying what I've just learned I looked at the datasheet of the MAX3232 (https://datasheets.maximintegrated.com/en/ds/MAX3222-MAX3241.pdf):
This one operates with 3.3V VCC as well:
Page 6 (PIN descriptions) says "+3.0V to +5.5V Supply Voltage"

So iiiifffff:

everything should work sweet as strawberries as I have a fully functional ETH, RS485 and RS232 Shield :smiley: :smiley:

I've already found a "shield" with MAX3232 (and ordered it): MAX3232 RS232 Serial Port to TTL Converter Module DB9

I just did go through https://www.arduino.cc/en/Tutorial/SamdSercom again. I quite don't understand what is is doing but comparing the variant.cpp of the MKR1000 and my MKRZero it shows that the sections are the same.
So I reckon I can fully copy the example code :slight_smile:
The only thing in the two examples (Wire and Serial) is the "// Attach the interrupt handler to the SERCOM" section. The Serial is missing the "extern "C" {..." part. Wondering if this is a typo/error...

thx
Soko