This repository was archived by the owner on Feb 28, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork29
Refactor RS485 support#58
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions.github/workflows/compile-examples.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
46 changes: 30 additions & 16 deletionsexamples/RS485_fullduplex/RS485_fullduplex.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletionsexamples/RS485_halfduplex/RS485_halfduplex.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
RS485 Half Duplex communication | ||
This sketch shows how to use the SP335ECR1 on the Machine | ||
Control as a half duplex (AB) 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 | ||
- Machine Control | ||
- A Slave device with RS485 interface | ||
- Connect TXP to A(+) and TXN to B(-) | ||
*/ | ||
#include "Arduino_MachineControl.h" | ||
using namespace machinecontrol; | ||
constexpr unsigned long sendInterval { 1000 }; | ||
unsigned long sendNow { 0 }; | ||
unsigned long counter { 0 }; | ||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
// Wait for Serial or start after 2.5s | ||
for (auto const timeout = millis() + 2500; !Serial && timeout < millis(); delay(500)) | ||
; | ||
delay(2500); | ||
Serial.println("Start RS485 initialization"); | ||
// Set the PMC Communication Protocols to default config | ||
comm_protocols.init(); | ||
// RS485/RS232 default config is: | ||
// - RS485 mode | ||
// - Half Duplex | ||
// - No A/B and Y/Z 120 Ohm termination enabled | ||
// Enable the RS485/RS232 system | ||
comm_protocols.rs485Enable(true); | ||
// Specify baudrate, and preamble and postamble times for RS485 communication | ||
comm_protocols.rs485.begin(115200, 0, 500); | ||
// Start in receive mode | ||
comm_protocols.rs485.receive(); | ||
Serial.println("Initialization done!"); | ||
} | ||
void loop() | ||
{ | ||
if (comm_protocols.rs485.available()) | ||
Serial.write(comm_protocols.rs485.read()); | ||
if (millis() > sendNow) { | ||
// Disable receive mode before transmission | ||
comm_protocols.rs485.noReceive(); | ||
comm_protocols.rs485.beginTransmission(); | ||
comm_protocols.rs485.print("hello "); | ||
comm_protocols.rs485.println(counter++); | ||
comm_protocols.rs485.endTransmission(); | ||
// Re-enable receive mode after transmission | ||
comm_protocols.rs485.receive(); | ||
sendNow = millis() + sendInterval; | ||
} | ||
} |
1 change: 1 addition & 0 deletionslibrary.properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
38 changes: 30 additions & 8 deletionssrc/Arduino_MachineControl.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.