This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RE: CAN message ID's

Other Parts Discussed in Thread: HALCOGENHello

I am beginner and I used example canCommunication.c to transmit the message.
I am not able to understand, where the id is set ?
What should I do to change the id of my choice ?
  • Ankush,

    Try setting it here:

  • Thanks Anthony,

    But can we make it different using software code.
    I mean to say, suppose we are transmitting information of two sensors over CAN. So I need to give id:1 to information from one sensor and id:2 to the information from other sensor.
    Is it possible to do ?
  • Anjush,

    Well, the can bus I don't think has addresses like I2C - instead these are IDs for the message (could come from any device on the bus, and if they have the message ID matching the mailbox they appear in the mailbox.. doesn't matter who sent).
    There are something like 64 mailboxes so if it's just a few message types you can set them in HalCoGen statically and leave them as-is.

    If you have many message IDs to handle you can change the mailbox in software although it's a bit tricky because there are four shadow registers to write to; and one specific byte in the shadow register set initiates a copy from the shadow registers to the active CAN mailbox RAM. This is typical for programming IO devices - where there is a side effect to register reads/writes.

    And because these shadow registers are global resources - you have to be careful if you are using an OS and you have different threads updating the CAN mailboxes to guard the shadow register sets with some semaphore - to avoid the problem where one task is staging an update to a mailbox RAM but gets interrupted by another that uses the same shadow registers. The second would corrupt the state of the first if it doesn't check for ownership via a semaphore.

    Maybe this is something you could work into your blog as an example of when to use the semaphore ;)

    Best Regards,
    Anthony
  • Thanks for quick reply.

    Where I can read about these concepts you just explained ?
    and I am trying to see from the prospect of CAN transmitter.
    I think you explained about receiver side regarding mailbox. Right now I am not concerned with the receiver mailbox settings.
    I want to ask
    is it possible for a single CAN Transmitter to transmit once a string "ABCD" with id "0x1234" and next time transmit another string "LMNO" with id "0x8765" ? irrespective of CAN recivers.

    Please don't feel bad if I am taking anything wrong . You can always correct me sir.
  • Ankush,

    The technical reference manual has a whole chapter explaining how the CAN controller works.
    There is also a good 'poster' to request from Vector vector.com/vi_can_solutions_en.html
    Look for the 'Can/CanFD reference chart on the side of the page. This is a kind of 'cheat sheet' for most things CAN.
  • Hi Anthony
    Thank you very much. I will go through this link and will try to figure out my doubts.
  • Hi Anthony,

    I checked the reference design of CAN message protocol on Vector. I am not able to get good picture quality image from Vector website. As soon as I zoom it, everything is blurred. Do you have good quality image of it ?
  • Ankush,

    It's a wall-size poster about 2' x 4' -- if you fill in the request form they will usually mail you one.
    Good to have on your wall. I had one but lost mine when we changed buildings a few years ago.
    It was in the hallway for everyone in the team to look at and I think I left it hanging up :(
  • Its simple. Create Mailbox 3 to Tx a message. Mailbox 1 to receive a msg from sensor 1,Mailbox 2 to receive a msg from sensor 2(Setting Tx,Rx direction and ID's properly in Halcogen). After this, when sensor 1 sends a data with the ID1,it will be in Message box 1. Poll for NewData Flag to be set and read the data. If you have to send back a message to sensor 1, load an appropriate id that sensor 1's acceptence filter(if configured) will allow into its RAM and send(for this you will have to customise the Halcogen code as per your requirement)
  • Hi Akshay

    Thanks for your reply.
    I got nice explanation.

    " If you have to send back a message to sensor 1, load an appropriate id that sensor 1's acceptence filter"

    Can you please suggest me the steps to load an appropriate id, means the id I wish to configure while transmitting CAN message?
    Lets say I am sending 0x08 and 0x09 id's to two different sensors with data. So how can I do that ?
  • Generate code using Halcogen>Refer can_init for the appropriate message box>Configure IFxNO register to suit your need.Also canFillMessageObjectData,canUpdateID,canTransmit might help you with few customisations
  • Thanks for reply...
    Can I change id during runtime ?
    Like if I need to pass CAN id from some array while program is running ?
  • Yes, use the HALCoGen function canUpdateID() to change the ID of a mailbox.
  • Yes...I also suggest to spend some time reading the CAN Spec cos ul be able to use the DCAN module to the full potential then...The TRM does'nt talk about the Can Spec