I have a Photon that talks to a CANbus module via UART. TBH I’ve not had any problems with it before now and the code hadn’t changed. Things stopped working and I’ve now made many changes in order to debug the system and here’s what I’ve arrived at…
The module is connected to the CANbus fine, and can receive data. If I try and send data I get spark/device/last_reset : panic, hard_fault
The line of code is: can.send(0x7DF, 0, 0, sizeof(data), data);
the data is {0x02, 0x01, 0x0F, 0x55, 0x55, 0x55, 0x55, 0x55}
This calls a class that came with the module https://www.seeedstudio.com/Serial-CAN-BUS-Module-based-on-MCP2551-and-MCP2515.html and the method looks like this:
unsigned char Serial_CAN::send(unsigned long id, uchar ext, uchar rtrBit, uchar len, const uchar *buf) {
unsigned char dta[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
dta[0] = id>>24; // id3
dta[1] = id>>16&0xff; // id2
dta[2] = id>>8&0xff; // id1
dta[3] = id&0xff; // id0
dta[4] = ext;
dta[5] = rtrBit;
for(int i=0; i<len; i++)
{
dta[6+i] = buf[i];
}
for(int i=0; i<14; i++)
{
Serial1.write(dta[i]);
}
}
All it does is send some data over serial, so I don’t see how a) the status of the CANbus can have any effect on whether this method throws an error or not and b) how this could result in a hard_fault
Bearing in mind all the other can methods just use the same serial interface and work successfully up until this point.
How do I debug this further?