Go Down

Topic: Cheap & simple MCP2551/MCP2515 CAN BUS set up (Read 67194 times) previous topic - next topic


I understand the basic send and receive sketches, but I wish to send / receive a data structure rather than bytes.  The structure will be something like:
struct MsgType
  unsigned int NodeID;
  unsigned int NodeLoc;
  unsigned int DevType;
  byte DevID;
  byte DevStat;

MsgType  MsgData

After assigning values the data would be transmitted.  On receiving the data it would be translated back into a structure format.

All examples that I have seen on the Internet deal only with byte data.  Can a structure be transmitted and received, and can you please provide some sample code.

I am wanting to use this in a model railroad to transmit messages to operate various devices such as crossarms and servos.

Appreciate your assistance.


you fix those things with:

 typedef union {
    UCHAR array[sizeof(float)];
    float ebyte;
} E_float;

typedef union {
   UCHAR array[sizeof(int)];
   int Eint;
} E_int;

typedef union {
   UCHAR array[sizeof(UCHAR)];
   UCHAR Euchar;

in fact you need a converter visa versa to convert your structure

Go Up