Summary:
I am able to read messages from the CANbus network, but not transmit messages from the Photon.
I have tried the following methods:
Method 1:
One Photon in CAN_TEST_MODE with a jumper wire connecting RX and TX. I wrote a program to send a message out on ID 215, and added 1 to the ID every time the message was received. I then printed on the serial, the message ID and received 215, 216, 217… etc. – This functioned as expected
Method 2:
Two Photons connected Rx to Tx and Tx to Rx, both powered by the same USB source (computer).
Photon 1 would send a CAN message out to Photon 2.
Photon 2 then added 1 to the message ID and sent the message back to Photon 1.
Photon 1 would then add 1 more to the ID and so forth, until the ID reached a number.
I tried this method with and without the CAN_TEST_MODE.
With CAN_TEST_MODE, Photon 1 would reply to itself, ignoring Photon 2.
Without CAN_TEST_MODE, can.isEnabled returned 1 and can.errorStatus returned 1 or 2. - No messages were sent
Method 3:
A single Photon was connected to an MCP 2561, which was then connected to a car’s OBDII Port.
When only attempting to read messages, the CAN was working successfully (can.isEnabled = 1, and can.errorStatus = 0)
When attempting to transmit messages, the can.errorStatus would return 1 or 2 and I could not read or write messages.
Has anyone tested whether the MCP 2561 works instead of the MCP2551?
I am new to the Photon environment and hardware, but have experience with CAN in my everyday job. Where should I begin troubleshooting?
I can post my code if necessary.
I recommend that you compare your code and your setup with carloop.io.
Carloop uses Particle devices to link into OBDII ports. The Carloop founders are also Particle people, so they definitely know their stuff. All their stuff on Carloop is opensource, so you can see how they did it and compare with yours.
With Method 2, ensure that both Photons share a common ground since you are not using CAN transceiver chips in your circuit (although that should not be an issue if the power source is the same). One other thing to look into is timing in case Photon 1 is not waiting for the return from Photon 2. Can you verify if Photon 2 is receiving the first message from Photon 1? Maybe add in some serial.print() statements that you can monitor over USB with a terminal program.
With Method 3, carloop does the same thing you are trying to do. However, I believe they are using a different transceiver (TJA1049), but the code should be very similar to what you are looking for.
I have looked into the carloop code. I have looked through the carloop source files and the examples from the site. From what I can tell, the way you send messages using carloop carloop.can().transmit(message);. I have tried to find the construction of carloop.can().transmit() but I can’t find it anywhere. The particle documentation states that can.transmit(message); is the correct syntax to send a CAN message.
Above are the important parts of my code.
The if statement returns true and the I see TX in the serial monitor but my PeakCAN monitor on the car does not see the message.
@Strefz, I may have misunderstood you the first time. I think you are looking for something lower level, such as the HAL (hardware abstraction layer) or the hardware driver firmware. If I got it right this time, then this thread will have the clues to what you are looking for. I have not delved into it that deeply, so I might not be able to offer much more than this: