Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    CAN with MCP2551

    Scheduled Pinned Locked Moved Discussion
    canmcp2551transceiver
    6 Posts 2 Posters 2.4k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      johand
      last edited by

      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?

      0_1516361017835_MVIMG_20180119_120544.jpg

      R 1 Reply Last reply Reply Quote 0
      • R Offline
        rskoniec @johand
        last edited by rskoniec

        @johand

        1. 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.
        2. 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.
        3. Did you try with mode=CAN.SILENT (for sniffing the bus) and frame_format=CAN.FORMAT_BOTH (to catch 11bit (standard) and 29bit (extended) frames)?

        The machine is working as good as it's code.

        1 Reply Last reply Reply Quote 0
        • J Offline
          johand
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • J Offline
            johand
            last edited by

            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!

            1 Reply Last reply Reply Quote 1
            • J Offline
              johand
              last edited by

              Managed to send as well, awesome!

              R 1 Reply Last reply Reply Quote 1
              • R Offline
                rskoniec @johand
                last edited by

                @johand Good to hear that all is working now. :o)

                The machine is working as good as it's code.

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom