CAN with MCP2551
-
I try to use the new CAN support. The only tranciever I have access to is a couple of MCP2551. Since it is 5V I have added 2 resistors (the same way as in the drawing in the first post from "rudi ;-)" here: https://www.esp32.com/viewtopic.php?t=380&start=70)
This is the code I am using:
from machine import CAN can = CAN(mode=CAN.NORMAL, baudrate=250000, pins=('P3', 'P4')) while True: can.send(id=2, data=bytes([1, 2, 3, 4, 5, 6, 7, 8])) print("send") print(can.recv()) time.sleep(1)
Nothing is received, but I can see some signals coming from the transciever with an oscilloscope.
The frame I try to send cannot be seen on the bus, but I can see that something is transmitted to the transceiver (with an oscilloscope).
I have tried this with a LoPy and a WiPy3 and two different MCP2551.
What can be wrong? I can read data from the bus with a CAN-interface to my computer in the same connector without problem.
I am no hardware expert, anything wrong with my connections?
-
@johand Good to hear that all is working now. :o)
-
Managed to send as well, awesome!
-
I received the SN65HVD230 tranciever today (a board called CJMCU-230). I can read from the bus now (will try to send later). Must have been something wrong with my connections. Thanks!
-
I´ve tried both 10kbps and 250kbps bus speed (on an isolated bus). I know for sure that the bus speed is 250k, I can read frames with a USB CAN interface. Have tried all modes. What I have found it should be ok to connect pin 8 (RS) to GND without resistor (http://www.microchip.com/forums/m637386.aspx).
Anyway, I gave up and ordered a couple of SN65HVD230, hopefully that will solve my problem.
-
- According to http://www.learningaboutelectronics.com/Articles/MCP2551-CAN-transceiver-circuit.php it should be 10k resistor between pin 8 and GND. Anyway, it's hard to trace connections from your photo to confirm that everything is OK. Also have in mind that recommended transceiver is the SN65HVD230, but MCP2551 also should work.
- Did you try with different speed 125000 or 500000? Devices on CAN bus have to talk at the same speed, sometimes for example in Mazda there are two speeds 125k and 500k on the CAN bus.
- Did you try with
mode=CAN.SILENT
(for sniffing the bus) andframe_format=CAN.FORMAT_BOTH
(to catch 11bit (standard) and 29bit (extended) frames)?