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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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 Probing your Hercules LaunchPad CAN bus Part 2
  • 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: 4 Feb 2015 5:00 PM Date Created
  • Views 2221 views
  • Likes 1 like
  • Comments 1 comment
  • hercules_launchpad
  • arm_cortex
  • automotive
  • real_time
  • texas_instructments
  • protocol
  • safety_devices
  • hercules
  • launchpad
  • can
Related
Recommended

Probing your Hercules LaunchPad CAN bus Part 2

Jan Cumps
Jan Cumps
4 Feb 2015

The Hercules LaunchPads of Texas Instruments have two (or three) CAN controllers.

It is possible to learn the CAN protocol and have real messages flowing with the LaunchPad and only three jellybean components.

This series explains how the standard TI examples work, but it goes further than that.

I'll also be looking at the signals with an oscilloscope and logic analyzer.

 

My first post in this series, Probing your Hercules LaunchPad CAN bus Part 1,

explains the minimal hardware required to get the example working on the LaunchPads (a resistor and two diodes).

In this post I'll check out the example project.

 

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

 

TI's example project

 

The Hercules examples are available from the HALCoGen Help menu.

 

image

 

You'll find two examples for the CAN controller.

They have the same functionality, but one is interrupt based, the other manages the communication without interrupts.

In my review, I'm using the interrupt driven approach of example_canIntCommunication.

 

image

 

I'm not doing a step by step guide on how to make the example - that's what the help file from HALCoGen is doing.

The focus in this article is on the things that are not documented in HalcoGen Help.

 

What is that code supposed to do?

 

The example sends data form the CAN1 of the Hercules microcontroller to CAN2.

Both CAN controllers are activated and configured in HALCoGen. The actual data exchange is coded in C.

 

Module configuration in HalCoGen

 

Message box 1 of CAN1 sends messages with ID 1.

 


image


Message box 1 of CAN2 listens for messages with ID 1 in its message box 1.

 


image

 

The settings highlighted on the images above show what's happening. In the first picture,

Message box 1 of CAN1 is set up as transmitter, sending messages with ID 1.

You can also see that the interrupt is enabled.

In the second picture, with settings of CAN2 Message box 1, everything is the same, except that this box is configured as receiver.

 

You can see on the interrupt tabs of HALCoGen what's happening when the interrupts fire.

I've kept all settings as default. The only action in HALCoGen is to enable the channels.

Here's the mapping between the event in the CAN1 tab and the interrupt map:


image

And this is the mapping for CAN2:


image

 

On the VIM tab, you can see how the channels are mapped to interrupt handlers:


image

 

If you spend some time in the source files generated by HALCoGen, in particular sys_vim.h, sys_vim.c and can.c,

you can follow how the entries can1HighLevelInterrupt and can2HighLevelInterrupt are resolving to a call to the function canMessageNotification().

 

The C code in Code Composer Studio:

 

The program is very small, and we can split it up in 3 sections of only a few lines of C: setup, communication and validation.

 

The setup

 

    /* enable irq interrupt in Cortex R4 */
    _enable_interrupt_();


    /** - writing a random data in RAM - to transmit */
    dumpSomeData();


    /** - configuring CAN1 MB1,Msg ID-1 to transmit and CAN2 MB1 to receive */
    canInit();


    /** - enabling error interrupts */
    canEnableErrorNotification(canREG1);
    canEnableErrorNotification(canREG2);

 

Interrupts are enabled,

test message data is generated (just some data to have a paiload that can be transmitted and received),

the settings from HALCoGen are applied in the canInit() call

and error notification is activated.

 

communication

 

    /** - starting transmission */
    for(cnt=0;cnt<D_COUNT;cnt++)
    {
      canTransmit(canREG1, canMESSAGE_BOX1, tx_ptr); /* transmitting 8 different chunks 1 by 1 */
      while(tx_done == 0){};                /* ... wait until transmit request is through        */
      tx_done=0;
      tx_ptr +=8;    /* next chunk ...*/
    }

 

Thanks to the interrupt support, this piece of code is very condensed. Below is the interrupt handler that completes the whole exchange process:

 

void canMessageNotification(canBASE_t *node, uint32 messageBox)
{
    /* node 1 - transfer request */
    if(node==canREG1)
    {
      tx_done=1; /* confirm transfer request */
    }


    /* node 2 - receive complete */
    if(node==canREG2)
    {
    while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));
    canGetData(canREG2, canMESSAGE_BOX1, rx_ptr); /* copy to RAM */
    rx_ptr +=8;
    }
}

 

That's all for the communication part.

 

validation

 

    /** - check the received data with the one that was transmitted */
    tx_ptr = &tx_data[0][0];
    rx_ptr = &rx_data[0][0];


    for(cnt=0;cnt<63;cnt++)
     {
          if(*tx_ptr++ != *rx_ptr++)
          {
               error++; /* data error */
          }
     }

 

This is a simple compare of the data that is sent to the received info.

If error is still 0 after the validation, the data check was ok, and the exact same data that was sent on CAN1 has been received by CAN2.

 

And that's it. The example isn't that exciting, but a lot of things happened. And you can measure that. In the following post we'll do the setup and measure the real data.

Have a resistor, two diodes and a Hercules LaunchPad ready by then. And boot your scope.

 


image

related posts

Probing your Hercules LaunchPad CAN bus Part 1

Probing your LaunchPad CAN bus Part 3

  • Sign in to reply

Top Comments

  • DAB
    DAB over 10 years ago +1
    Nice detailed post. DAB
  • DAB
    DAB over 10 years ago

    Nice detailed post.

     

    DAB

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