element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • 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
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • 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
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs TI Hercules LaunchPad -  test the CAN with a poor man's CAN driver
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 13 Dec 2014 10:40 PM Date Created
  • Views 1015 views
  • Likes 6 likes
  • Comments 7 comments
  • hercules_launchpad
  • arm_cortex
  • texas_instruments
  • automotive
  • microcontroller
  • protocol
  • feature_tutorial
  • can
Related
Recommended

TI Hercules LaunchPad -  test the CAN with a poor man's CAN driver

Jan Cumps
Jan Cumps
13 Dec 2014

I've been working on a breadboarded BoosterPack to test the CAN modules on the TI Hercules LaunchPad, without transceivers or real CAN bus.

image

This is inspired by the following Siemens application note AP2921 On-Board Communication via CAN without Transceiver.
The example allows you to run and probe the canIntCommunication example from HALCoGen by using 1 resistor, 2 diodes, some wire and a breadboard.

For learning use only. This design is not intended for use outside your lab. See this design for a fully functional CAN bus.

 

EXPERIENCE ZONE:

  • Automotive: My design facilitates investigating the automotive CAN protocol.

PROJECT FEATURES:

  • Learn CAN with your LaunchPad and a few passive components
  • the CAN1 and CAN2 module on your LaunchPad can talk to each other - just like with the bigger development boards
  • You can probe the signals with oscilloscope and logic analyzer
  • Low entry point to experiment with CAN

 

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

 

The poor man's can bus

 

A proper CAN implementation uses tranceivers and twisted pair wiring. And in an automotive setting I would not use anything different.

But for experimenting purposes, there's a simpler solution. You can replace a driver by a single diode on the transmit line:

image

 

The launchpad has 2 CAN modules, but no driver. In a test setting, that driver is not really needed.

Send and Receive of all CAN devices use the same single wire. The only thing we have to take care of is that the send lines don't conflict.

A simple isolation diode does the job. It takes care that a transmit line can drive the line without having to fight with the line's level.

If there's a conflict between senders, the diode takes care that it doesn't result in overload of the CAN peripheral.

image

Code

 

I use HALCoGen's canIntCommunication example.

The only change I've made is to place the canMessageNotification() function in notification.c in stead of in sys_main.c, because it belongs there.

 

sys_main.c:

// ...
/* USER CODE BEGIN (1) */
#include "can.h"
#include "esm.h"
#include "sys_core.h"


#define D_COUNT  8


uint32 cnt=0, error =0, tx_done =0;
uint8 tx_data[D_COUNT][8] = {0};
uint8 rx_data[D_COUNT][8] = {0};
uint8 *tx_ptr = &tx_data[0][0];
uint8 *rx_ptr = &rx_data[0][0];
uint8 *dptr=0;


void dumpSomeData();
/* USER CODE END */







// ..// ....

 

void main(void)
{
/* USER CODE BEGIN (3) */


    /* 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);


    /** - 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 ...*/
    }


    /** - 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 */
          }
     }


    while(1){}; /* wait forever after tx-rx complete. */


/* USER CODE END */
}


/* USER CODE BEGIN (4) */
/* writing some data to ram  */
void dumpSomeData()
{
     uint32 tmp = 0x11;


     cnt = (D_COUNT*8)-1;
     dptr = &tx_data[0][0];
     *dptr = tmp;


     while(cnt--)
     {
        tmp = *dptr++;
        *dptr = tmp + 0x11;
     }
}




/* can interrupt notification */
/* Note-You need to remove canMessageNotification from notification.c to avoid redefinition */


// jc: moved to notification.c




/* USER CODE END */

 

 

notification.c:

/* USER CODE BEGIN (0) */
extern uint32 tx_done;
extern uint8 *rx_ptr;


/* USER CODE END */

...

#pragma WEAK(canMessageNotification)
void canMessageNotification(canBASE_t *node, uint32 messageBox)
{
/*  enter user code between the USER CODE BEGIN and USER CODE END. */
/* USER CODE BEGIN (15) */
    /* 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;
    }


   /* Note: since only message box 1 is used on both nodes we dont check it here.*/
/* USER CODE END */
}

 

Result

 

Here's a sample taken with my protocol analyzer (a Papilio Pro loaded with the LogicSniffer design, with OpenLogic Sniffer as client):

image

 

Nothing spectacular here. But it's now possible to start digging into the CAN protocol with the Hercules LaunchPad without additional investment. A few scrap parts will do.

  • Sign in to reply

Top Comments

  • jw0752
    jw0752 over 8 years ago +1
    Thanks for your post. I had never even heard of the CAN buss before this. Learn something new everyday. John
  • michaelkellett
    michaelkellett over 4 years ago in reply to DAB +1
    CAN bus had several advantages over other things that were available at the time of its introduction and some of these persist. At the time the main competitor in automotive were various forms of UART…
  • Jan Cumps
    Jan Cumps over 4 years ago in reply to michaelkellett +1
    michaelkellett wrote: ... I've just noticed that DAB wrote his comment 4 years ago - MK He's a visionary . Also shows that I never give up on a design, even though many kickstarters and new disrupting…
  • DAB
    DAB over 4 years ago in reply to michaelkellett

    I try to follow all of the interesting projects.

    Jan's work got me interested in the Hercules board.

     

    DAB

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

    michaelkellett  wrote:

     

    ...

    I've just noticed that DAB wrote his comment 4 years ago - image

     

    MK

    He's a visionary image. Also shows that I never give up on a design, even though many kickstarters and new disrupting technologies gave up in that timespan image.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett over 4 years ago in reply to DAB

    CAN bus had several advantages over other things that were available at the time of its introduction and some of these persist. At the time the main competitor in automotive were various forms of UART based NRZ (eg K-line)

    CAN offered the advantages of speed, true multi-drop, built in error detection and non-destructive bit-wise arbitration (which means that priorities may be assigned to devices and are supported by hardware.)

    Even when it first appeared it was quite cheap and it's now very cheap.

     

    I've just noticed that DAB wrote his comment 4 years ago - image

     

    MK

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

    I now have the physical layer CAN boards working: CAN communication with Hercules Safety Microcontroller - part 3a: Design a Bus Driver PCB .

    These can be used in automotive builds, while the design in the blog above is for experimenting and learning only.

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

    There's some info of the history on the below PDF, and on wikipedia.

    http://www.eecs.umich.edu/eecs/courses/eecs373/Lec/W12Student/373CANpreso.pdf

     

    Developed because existing serial buses in the early 1980s were not able to

    fulfill all the requirements to be used in passenger cars

     

    Maybe the avionics standards were overkill for automotive use?

    • Cancel
    • Vote Up 0 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 © 2023 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube