-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add: loopback() Todo: comments some part can be improved... * Add: Loopback example sketch * Docu: change for loopback() and update version * Style: format theCAN lib with Clang formatter * Fix: PWM pin defines of XMC1400 2go
- Loading branch information
1 parent
644093d
commit 86c623f
Showing
5 changed files
with
331 additions
and
200 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,61 @@ | ||
// Copyright (c) Linjing Zhang. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#include <CAN.h> | ||
using namespace ifx; | ||
|
||
void setup() { | ||
// put your setup code here, to run once: | ||
Serial.begin(9600); | ||
while (!Serial) | ||
; | ||
|
||
Serial.println("CAN Loopback"); | ||
|
||
// start the CAN bus at 500 kbps | ||
if (!CAN.begin(500E3)) { | ||
Serial.println("Starting CAN failed!"); | ||
while (1) | ||
; | ||
} | ||
|
||
// set the can in loopback mode | ||
CAN.loopback(); | ||
} | ||
|
||
void loop() { | ||
|
||
// | ||
Serial.print("Sending packet"); | ||
CAN.beginPacket(0x12); | ||
CAN.write('L'); | ||
CAN.write('O'); | ||
CAN.write('O'); | ||
CAN.write('P'); | ||
CAN.endPacket(); | ||
|
||
|
||
int packetSize = CAN.parsePacket(); | ||
|
||
if (packetSize) { | ||
// received a packet | ||
Serial.print("Received "); | ||
|
||
if (CAN.packetExtended()) { | ||
Serial.print("extended "); | ||
} | ||
|
||
Serial.print("packet with id 0x"); | ||
Serial.print(CAN.packetId(), HEX); | ||
|
||
Serial.print(" and length "); | ||
Serial.println(packetSize); | ||
|
||
while (CAN.available()) { | ||
Serial.print((char)CAN.read()); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
delay(1000); | ||
} |
Oops, something went wrong.