0

I need help with a code to convert an AnalogIn input on the mbed LPC1768 to digital to be used by the CAN controller.The example syntax I'm using is

if(can1.write(CANMessage(1337, &counter, 2))) {
..........
}

where "counter" is the data to be transmitted and defined by me as a signed int (the example however defines it as a char). But I keep getting an error message

Error: No instance of constructor "mbed::CANMessage::CANMessage" matches the argument list in "project_test.cpp"

The controller CANMessage syntax is

CANMessage(int _id, const char *_data, char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard) {

  len    = _len & 0xF;
  type   = _type;
  format = _format;
  id     = _id;
  memcpy(data, _data, _len);
}

I really do not understand the controller syntax and how to apply it. Any help in explaining would be appreciated. Thanks

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Sue
  • 1
  • 1

1 Answers1

0

Since CANMessage only accepts a char* for the data paramter, you can convert your signed int value (which is 4 bytes) to an unsigned char like this:

unsigned char buf[0x8];
buf[0]=value & 0x000000ff;
buf[1]=(value >> 8)  & 0x000000ff;
buf[2]=(value >> 16) & 0x000000ff;
buf[3]=(value >> 24) & 0x000000ff;

and then

if (can1.write(CANMessage(1337, &buf, 8))) {
..........
}
fguertin
  • 3
  • 2