Serial1 on IND.I/O

Eventually, I need to be able to use modbus to communicate with another device. I connected everything and it didn't work, so I've been simplifying and simplifying, and I'm down to this:

I am trying to get my IND.I/O to use its Serial1 (RS-485) port. Here is my sketch:

void setup() {
  Serial1.begin(9600, SERIAL_8N2);
  pinMode(9 /*TxEnablePin*/, OUTPUT);
  digitalWrite(9 /*TxEnablePin*/, LOW);
  delay(1);
}

void loop() {
  digitalWrite(9, HIGH);
  Serial1.write(85);
  delay(200);
  digitalWrite(9, LOW);
  delay(200);
}

I put a scope on the A and B RS-485 lines. With this sketch, I see this in the scope: https://imgur.com/SztEalF.png. As far as I can tell, this is basically what the simple modbus master library does (albeit grossly simplified).

It looks like the writes to pin 9 are simply setting the serial output to high or low!? (and the other wire is negative of the main wire.) When I change the delays, the length of time high or low (depending on which delay I change) changes accordingly.

If I change the code to use the Indio library like so:

#include <Indio.h>

void setup() {
  Serial1.begin(9600, SERIAL_8N2);
  Indio.digitalMode(9 /*TxEnablePin*/, OUTPUT);
  Indio.digitalWrite(9 /*TxEnablePin*/, LOW);
  delay(1);
}

void loop() {
  Indio.digitalWrite(9, HIGH);
  Serial1.write(85);
  delay(200);
  Indio.digitalWrite(9, LOW);
  delay(200);
}

I get the following on the scope: https://imgur.com/f3iVsDn.png. So apparently digitalWrite(9, HIGH) is different from Indio.digitalWrite(9, HIGH). That's fine, at least I don't get 400 ms pulses, but I would really like to see my "85" be serialized on the line!

Please let me know what I should do next to try to troubleshoot this issue. Have I missed some configuration? Is there another test I should be running to rule out other problems? Thanks!

Aaron
Aaron
44
| 1 0 2
Asked on 7/30/20, 4:11 PM
0
vote
1272 Views

I have been reading the Indio library and I see how different `India.digitalWrite` is from `digitalWrite`! I'm starting to think I have a bad modbus chip in my IND.I/O? (max485 I think?)

Aaron
on 7/30/20, 8:03 PM

After further working on it, everything's okay in my indio board!

Aaron
on 6/14/21, 4:51 PM

Hi, the RS485 is on 'Serial', please have a look at https://github.com/Industruino/documentation/blob/master/indio.md#rs485

'Serial1' is on D10/D5, available on the 14-pin IDC expansion port.

 

Tom
Tom
5675
| 1 1 3
Answered on 7/31/20, 1:12 AM
1
vote

You're my best friend now. I thought `SerialUSB` is an alias for `Serial`. Apparently they're separate UART modules. Thank you for the pointer!

Aaron
on 7/31/20, 3:07 PM

I don't have permission to mark this as an answer, but it does solve (this part of) my problem!

Aaron
on 7/31/20, 3:08 PM

Your answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

Ask a Question

Keep Informed

About This Forum

This community is for professionals and enthusiasts of our products and services.

Read Guidelines

Question tools

62 follower(s)

Stats

Asked: 7/30/20, 4:11 PM
Seen: 1272 times
Last updated: 6/14/21, 4:51 PM