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

Commit c9f3652

Browse files
authored
fixed Digital_out example and added CAN Examples
Fixed digital out example and added CAN read and write Examples
1 parent b271e98 commit c9f3652

File tree

12 files changed

+120
-547
lines changed

12 files changed

+120
-547
lines changed

examples/CAN/ReadCan/ReadCan.ino

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
CAN Read Example
3+
4+
This sketch shows how to use the CAN transceiver on the Machine
5+
Control and how to receive data from the RX CAN channel.
6+
7+
Circuit:
8+
- Portenta H7
9+
- Automation Carrier
10+
11+
12+
created 25 August 2020
13+
by Silvio Navaretti
14+
modified 4 November 2020
15+
by Riccardo Rizzo
16+
*/
17+
#include <AutomationCarrier.h>
18+
#include <CAN.h>
19+
20+
using namespace automation;
21+
22+
#define DATARATE_2MB 260000
23+
#define DATARATE_1_5MB 206000
24+
#define DATARATE_1MB 125000
25+
#define DATARATE_800KB 100000
26+
27+
28+
void setup() {
29+
Serial.begin(9600);
30+
while (!Serial) {
31+
; // wait for serial port to connect.
32+
}
33+
34+
Serial.println("Start CAN initialization");
35+
comm_protocols.enableCAN();
36+
comm_protocols.can.frequency(DATARATE_800KB);
37+
Serial.println("Initialization done");
38+
}
39+
40+
41+
void loop() {
42+
mbed::CANMessage msg;
43+
if (comm_protocols.can.read(msg)) {
44+
45+
// Print the sender ID
46+
Serial.print("ID: ");
47+
Serial.println(msg.id);
48+
49+
// Print the first Payload Byte
50+
Serial.print("Message received:");
51+
Serial.println(msg.data[0], DEC);
52+
53+
}
54+
55+
delay(100);
56+
}

examples/CAN/WriteCan/WriteCan.ino

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
CAN Write Example
3+
4+
This sketch shows how to use the CAN transceiver on the Machine
5+
Control and how to transmit data from the TX CAN channel.
6+
7+
Circuit:
8+
- Portenta H7
9+
- Automation Carrier
10+
11+
12+
created 25 August 2020
13+
by Silvio Navaretti
14+
modified 4 November 2020
15+
by Riccardo Rizzo
16+
*/
17+
#include <AutomationCarrier.h>
18+
#include <CAN.h>
19+
using namespace automation;
20+
21+
#define DATARATE_2MB 260000
22+
#define DATARATE_1_5MB 206000
23+
#define DATARATE_1MB 125000
24+
#define DATARATE_800KB 100000
25+
26+
27+
void setup() {
28+
Serial.begin(9600);
29+
while (!Serial) {
30+
; // wait for serial port to connect.
31+
}
32+
33+
Serial.println("Start CAN initialization");
34+
comm_protocols.enableCAN();
35+
comm_protocols.can.frequency(DATARATE_800KB);
36+
Serial.println("Initialization done");
37+
}
38+
39+
int counter = 0;
40+
unsigned char payload = 0x49;
41+
int payload_size = 1;
42+
43+
void loop() {
44+
45+
mbed::CANMessage msg = mbed::CANMessage(13ul, &payload, payload_size);
46+
if (comm_protocols.can.write(msg)) {
47+
Serial.println("Message sent");
48+
}
49+
50+
delay(100);
51+
}

examples/Digital_output/Digital_output.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void setup() {
4343
while (!Serial);
4444

4545
//Set over current behavior of all channels to latch mode:
46-
programmable_digital_io.setLatch();
46+
digital_programmables.setLatch();
4747
//Set over current behavior of all channels to auto retry mode:
48-
programmable_digital_io.setRetry();
48+
digital_programmables.setRetry();
4949

5050
//At startup set all channels to OPEN
5151
digital_outputs.setAll(0);

0 commit comments

Comments
 (0)