Go Down

Topic: Building a CAN API for Arduino DUE (Read 138 times) previous topic - next topic


perhaps the while loop at the very end of loop method? I sometimes overlook the simplest things and over complicate them (life of a code monkey!!!)


Hello friends

I've been programming for a while with the API and there are some questions that I don't get very well.

These are my questions for the gurus:

1) I wasn't able to find the structure of "can_mb_conf_t" and the correspondence of the different elements with the CAN Register mapping (Section 41.9 of SAM3XA of Atmel documentation) so I get a little lost...
2) I also would appreciate a list with all defined parameters.

Thats all by this time.

Thank you a lot!!!



No problem Lufe,

Code: [Select]

typedef struct {
uint32_t ul_mb_idx;
uint8_t uc_obj_type;  //! Mailbox object type, one of the six different objects.
uint8_t uc_id_ver;    //! 0 stands for standard frame, 1 stands for extended frame.
uint8_t uc_length;    //! Received data length or transmitted data length.
uint8_t uc_tx_prio;   //! Mailbox priority, no effect in receive mode.
uint32_t ul_status;   //! Mailbox status register value.
uint32_t ul_id_msk;   //! No effect in transmit mode.
uint32_t ul_id;       //! Received frame ID or the frame ID to be transmitted.
uint32_t ul_fid;      //! Family ID.
uint32_t ul_datal;
uint32_t ul_datah;
} can_mb_conf_t;

This can be found within the can.h file in the libsam files.

Here are some other relevant structures which are found in component_can.h in the CMSIS files:
Code: [Select]

typedef struct {
  RwReg  CAN_MMR;       // (CanMb Offset: 0x0) Mailbox Mode Register
  RwReg  CAN_MAM;       // (CanMb Offset: 0x4) Mailbox Acceptance Mask Register
  RwReg  CAN_MID;       /**< \brief (CanMb Offset: 0x8) Mailbox ID Register
  RwReg  CAN_MFID;      /**< \brief (CanMb Offset: 0xC) Mailbox Family ID Register
  RwReg  CAN_MSR;       /**< \brief (CanMb Offset: 0x10) Mailbox Status Register
  RwReg  CAN_MDL;       /**< \brief (CanMb Offset: 0x14) Mailbox Data Low Register
  RwReg  CAN_MDH;       /**< \brief (CanMb Offset: 0x18) Mailbox Data High Register
  RwReg  CAN_MCR;       /**< \brief (CanMb Offset: 0x1C) Mailbox Control Register
} CanMb;
/** \brief Can hardware registers
#define CANMB_NUMBER 8
typedef struct {
  RwReg  CAN_MR;        /**< \brief (Can Offset: 0x0000) Mode Register
  WoReg  CAN_IER;       /**< \brief (Can Offset: 0x0004) Interrupt Enable Register
  WoReg  CAN_IDR;       /**< \brief (Can Offset: 0x0008) Interrupt Disable Register
  RoReg  CAN_IMR;       /**< \brief (Can Offset: 0x000C) Interrupt Mask Register
  RoReg  CAN_SR;        /**< \brief (Can Offset: 0x0010) Status Register
  RwReg  CAN_BR;        /**< \brief (Can Offset: 0x0014) Baudrate Register
  RoReg  CAN_TIM;       /**< \brief (Can Offset: 0x0018) Timer Register
  RoReg  CAN_TIMESTP;   /**< \brief (Can Offset: 0x001C) Timestamp Register
  RoReg  CAN_ECR;       /**< \brief (Can Offset: 0x0020) Error Counter Register
  WoReg  CAN_TCR;       /**< \brief (Can Offset: 0x0024) Transfer Command Register
  WoReg  CAN_ACR;       /**< \brief (Can Offset: 0x0028) Abort Command Register
  RoReg  Reserved1[46];
  RwReg  CAN_WPMR;      /**< \brief (Can Offset: 0x00E4) Write Protect Mode Register
  RoReg  CAN_WPSR;      /**< \brief (Can Offset: 0x00E8) Write Protect Status Register
  RoReg  Reserved2[69];
  CanMb  CAN_MB[CANMB_NUMBER]; /**< \brief (Can Offset: 0x200) MB = 0 .. 7
} Can;

If you look in the files I referenced you'll find a whole bunch of definitions. You can reference back and forth between those things and section 41 of the SAM3XA docs to figure things out.

However, the whole point of the canbus library is to make it so that you don't have to worry about all of these details. Palliser, I, and others have already been working on the library so that you don't have to worry about all these low-level details. My hope is that soon nobody will really wonder about can_mb_conf_t or any of the other low level structures. In my version of the lib I already basically removed all references and uses of that struct since it seems overly tied to hardware and complex to work with.


Thank you a lot!

I appreciate very much your work. I know how difficult it is to write libraries that match the needs of everybody. I will give a good use of this info!

I grow up in engineering through pages and pages of datasheets (when you had to get them in paper, long long time ago...) so although it is not the Arduino Spirit, sometimes I prefer go to a low level...

In any case THANK YOU!!!!! You guys have my full respect!



Hello all, firstly may I please apologise if this appears to be a daft question, I am new to Arduino Can Bus on the Due.

I've had a look at the examples given and the library and the SAM manual section, but I'm at a loss to understand how to setup the Due to receive ALL messages regardless of id.

Or if it was setup to receive SAE J1939 messages (29 bit messages) that uses a 3 bit priority, then a 18 bit Parameter Group Number (PGN), and then an 8 bit source address for the message.  The PGN allows for destination specific communication and broadcast communication.  How to set it up to receive a range or all PGN messages or a bank of PGN messages.

Thanks for your time & advice in advance.


Go Up