PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2KB

  1. #include <FlexCAN_T4.h>
  2. FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can1;
  3. FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> can2;
  4. CAN_message_t msg;
  5. void setup(void) {
  6. can1.begin();
  7. can1.setBaudRate(250000);
  8. can2.begin();
  9. can2.setBaudRate(250000);
  10. }
  11. void loop() {
  12. if ( can1.read(msg) ) {
  13. Serial.print("CAN1 ");
  14. Serial.print("MB: "); Serial.print(msg.mb);
  15. Serial.print(" ID: 0x"); Serial.print(msg.id, HEX );
  16. Serial.print(" EXT: "); Serial.print(msg.flags.extended );
  17. Serial.print(" LEN: "); Serial.print(msg.len);
  18. Serial.print(" DATA: ");
  19. for ( uint8_t i = 0; i < 8; i++ ) {
  20. Serial.print(msg.buf[i]); Serial.print(" ");
  21. }
  22. Serial.print(" TS: "); Serial.println(msg.timestamp);
  23. }
  24. else if ( can2.read(msg) ) {
  25. Serial.print("CAN2 ");
  26. Serial.print("MB: "); Serial.print(msg.mb);
  27. Serial.print(" ID: 0x"); Serial.print(msg.id, HEX );
  28. Serial.print(" EXT: "); Serial.print(msg.flags.extended );
  29. Serial.print(" LEN: "); Serial.print(msg.len);
  30. Serial.print(" DATA: ");
  31. for ( uint8_t i = 0; i < 8; i++ ) {
  32. Serial.print(msg.buf[i]); Serial.print(" ");
  33. }
  34. Serial.print(" TS: "); Serial.println(msg.timestamp);
  35. }
  36. }