I need help with the DUE_CAN library. What I want to do is create a variable that will change the value in a message to be transmitted using the DUE_CAN Library from Collin80 on GitHub. I will use the example code from the library with a little tweaking to try and explain what I mean.
What I want to do is make the 0x00 a variable place holder. ex.
myFrame.data.bytes[0] = (MyVariable);
What datatype can I use for the variable where I can assign my variable to be a HEX value that will be sent over the can bus?
If this will not work or someone has a better method please let me know. I am open to any suggestions.
//This is architecture specific. DO NOT USE THIS UNION ON ANYTHING OTHER THAN THE CORTEX M3 / Arduino Due
//UNLESS YOU DOUBLE CHECK THINGS!
typedef union {
uint64_t value;
struct {
uint32_t low;
uint32_t high;
};
struct {
uint16_t s0;
uint16_t s1;
uint16_t s2;
uint16_t s3;
};
uint8_t bytes[8];
uint8_t byte[8]; //alternate name so you can omit the s if you feel it makes more sense
} BytesUnion;
typedef struct
{
uint32_t id; // EID if ide set, SID otherwise
uint32_t fid; // family ID
uint8_t rtr; // Remote Transmission Request
uint8_t priority; // Priority but only important for TX frames and then only for special uses.
uint8_t extended; // Extended ID flag
uint8_t length; // Number of data bytes
BytesUnion data; // 64 bits - lots of ways to access it.
} CAN_FRAME;
Thank you for your response. As you can probably already tell by my questions I don't have much experience coding. My response is this. Based upon the snippet provided can I make my variable a uint8_t data type? Would this work correctly or would I be violating a language rule trying to use a variable where I want to? Could I use something like this:
uint8_t myVariable;
myFrame.data.bytes[0] = ("%#x\n", myVariable); or could I just use (myVariable);