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

added RS485 support #6

Merged
merged 4 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions examples/RS485_fullduplex/RS485_fullduplex.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
RS485 Full duplex communication

This sketch shows how to use the SP335ECR1 on the Automation
Carrier as a full duplex RS485 interface, how to periodically
send a string on the RS485 TX channel and how to receive data
from the interface RX channel.

Circuit:
- Portenta H7
- Automation Carrier
- A Slave device with RS485 inteface


created 25 August 2020
by Silvio Navaretti
modified 24 September 2020
by Martino Facchin, Riccardo Rizzo
*/

#include "AutomationCarrier.h"

using namespace automation;

unsigned long counter = 0;

void setup() {

Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
Serial.println("Start RS485 initialization");

// Initialize the serial interface, enable the
// RS485 on SP335ECR1 and set as full duplex
comm_protocols.rs485.begin(9600);
comm_protocols.rs485.enable = 1;
comm_protocols.rs485.sel_485 = 1;
comm_protocols.rs485.half_duplex = 0;

Serial.println("Initialization done!");
}


void loop() {
// Call receive(); sets the flux control pins properly
// and allows receiving data if available
comm_protocols.rs485.receive();
if (comm_protocols.rs485.available()) {
Serial.print("read byte: ");
Serial.write(comm_protocols.rs485.read());
Serial.println();
}
// Call beginTransmission(); sets the flux control pins properly
// and allows starting a trasnsmission.
// If instead of a string, you want
// to send bytes, use the API write();
comm_protocols.rs485.beginTransmission();
comm_protocols.rs485.print("hello ");
comm_protocols.rs485.println(counter);
comm_protocols.rs485.endTransmission();
counter++;

delay(1000);
}
2 changes: 1 addition & 1 deletion src/AutomationCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "utility/Adafruit_MAX31865/Adafruit_MAX31865.h"
#include "utility/Arduino_MKRTHERM/src/MKRTHERM.h"
#include "utility/ArduinoRS485/src/ArduinoRS485.h"
#include "utility/RS485/RS485.h"
#include "utility/QEI/QEI.h"
#include "utility/ioexpander/TCA6424A.h"

Expand Down
28 changes: 0 additions & 28 deletions src/utility/ArduinoRS485/README.adoc

This file was deleted.

This file was deleted.

37 changes: 0 additions & 37 deletions src/utility/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino

This file was deleted.

38 changes: 0 additions & 38 deletions src/utility/ArduinoRS485/examples/RS485Sender/RS485Sender.ino

This file was deleted.

33 changes: 0 additions & 33 deletions src/utility/ArduinoRS485/keywords.txt

This file was deleted.

10 changes: 0 additions & 10 deletions src/utility/ArduinoRS485/library.properties

This file was deleted.

25 changes: 0 additions & 25 deletions src/utility/ArduinoRS485/src/ArduinoRS485.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the ArduinoRS485 library.
Copyright (c) 2018 Arduino SA. All rights reserved.
Copyright (c) 2020 Arduino SA.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -61,7 +61,7 @@ void RS485Class::end()
digitalWrite(_rePin, LOW);
pinMode(_dePin, INPUT);
}

if (_dePin != NC) {
digitalWrite(_dePin, LOW);
pinMode(_rePin, INPUT);
Expand Down
19 changes: 2 additions & 17 deletions src/utility/ArduinoRS485/src/RS485.h → src/utility/RS485/RS485.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
This file is part of the ArduinoRS485 library.
Copyright (c) 2018 Arduino SA. All rights reserved.
Copyright (c) 2020 Arduino SA.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -20,24 +20,9 @@
#ifndef _RS485_H_INCLUDED
#define _RS485_H_INCLUDED

#include <Arduino.h>

#include "Arduino.h"
#include "mbed.h"

#ifdef PIN_SERIAL1_TX
#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX
#else
#define RS485_DEFAULT_TX_PIN 1
#endif

#ifdef __AVR__
#define RS485_DEFAULT_DE_PIN 2
#define RS485_DEFAULT_RE_PIN -1
#else
#define RS485_DEFAULT_DE_PIN A6
#define RS485_DEFAULT_RE_PIN A5
#endif

class RS485Class : public Stream {
public:
RS485Class(HardwareSerial& hwSerial, PinName txPin = NC, PinName dePin = NC, PinName rePin = NC);
Expand Down