Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 275b47e

Browse files
authored
added RS485 support (#6)
added RS485 support renaming and changes for RS485 library to support mbed
1 parent bbc999d commit 275b47e

File tree

11 files changed

+71
-236
lines changed

11 files changed

+71
-236
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
RS485 Full duplex communication
3+
4+
This sketch shows how to use the SP335ECR1 on the Automation
5+
Carrier as a full duplex RS485 interface, how to periodically
6+
send a string on the RS485 TX channel and how to receive data
7+
from the interface RX channel.
8+
9+
Circuit:
10+
- Portenta H7
11+
- Automation Carrier
12+
- A Slave device with RS485 inteface
13+
14+
15+
created 25 August 2020
16+
by Silvio Navaretti
17+
modified 24 September 2020
18+
by Martino Facchin, Riccardo Rizzo
19+
*/
20+
21+
#include "AutomationCarrier.h"
22+
23+
using namespace automation;
24+
25+
unsigned long counter = 0;
26+
27+
void setup() {
28+
29+
Serial.begin(9600);
30+
while (!Serial) {
31+
; // wait for serial port to connect.
32+
}
33+
Serial.println("Start RS485 initialization");
34+
35+
// Initialize the serial interface, enable the
36+
// RS485 on SP335ECR1 and set as full duplex
37+
comm_protocols.rs485.begin(9600);
38+
comm_protocols.rs485.enable = 1;
39+
comm_protocols.rs485.sel_485 = 1;
40+
comm_protocols.rs485.half_duplex = 0;
41+
42+
Serial.println("Initialization done!");
43+
}
44+
45+
46+
void loop() {
47+
// Call receive(); sets the flux control pins properly
48+
// and allows receiving data if available
49+
comm_protocols.rs485.receive();
50+
if (comm_protocols.rs485.available()) {
51+
Serial.print("read byte: ");
52+
Serial.write(comm_protocols.rs485.read());
53+
Serial.println();
54+
}
55+
// Call beginTransmission(); sets the flux control pins properly
56+
// and allows starting a trasnsmission.
57+
// If instead of a string, you want
58+
// to send bytes, use the API write();
59+
comm_protocols.rs485.beginTransmission();
60+
comm_protocols.rs485.print("hello ");
61+
comm_protocols.rs485.println(counter);
62+
comm_protocols.rs485.endTransmission();
63+
counter++;
64+
65+
delay(1000);
66+
}

src/AutomationCarrier.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "utility/Adafruit_MAX31865/Adafruit_MAX31865.h"
55
#include "utility/Arduino_MKRTHERM/src/MKRTHERM.h"
6-
#include "utility/ArduinoRS485/src/ArduinoRS485.h"
6+
#include "utility/RS485/RS485.h"
77
#include "utility/QEI/QEI.h"
88
#include "utility/ioexpander/TCA6424A.h"
99

src/utility/ArduinoRS485/README.adoc

-28
This file was deleted.

src/utility/ArduinoRS485/examples/RS485Passthrough/RS485Passthrough.ino

-45
This file was deleted.

src/utility/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino

-37
This file was deleted.

src/utility/ArduinoRS485/examples/RS485Sender/RS485Sender.ino

-38
This file was deleted.

src/utility/ArduinoRS485/keywords.txt

-33
This file was deleted.

src/utility/ArduinoRS485/library.properties

-10
This file was deleted.

src/utility/ArduinoRS485/src/ArduinoRS485.h

-25
This file was deleted.

src/utility/ArduinoRS485/src/RS485.cpp renamed to src/utility/RS485/RS485.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the ArduinoRS485 library.
3-
Copyright (c) 2018 Arduino SA. All rights reserved.
3+
Copyright (c) 2020 Arduino SA.
44
55
This library is free software; you can redistribute it and/or
66
modify it under the terms of the GNU Lesser General Public
@@ -61,7 +61,7 @@ void RS485Class::end()
6161
digitalWrite(_rePin, LOW);
6262
pinMode(_dePin, INPUT);
6363
}
64-
64+
6565
if (_dePin != NC) {
6666
digitalWrite(_dePin, LOW);
6767
pinMode(_rePin, INPUT);

src/utility/ArduinoRS485/src/RS485.h renamed to src/utility/RS485/RS485.h

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of the ArduinoRS485 library.
3-
Copyright (c) 2018 Arduino SA. All rights reserved.
3+
Copyright (c) 2020 Arduino SA.
44
55
This library is free software; you can redistribute it and/or
66
modify it under the terms of the GNU Lesser General Public
@@ -20,24 +20,9 @@
2020
#ifndef _RS485_H_INCLUDED
2121
#define _RS485_H_INCLUDED
2222

23-
#include <Arduino.h>
24-
23+
#include "Arduino.h"
2524
#include "mbed.h"
2625

27-
#ifdef PIN_SERIAL1_TX
28-
#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX
29-
#else
30-
#define RS485_DEFAULT_TX_PIN 1
31-
#endif
32-
33-
#ifdef __AVR__
34-
#define RS485_DEFAULT_DE_PIN 2
35-
#define RS485_DEFAULT_RE_PIN -1
36-
#else
37-
#define RS485_DEFAULT_DE_PIN A6
38-
#define RS485_DEFAULT_RE_PIN A5
39-
#endif
40-
4126
class RS485Class : public Stream {
4227
public:
4328
RS485Class(HardwareSerial& hwSerial, PinName txPin = NC, PinName dePin = NC, PinName rePin = NC);

0 commit comments

Comments
 (0)