Permalink
Browse files

Added RS485 tx enable pin handling

  • Loading branch information...
gioblu committed Sep 21, 2016
1 parent d029bf9 commit 71e59a0218dd253584c7a26e735930f56ea8c698
Showing with 25 additions and 1 deletion.
  1. +6 −1 strategies/ThroughSerial/README.md
  2. +19 −0 strategies/ThroughSerial/ThroughSerial.h
@@ -2,7 +2,7 @@
**Medium:** Hardware/Software Serial port |
**Pins used:** 1 or 2
With ThroughSerial data link layer strategy, PJON can run through a software emulated or hardware Serial port.
With ThroughSerial data link layer strategy, PJON can run through a software emulated or hardware Serial port. Thanks to this choice it is possible to leverage of virtually all the arduino compatible serial transceivers, like RS485, radio or infrared modules, still communicating with PJON.
####Why PJON over Serial?
Serial communication is an hardware integrated or software emulated data communication that can reach very fast communication speed but it includes only the data link layer; adding PJON on top of the Serial data link layer it is possible to leverage of the PJON protocol layer features like acknowledge, addressing, multiplexing, packet handling, 8-bit CRC and traffic control.
@@ -19,4 +19,9 @@ Call the `begin` method on the `Serial` or `SoftwareSerial` object you want to
bus.strategy.set_serial(&Serial);
}
```
For a simple use with RS485 serial modules a transmission enable pin setter has been added:
```cpp
bus.set_enable_RS485_pin(11);
```
All the other necessary information is present in the general [Documentation](https://github.com/gioblu/PJON/wiki/Documentation).
@@ -6,6 +6,7 @@
- Fred Larsen, Development, testing and debugging
- Zbigniew Zasieczny, collision avoidance multi-drop RS485 (latency)
and SoftwareSerial compatibility
- Franketto (Arduino forum user) RS485 TX enable pin compatibility
____________________________________________________________________________
ThroughSerial, Copyright (c) 2016 by Giovanni Blu Mitolo All rights reserved.
@@ -74,17 +75,29 @@ class ThroughSerial {
/* Send byte response to the packet's transmitter */
void send_response(uint8_t response) {
if(_enable_RS485_pin != NOT_ASSIGNED)
digitalWriteFast(_enable_RS485_pin, HIGH);
send_byte(response);
serial->flush();
if(_enable_RS485_pin != NOT_ASSIGNED)
digitalWriteFast(_enable_RS485_pin, LOW);
};
/* Send a string: */
void send_string(uint8_t *string, uint8_t length) {
if(_enable_RS485_pin != NOT_ASSIGNED)
digitalWriteFast(_enable_RS485_pin, HIGH);
for(uint8_t b = 0; b < length; b++)
send_byte(string[b]);
serial->flush();
if(_enable_RS485_pin != NOT_ASSIGNED)
digitalWriteFast(_enable_RS485_pin, LOW);
};
@@ -98,6 +111,12 @@ class ThroughSerial {
serial = serial_port;
};
void set_enable_RS485_pin(uint8_t pin) {
_enable_RS485_pin = pin;
pinModeFast(_enable_RS485_pin, OUTPUT);
};
private:
uint32_t _last_reception_time;
uint8_t _enable_RS485_pin = NOT_ASSIGNED;
};

0 comments on commit 71e59a0

Please sign in to comment.