CAN Messaging and CAN Buffers

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times

CAN Messaging and CAN Buffers

Post by Jay Dee »

Hi, I have a couple of queries on how the CAN buffers work with the CAN component, it all related to a different method of CAN messaging I'm working with so thought I should outline that first...

COMPOUND MESSAGING
I have a CAN based device which transmits different groups of variables but under the same CAN ID. As opposed to a standard CAN message which contains the same group of variables in each message. In our industry we often refer to this as compound messaging but this may not be a universally acknowledged term.

In this Compound method, the CAN message typically contains the full 8 data bytes but one of the data bytes is used to uniquely identify the subsequent group of variables, which occupy the remaining 7 bytes.

In the Compound example below, Byte0 of each message is used to uniquely identify the group. We refer to this value as the 'Compound ID'.

ID - DLC - Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7
7E8 - 8 - 0 Var#01 Var#02 var#03 var#04 var#05 var#06 var#07
7E8 - 8 - 1 Var#08 Var#09 var#10 var#11 var#12 var#13 var#14
7E8 - 8 - 2 Var#15 Var#16 var#17 var#18 var#19 var#20 var#21
7E8 - 8 - 3 Var#22 Var#23 var#24 var#25 var#26 var#27 var#28

As can be seen, this technique has allows many more variable to be transmitted under a single CAN ID, admittedly at a slower rate as you have to cycle though the groups of variables. And this brings me to my query on how the CAN buffers work with the CAN component.

CAN BUFFERS
A) After a message is loaded into the buffer, Under what conditions is the next message loaded into the buffer? Is it simply replaced as soon as the next message of the same ID is received?

B) If I read a byte from the buffer (I.e. the compound ID byte), when I read the next byte from the buffer will it be from the same message or could the buffer have been updated with new data.

B) Is there a method to read all of the bytes from the buffer in one go (or at least very quickly), thus ensuring you have all of that specific buffered message.

c) Is there a method to clear the buffer, to ensure that when I request a message,I know that the subsequent returned byte will drop straight into the buffer.

Any help and advice appreciated, :?
Cheer all,
John.

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times

Re: CAN Messaging and CAN Buffers

Post by Sean »

Hello,

The following assumes you are using the CAN E-Block as the interface hardware.

When a Flowcode program calls the CAN component CheckRX macro, if the hardware buffer being referenced in the CAN control chip has received a new message, the contents are read back to a local software buffer in the microcontroller RAM - freeing the hardware buffer to receive a new message.

The GetRx.... macros access the local, software buffer.

The hardware buffer(s) will generate an overflow flag if a valid message is received before a previous message has been read, but will not be overwritten.

The software buffer will not be overwritten until the next successful CheckRX.

The component only defines one software buffer. So, if you want access to multiple receive buffers simultaneously, the ID and data retrieved from successful CheckRX calls should be read back immediately to program variables.

Transmit ID and data is written directly to the selected hardware transmit registers by the SetTxID and SetTxData macro calls, and enabled for transmission by the SendBuffer macro call.

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times

Re: CAN Messaging and CAN Buffers

Post by Jay Dee »

Hi Sean,
Yep I'm using the CAN E-Block.
Thanks for outlining the way the buffers are loaded, I now know that I can read the 'Compound ID' byte and reliably return to the software buffer to extract the other 7 data bytes which is great.
Having read your description and a bit more from the CAN controllers data sheet, I have a better idea of how the hardware buffers are set-up. I see if I can get my system to play ball and look 'under the bonnet' of the CAN macros to see who everything is working.
Cheers,
John.

Post Reply