Forwarding with FlexCAN_T4 While Modifying Some

Surely the array sizes should be 13 and 8 instead of 12 and 7

And I think you would want a data type of uint8_t instead of uint16_t

Thanks, makes sense ... so declare the array with sizes 13 and 8, but would I address it with 0 - 12 and 0 - 7?

For the data type, Hex is base 16, so I thought I would be using uint16_t. But now that I think about it more, maybe I just need to declare it like: byte EVICMessages[13][8];

I changed the name of the matrix as it appears you can't start the name with a number (IDE gives me an error if I try to use 328Matrix as the name).

So I can declare it with byte EVICMessages[13][8]; without a compile error, but when trying to populate it with values, I am getting an error. Not sure if it's just a syntax error, or if I'm going about this incorrectly though.

Code:
  EVICMessages[13][8] = { {0x60, 0x42, 0x00, 0x54, 0x00, 0x68, 0x00, 0x65},
                          {0x50, 0x02, 0x00, 0x20, 0x00, 0x4A, 0x00, 0x75},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65}
                        };

The error I'm getting is:

Code:
  403 |                       };
      |                       ^

exit status 1

Compilation error: cannot convert '<brace-enclosed initializer list>' to 'byte' {aka 'unsigned char'} in assignment
 
So it looks like my issue is in trying to fill the matrix in a function, rather than setting the values within the declaration directly.

If I add this in the beginning of the code, outside of any functions, then it compiles.

Code:
byte EVICMessages[13][8] = { {0x60, 0x42, 0x00, 0x54, 0x00, 0x68, 0x00, 0x65},
                          {0x50, 0x02, 0x00, 0x20, 0x00, 0x4A, 0x00, 0x75},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65},
                          {0x40, 0x02, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x65}
                        };

For my purposes right now, this works fine, as once I figure out the messages I need to be sending, they will be static and I won't need to update them within the program.

It also works with uint16_t as the data type, but I assume byte is better for my purposes? If I am going to be leveraging something like this later in the program ... or, maybe uint16_t and byte are synonymous?

Code:
TestFrame.id = 0x328;
for (int j=0; J<13; J++) {
   for (int i=0; i<8; i++) {
      TestFrame.buf[i] = EVICMessages[j][i];
   }
   Can0.write (TestFrame);
}
 
Last edited:
No, byte is 8 bits wide, uint16_t is 16 bits wide.

Thanks, I misunderstood what the data type meant. I made a bad assumption it was referring to base (I guess because Hex is base 16?). Just my ignorance showing as I continue to learn.

I see now it breaks down as:

u = unsigned
int = integer
16 = number of bits used
t = typedef

Knowing that, and considering each CAN message is comprised of 8 bytes ... I should be able to use uint8_t or byte.

So it seems uint8_t and byte are then synonymous?

Here's how I'm understanding it

1711281275708.png


For anyone interested in this project in more detail, I've created a power point document outlining the approach and details, which can be accessed here:

Stoops Durango Canbus Details PPT
 
Back
Top