Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 3 months ago.
how to send a buffer through CAN?
how to send a buffer through CAN?
1 Answer
11 years, 3 months ago.
You need a global variable, data[], then you put your CAN data into an array, and call it. The code below is just an example from my program.
t
if(Send_stuff == 27) { data[0] = (char)(0x00); //EC1 status req data[1] = (char)(0x00); data[2] = (char)(0x00); data[3] = (char)(0x00); data[4] = (char)(0x00); data[5] = (char)(0x01); data[6] = (char)(0x00); data[7] = (char)(0x00); if(can2.write(CANMessage(EC_master_adress,data,6))) {} Send_stuff = 0; }
Of course you have to define the adress you are sending the data, and specify how many bytes of data to send. In my case, the EC_master_adress is defined in the header as #define EC_master_adres 0x40 and I need to send only 6 out of 8 bytes of data, but when doing copy/paste of blocks, is faster to copy the entire block. RGDS
To what? CAN frames can have up to 8 bytes of data but you would need to make some sense of them. CanOpen provides for more structured transmission.
posted by Ned Konz 15 Jun 2013