element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
On the Line
  • Challenges & Projects
  • Design Challenges
  • On the Line
  • More
  • Cancel
On the Line
Forum Smart Ventilation Motor Monitoring System #5 Getting Started with CAN Protocol on XMC4200 Platform2GO in Arduino
  • News
  • Projects
  • Forum
  • DC
  • Leaderboard
  • Files
  • Members
  • More
  • Cancel
  • New
Join On the Line to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 1 reply
  • Subscribers 38 subscribers
  • Views 91 views
  • Users 0 members are here
Related

Smart Ventilation Motor Monitoring System #5 Getting Started with CAN Protocol on XMC4200 Platform2GO in Arduino

fyaocn
fyaocn 1 month ago

1 Getting start with CAN

For test CAN in the other end, XMC4200 platform2go is used

CAN (Controller Area Network) is for industrial and automotive embedded communication. It’s a robust, multi-master serial protocol designed for reliable real-time data exchange between microcontrollers, sensors, and actuators—even in electrically noisy environments. Infineon XMC4200 Platform2GO with the Arduino IDE can give a quick glance.

image

2 CAN in a glance

CAN was developed by Bosch in the 1980s for automotive applications, but it’s now used widely in industrial automation, robotics, and aerospace. Key features,
No single “master” device; any node can send data when the bus is free.
Error resilience: Built-in error checking, arbitration, and retransmission to ensure data integrity.
Two message formats: Standard CAN (11-bit ID): Shorter, faster identifiers for simple systems and Extended CAN (29-bit ID): Longer identifiers for complex networks with many nodes.
Flexible data length: Classic CAN supports up to 8 bytes of data per packet; newer CAN FD extends this to 64 bytes.
For the XMC4200, the on-chip CAN peripheral is fully supported by Infineon’s Arduino core, making it easy to prototype CAN applications without low-level register programming.
image
CANH and CANL are two wires for communication on 12V or 24V bus.

3 USING ARDUINO IDE

Using Arduino is quick start for can
image

#include <CAN.h>
void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("CAN Sender");

  // start the CAN bus at 500 kbps
  if (!CAN.begin(500E3)) {
    Serial.println("Starting CAN failed!");
    while (1);
  }
}

void loop() {
  // send packet: id is 11 bits, packet can contain up to 8 bytes of data
  Serial.print("Sending packet ... ");

  CAN.beginPacket(0x12);
  CAN.write('h');
  CAN.write('e');
  CAN.write('l');
  CAN.write('l');
  CAN.write('o');
  CAN.endPacket();
  Serial.println("done");
  delay(1000);
  CAN.beginExtendedPacket(0xFFF);
  CAN.write('w');
  CAN.write('o');
  CAN.write('r');
  CAN.write('l');
  CAN.write('d');
  CAN.endPacket();

  Serial.println("done");

  delay(1000);
}

The code is simple , put loop code in the the CAN bus 

  • serial.begin(9600): Initializes the UART serial port at 9600 baud for debug messages.
  • CAN.begin(500E3): Initializes the CAN bus at 500 kbps, one of the most common baud rates for automotive and industrial applications. If initialization fails (e.g., hardware issue), the code prints an error and stops.

Then in  loop

  • CAN.beginPacket(0x12): Starts a new standard CAN packet with the 11-bit identifier 0x12.
  • CAN.write(): Adds data bytes to the packet. Here, we’re sending the ASCII characters 'h', 'e', 'l', 'l', 'o' (5 bytes total, well within the 8-byte limit).
  • CAN.endPacket(): Finalizes and sends the packet over the CAN bus.

Then in extend 

  • CAN.beginExtendedPacket(0xFFFFF): Starts an extended CAN packet with the 29-bit identifier 0xFFFFF. This is useful when you need more unique IDs for a large network of devices.
  • The rest works the same way: we send the characters 'w', 'o', 'r', 'l', 'd' as data bytes.

4  Test for CAN on XMC4200

Baud Rate Matching: All devices on the CAN bus must use the same baud rate. 500 kbps is standard for automotive, 125 kbps is common for industrial applications.

Termination Resistors: Always add 120Ω resistors at the two ends of the CAN bus to eliminate signal reflections. This resistor is soldered in this board.

Common Ground: All devices on the bus must share a common ground reference for reliable communication. Although only two line is enough for communication.

The test result is output in serial terminal

image

Now it is ready for the CAN bus run as expected.

  • Sign in to reply
  • Cancel
  • DAB
    DAB 1 month ago

    Nice update.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube