8 years, 11 months ago.

CAN Extended Frame 29-Bit

Hello Community, I have a problem with my CAN messages.

My program reads CAN messages from a document and put them out via a CAN transceiver. (It works) But there are also extended frame messages (29-bit) included in my document. And now my questions:

What is the easiest way to tell my program, that it should switch from standard to extended frame? Is there a command for this? (Please explain for a beginner)

Thank you very much,

Marv

1 Answer

8 years, 11 months ago.

The can message data structure contains a format field. The default is CANStandard, for 29 bit addresses set it to extended, everything else is the same. e.g.

canMessage myMessage;
myMessage.format = CANExtended;
myMessage.id = 0x34444;
myMessage.length = 1;
myMessage.data[0] = 0x55;
myCanBus.write(myMessage);

I build my own Message. Can I also integrate it there?

class CANTxMessage {

public:

Creates CAN TX Message

CANTxMessage(uint32_t _id = 0, uint8_t _dlc = 0, uint8_t *_data = 0, uint8_t _cycle = 1, bool _crc = false) {

id = _id;

dlc = _dlc;

data = _data;

cycle = _cycle;

crc = _crc;

for (int i=0; i<16; i++) {

s_pdu[i] = 0;

}

bz = 0;

cnt = 0;

}

uint32_t id; CAN identifier

uint8_t dlc; data length code

uint8_t *data; payload

uint8_t cycle; cycletime / timer_period

bool crc; flag: use crc?

uint8_t s_pdu[16]; S_PDU

uint8_t bz; message counter (for CRC protected msgs)

uint8_t cnt; cycle counter (for TX cycle timing)

};

posted by Marvin D. 20 Apr 2015

The mbed library only uses its own CANMessage data structure. You can't use your own class directly.

The best option if you want to keep your class within your code would be to create a function (or a method within your class) to convert between the two. Or you could modify the mbed libraries to use your class but that's a lot more work and just asking for trouble.

posted by Andy A 21 Apr 2015