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
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs CAN communication with Hercules Safety Microcontroller - part 1: tryout
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 12 Sep 2017 7:06 PM Date Created
  • Views 3819 views
  • Likes 7 likes
  • Comments 11 comments
  • automotive
  • hercules
  • launchpad
  • can
Related
Recommended

CAN communication with Hercules Safety Microcontroller - part 1: tryout

Jan Cumps
Jan Cumps
12 Sep 2017

I'm trying out basic CAN communication on a Hercules microcontroller.

This first test is to test an example project.

Four CAN modules send an 8 char message out to themselves (so that we don't need external hardware).

 

What's tested here is how to set up CAN and how to use interrupt read-back.

 

image

 

 

The CAN example

 

This is the training code that comes with the HALCoGen configuration tool for Hercules.

It uses the controller's internal loop back mechanism to send messages to itself without going external.

This is an inherent part of the safety features of this controller: the ability to verify its own peripherals.

We use it here as part of a demo. In the Hercules safety library, this function is used to validate that the module works and fails safely.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

I'm using a Hercules TMS570LC43 LaunchPad. The controller has 4 DAC modules. I enable all.

image

Then I configure a message sender (1) and receiver (2) for each of the 4 CANs. The message ID for sender and receiver have to be the same (I use 1), otherwise traffic is ignored by the receiver.

Interrupts are enabled on the receivers.

The image shows CAN #2. The setup is the same for all 4.

image

The high interrupts for the 4 CAN modules have to be enabled in the VIM table.

I'm showing CAN 1 here. It's interrupt 16.

the other ones are on position 35, 45 and 113.

image

 

The Code

 

We use a sender buffer for each of the 4 modules that contains dummy values (not really. It's Jack Kilby Day so I've adapted the content).

 

#define D_COUNT  8

uint8 tx_data1[D_COUNT] = {'J','a','c','k',' ', ' ',' ',' '};
uint8 tx_data2[D_COUNT] = {'K', 'i', 'l', 'b', 'y', ' ', ' ', ' '};
uint8 tx_data3[D_COUNT] = {'D', 'a', 'y', ' ', ' ', ' ', ' ', ' '};
uint8 tx_data4[D_COUNT] = {31,32,33,34,35,36,37,38};

 

The receive buffers are empty. At the end of the program they should get the same values as the send buffers.

 

uint8 rx_data1[D_COUNT] = {0};
uint8 rx_data2[D_COUNT] = {0};
uint8 rx_data3[D_COUNT] = {0};
uint8 rx_data4[D_COUNT] = {0};

 

At init time, we set the loop-back mode of the 4 CAN modules so that all traffic internally flows from the output to it's own input.

 

    /** - configuring CAN1 MB1,Msg ID-1 to transmit and CAN2 MB1 to receive */
    canInit();
    canEnableloopback(canREG1, Internal_Lbk);
    canEnableloopback(canREG2, Internal_Lbk);
    canEnableloopback(canREG3, Internal_Lbk);
    canEnableloopback(canREG4, Internal_Lbk);

 

The only thing the code will do is send the 4 messages. You will not find read functions here. That happens in the interrupt service handler.

 

    canTransmit(canREG1, canMESSAGE_BOX1, (const uint8 *) &tx_data1[0]);
    canTransmit(canREG2, canMESSAGE_BOX1, (const uint8 *) &tx_data2[0]);
    canTransmit(canREG3, canMESSAGE_BOX1, (const uint8 *) &tx_data3[0]);
    canTransmit(canREG4, canMESSAGE_BOX1, (const uint8 *) &tx_data4[0]);

 

The ISR receives the info and fills the receive buffers.

 

void canMessageNotification(canBASE_t *node, uint32 messageBox)  
{
    if(node==canREG1)
    {
        canGetData(canREG1, canMESSAGE_BOX2, (uint8 * )&rx_data1[0]); /* copy to RAM */
    }
    if(node==canREG2)
    {
        canGetData(canREG2, canMESSAGE_BOX2, (uint8 * )&rx_data2[0]); /* copy to RAM */
    }
    if(node==canREG3)
    {
        canGetData(canREG3, canMESSAGE_BOX2, (uint8 * )&rx_data3[0]); /* copy to RAM */
    }
    if(node==canREG4)
    {
        canGetData(canREG4, canMESSAGE_BOX2, (uint8 * )&rx_data4[0]); /* copy to RAM */
    }
}

 

This is a little exercise that learns how to configure the CAN peripherals. At the end of the program, the content of the receive buffers should be identical to the transmit info.

 

image

 

My next exercise will be to send CAN messages physically from one microcontroller to another.

 

Project attached. Have a nice Jack Kilby Day!

 

 

Road Test Blog
part 1: First trials
part 2: Inject CAN Messages
part 3: Analyzer as Test Tool
part 4: Analyze the Physical layer of CAN Bus
Related Blog
part 1: tryout
part 2: Communication between 2 Devices
part 3a: Design a Bus Driver PCB
part 3b: Design a Bus Driver PCB - Schematics and Custom Components
part 3c: Design a Bus Driver PCB - Layout
part 3d: Design a Bus Driver PCB - Test
Attachments:
TMS570LC43_CAN_TEST.zip
  • Sign in to reply

Top Comments

  • DAB
    DAB over 8 years ago +3
    Interesting post. I have not done anything with CAN, so I find these posts very informative. DAB
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to michaelkellett +2
    First little success:
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to DAB +1
    Thank you, DAB . (note that I cunningly used Dudley 's trick to @mention you )
Parents
  • Jan Cumps
    Jan Cumps over 8 years ago

    Even though the internal loopback is enabled, you can still probe the traffix on the TX pins.

    Here's a capture for CAN 1 - 3.

     

    image

     

    It would even be more fun if my logic analyser would understand CAN.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett over 8 years ago in reply to Jan Cumps

    There's a pending RoadTest for a Microchip CAN tool !

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to michaelkellett

    checking ... I haven't seen that. Thanks for the info MK.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to michaelkellett

    michaelkellett  wrote:

     

    There's a pending RoadTest for a Microchip CAN tool !

     

    MK

    Are you referring to this one: Microchip CAN Bus Analyser Tool ?

    If I can find a good use case, I'll enroll.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett over 8 years ago in reply to Jan Cumps

    Hello Jan,

     

    Yes, that's it.

     

    Good luck.

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to michaelkellett

    michaelkellett  wrote:

     

    There's a pending RoadTest for a Microchip CAN tool !

     

    MK

    I've enrolled. Crossing fingers.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Jan Cumps
    Jan Cumps over 8 years ago in reply to michaelkellett

    michaelkellett  wrote:

     

    There's a pending RoadTest for a Microchip CAN tool !

     

    MK

    I've enrolled. Crossing fingers.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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 © 2025 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.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube