CanBus v1.2 message delay and HEX structure

Hi everyone,

The past few weeks have gone really well using the canbus shield v1.2 for pulling a can dump from both my pontiac and my friends FRS. I was even able to broadcast RPM back to the pontiac and have it change the tach with the engine off.



Currently, I have the electronic steering system out of the FRS on a test bench in my living room, and need to broadcast (18) Can ID’s over the network. After a few weeks of recording and translating the Id’s from the car and rebroadcasting them, I haven’t had any success getting the test rig to respond.



I have 2 questions that I havn’t been able to find answers for:

  1. Can I just use CAN.sendMsgBuf one after another or do I need a delay after it? If I do use a delay, does it interfere with transmitting at the right times on the 500kbps bus?


  2. I am structuring the message “buff” for each ID as I recorded it. Should the buff be structured as I have it in HEX? or should I input decimal and the shield takes care of translating? MY code is below for anyone that might see something that I’m doing wrong. Thanks for the help.

[code]
// demo: CAN-BUS Shield, send data
// [email protected]

#include <mcp_can.h>
#include <SPI.h>

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);

unsigned char msg144[8] = {0xC0, 0x0, 0x71, 0x8A, 0x44, 0xA4, 0xA0, 0x0};// 0x140 70mph C0 0 71 8A 44 A4 A0 0
unsigned char msg360[8] = {0x96, 0x7, 0x87, 0x80, 0x37, 0x80, 0x1, 0x0};// 0x360 70mph: 96 7 87 80 37 80 1 0
unsigned char msg282[8] = {0xB0, 0xB1, 0x8A, 0x64, 0x64, 0x0, 0x20, 0x0};//282 70MPH : B0 B1 8A 64 64 0 20 0
unsigned char msg142[8] = {0x5B, 0x26, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0};//0X142 70MPH 5B 26 8 0 0 0 0 0
unsigned char msg361[8] = {0x5, 0x29, 0x0, 0xD8, 0xD, 0xB0, 0x85, 0x79}; //5 29 0 D8 D B0 85 79
unsigned char msg152[8] = {0xF0, 0xE4, 0x0, 0x0, 0x0, 0x2, 0x0, 0x4C};
unsigned char msg372[8] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};// 0X372 0 0 0 0 0 0 0 0
unsigned char msg4DD[8] = {0x1E, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; ///1E 0 0 0 0 0 0 0 (159661)
unsigned char msg4C1[8] = {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};//1 0 0 0 0 0 0 0
int dT = 0;//easy to change the delay between sending mesages

void setup() {
Serial.begin(115200);

while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println(“CAN BUS Shield init fail”);
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println(“CAN BUS Shield init ok!”);
// Serial.println(msg18[2]);
}

void loop() {
CAN.sendMsgBuf(0x144, 0, 8, msg144); delay(dT);

CAN.sendMsgBuf(0x360, 0, 8, msg360); delay(dT);

CAN.sendMsgBuf(0x282, 0, 8, msg282); delay(dT);

CAN.sendMsgBuf(0x142, 0, 8, msg142); delay(dT);

CAN.sendMsgBuf(0x361, 0, 8, msg361); delay(dT);

CAN.sendMsgBuf(0x152, 0, 8, msg152); delay(dT);

CAN.sendMsgBuf(0x372, 0, 8, msg372); delay(dT);

CAN.sendMsgBuf(0x4DD, 0, 8, msg4DD); delay(dT);

CAN.sendMsgBuf(0x4C1, 0, 8, msg4C1); delay(dT);

}
[/code]

1)Baud rate is an attribute of signals, and delay determines the gap between each time signal transmitted, which is independent of each other.

2)Data type is basic knowledge of Computer Science. If you are interested in it, you can study the relevant books of C and C++.

LOL Bestlux. so you joined today, just to insult my lack of knowledge? trolls everywhere smh.



I’m hoping someone else has some thoughts other than “go get a degree in computer science”

Hello,I’m sorry for being some kind of impolite because of my poor language skill. I’m a novice of English, surfing in the forum for improving my communication skill. And after reading your post, I think you have successfully completed the experiment successfully, but still have some questions, that are just for curiosity.

Your question is a very basic knowledge of programming, and you can find your answer easily through Wiki or any programming tutorial.

Please refer to this link:

https://en.wikipedia.org/wiki/Data_type

Specifically, Hex and Decimal are just different representations of the same values, and they are eventually translated into the same 0 and 1 in memory by the compiler.

For example, following two line of code does the same thing.
</s>unsigned char msg[8] = {0x5, 0x29, 0x0, 0xD8, 0xD, 0xB0, 0x85, 0x79}; <e>
</s>unsigned char msg[8] = {5, 41, 0, 216, 13, 176, 133, 121};<e>
They all create a section of memory with the same content as:



I hope my answer will help you.

Best regards,

I have 2 questions that I havn’t been able to find answers for:

  1. Can I just use CAN.sendMsgBuf one after another or do I need a delay after it? If I do use a delay, does it interfere with transmitting at the right times on the 500kbps bus?



    It is better to add delay between each message see the code for sendMsgBuf. It returns a byte CAN_OK if messages sends successfully.

[code]

/*********************************************************************************************************
** Function name: sendMsgBuf
** Descriptions: Send message by using buffer read as free from CANINTF status
** Status has to be read with readRxTxStatus and filtered with checkClearTxStatus
*********************************************************************************************************/
byte MCP_CAN::sendMsgBuf(byte status, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf)
{
byte txbuf_n=statusToTxSidh(status);

if ( txbuf_n==0 ) return CAN_FAILTX; // Invalid status

mcp2515_modifyRegister(MCP_CANINTF, status, 0); // Clear interrupt flag
mcp2515_write_canMsg(txbuf_n, id, ext, rtrBit, len, buf);

return CAN_OK;
}
[/code]

  1. I am structuring the message “buff” for each ID as I recorded it. Should the buff be structured as I have it in HEX? or should I input decimal and the shield takes care of translating? MY code is below for anyone that might see something that I’m doing wrong. Thanks for the help.

    I don’t get your this query. I hope the first one will help you.