- Wed Aug 10, 2011 6:23 pm
#131643
Hey guys, I was hoping there was someone on here that could help me out with some extended can messaging? I am currently using the following library for my CANBUS Shield
https://github.com/franksmicro/Arduino/ ... es/MCP2515
Which has proven to be amazing, however, I am having some trouble with extended CAN messaging. I found that on my car, there is the tire pressure monitor module which is at
ECU: 0x751
Address: 0xC901
Mask: 0x00FF
So with my test application, I am setting the following:
https://github.com/franksmicro/Arduino/ ... es/MCP2515
Which has proven to be amazing, however, I am having some trouble with extended CAN messaging. I found that on my car, there is the tire pressure monitor module which is at
ECU: 0x751
Address: 0xC901
Mask: 0x00FF
So with my test application, I am setting the following:
Code: Select all
I then have my software listen for the push of the joystick, and when pressed, it will transmit this message and listen on the bus, in a loop while the button is held down. I am not sure if my syntax above is correct? Here is a snippet of the library where the developer is setting the can message to transmit: message.adrsValue = 0x751;
message.isExtendedAdrs = true;
message.extendedAdrsValue = 0xC901;
message.rtr = false;
message.dataLength = 8;
for(int i = 0; i < 8; i++) {
message.data[i] = 0x00;
}
Code: Select all
I would be beyond grateful if someone could help me out. Greatful to the point of a donation if it has to come to that lol.boolean MCP2515::transmitCANMessage(CANMSG msg, unsigned long timeout)
{
unsigned long startTime, endTime;
boolean sentMessage;
unsigned short val;
int i;
startTime = millis();
endTime = startTime + timeout;
sentMessage = false;
val = msg.adrsValue >> 3;
writeReg(TXB0SIDH,val);
val = msg.adrsValue << 5;
if(msg.isExtendedAdrs)
val |= 1 << EXIDE;
writeReg(TXB0SIDL,val);
if(msg.isExtendedAdrs)
{
val = msg.extendedAdrsValue >> 8;
writeReg(TXB0EID8,val);
val = msg.extendedAdrsValue;
writeReg(TXB0EID0,val);
}
val = msg.dataLength & 0x0f;
if(msg.rtr)
bitWrite(val,TXRTR,1);
writeReg(TXB0DLC,val);
//Message bytes
digitalWrite(SLAVESELECT,LOW);
SPI.transfer(WRITE);
SPI.transfer(TXB0D0);
for(i = 0; i < msg.dataLength; i++)
SPI.transfer(msg.data[i]);
digitalWrite(SLAVESELECT,HIGH);
//Transmit the message
writeRegBit(TXB0CTRL,TXREQ,1);
sentMessage = false;
while(millis() < endTime)
{
val = readReg(CANINTF);
if(bitRead(val,TX0IF) == 1)
{
sentMessage = true;
break;
}
}
//Abort the send if failed
writeRegBit(TXB0CTRL,TXREQ,0);
//And clear write interrupt
writeRegBit(CANINTF,TX0IF,0);
return sentMessage;
}