Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Configuring TWI Communication

    Scheduled Pinned Locked Moved
    Tuning and tweaking
    2
    12
    1.4k
    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.
    • jmlundefined
      jml
      last edited by

      I'm trying to set up TWI communication. I assume that is what Wire.cpp and Wire.h are for. Does anyone have an example they can show where they configured and used it? I'm not sure what values to put in TWI_ConfigureMaster( , ) or if I need to execute other functions prior to using it.

      Edit: I've used Wire with Arduino successfully before, but it took me a while to get it right. And this Wire library is different, so I'd appreciate any help setting it up.

      1 Reply Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators
        last edited by

        There is already code that drives the TWI interface in the source code. it's in the files that interface to DueX expansion boards and external SX1509B devices, in the /src/DuetNG subfolder.

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        1 Reply Last reply Reply Quote 0
        • jmlundefined
          jml
          last edited by

          Thanks. Two questions:

          1. I notice that there are "slashes" through the DuetNG folder and the files inside it. The Duet folder is not slashed. Is that a problem?

          https://pasteboard.co/H0rO8cu.jpg

          2. To use it in Gcodes2.cpp, I do the following:
          #include Wire.h"
          …
          then within a custom g-code, I write:

          [[c++]]
          uint16_t val = ( (int) (5.3 + 0.5)) ; // rounding of a input value (normally a float, but set as 5.3 for testing)
          Wire.begin();
          Wire.beginTransmission(0x80); // address of TWI device
          Wire.write(0x30); // tells device what to do with the next incoming byte
          Wire.write(val/16); // upper data bits
          Wire.write((val%16) << 4); // lower data bits
          Wire.endTransmission();
          
          

          I get no error when compiling. But I do not get any response from the TWI device as expected. I had identical code in Arduino when I had it working there. Is there a way to scan the I2C devices? (btw, I have it hooked up according to the V0.8 Duex5 pin diagram and not based on the incorrectly labelled pcb silkscreen)

          1 Reply Last reply Reply Quote 0
          • jmlundefined
            jml
            last edited by

            Based on oscilloscope readings, it looks like Wire.beginTransmission does send the address to the SDA pin.

            If I only use Wire.write once after Wire.beginTransmission,, it does not result in any more data being sent.

            If I use Wire.write twice, then another chunk of data is sent, but the data is equal to the address.

            If I use Wire.write 3 times after beginTransmission, then 3 chunks of data are sent, but the data is equal to the beginTransmission address, no matter what I put in Wire.write().

            Any idea what is going on?

            1 Reply Last reply Reply Quote 0
            • jmlundefined
              jml
              last edited by

              Learning this as I go.

              For each sent byte, I am seeing a 1 in the ACK position, so I don't think it has anything to do with the Duet… must be the slave.

              1 Reply Last reply Reply Quote 0
              • jmlundefined
                jml
                last edited by

                Problem was a solder joint. Fixed!

                1 Reply Last reply Reply Quote 0
                • dc42undefined
                  dc42 administrators
                  last edited by

                  @jml:

                  Thanks. Two questions:

                  1. I notice that there are "slashes" through the DuetNG folder and the files inside it. The Duet folder is not slashed. Is that a problem?

                  https://pasteboard.co/H0rO8cu.jpg

                  That means the current configuration you have selected in Eclipse is not Duet WiFi or Duet Ethernet. The other boards supported by RRF do not use that folder. If you are using one of the older Duets, look in file src/Duet/MCP4461.cpp instead. In that file you will see that the available TWI interface on the older boards is Wire1 not Wire.

                  EDIT: our posts crossed.

                  Duet WiFi hardware designer and firmware engineer
                  Please do not ask me for Duet support via PM or email, use the forum
                  http://www.escher3d.com, https://miscsolutions.wordpress.com

                  1 Reply Last reply Reply Quote 0
                  • jmlundefined
                    jml
                    last edited by

                    Thanks dc42. If you could help me figure out the "slashes," that would be great. Am I able to build correctly even though the slashes are there?

                    When I build CoreNG, I click the hammer, but only SAM4E8E is check-marked:
                    https://pasteboard.co/H0GhCtw.jpg

                    When I build RepRapFirmware, only DuetWiFi is check-marked.

                    The hardware I am using Duet Wifi V1.02, Duex5 V0.8. And PanelDue. According to what it shows in DWC, the RRF firmware is 1.20beta6+1 (2017-11-09),

                    In Eclipse in the RepRapFirmware folder, the only ones crossed off are within the src folder: Alligator, DuetNG, and RADDS.

                    In the CoreNG folder, many are slashed, so I just took screenshots and you can see them in the links:
                    https://pasteboard.co/H0GfNiR.jpg
                    https://pasteboard.co/H0Gg2kT.jpg
                    https://pasteboard.co/H0GgbO0.jpg
                    https://pasteboard.co/H0Ggu5i.jpg

                    How to fix this? Does it even need fixing? I can print, and the TWI device works fine now. I do plan to make many more changes to the firmware though.

                    1 Reply Last reply Reply Quote 0
                    • dc42undefined
                      dc42 administrators
                      last edited by

                      The slashes indicate that the folders concerned are excluded from the build in the active configuration. To change the active configuration, right click on the project, select Build Configurations, then Set Active.

                      Duet WiFi hardware designer and firmware engineer
                      Please do not ask me for Duet support via PM or email, use the forum
                      http://www.escher3d.com, https://miscsolutions.wordpress.com

                      1 Reply Last reply Reply Quote 0
                      • jmlundefined
                        jml
                        last edited by

                        I right click on the CoreNG folder in the Navigator, and I go to Build Configurations > Set Active … and I can see that SAM4E8E is selected.

                        I do the same for the RepRapFirmware folder, and I see that it is set to DuetWiFi.

                        Those are correct, aren't they?

                        1 Reply Last reply Reply Quote 0
                        • dc42undefined
                          dc42 administrators
                          last edited by

                          Yes they are. If you have SAM4E8E as the active configuration in CoreNG, then with the variants folder, duetNG should be enabled and the other variants should have a slash through them.

                          There is a bug in Eclipse whereby occasionally it doesn't display an enabled folder but instead shows an extra copy of one of the disabled folders. It doesn't seem to affect building.

                          Duet WiFi hardware designer and firmware engineer
                          Please do not ask me for Duet support via PM or email, use the forum
                          http://www.escher3d.com, https://miscsolutions.wordpress.com

                          1 Reply Last reply Reply Quote 0
                          • jmlundefined
                            jml
                            last edited by

                            Hmmm, I have SAM4E8E active, but duetNG in the variants folder is slashed. Only duet is non-slashed. Maybe its another bug, hopefully in just the display of the folders.

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Unless otherwise noted, all forum content is licensed under CC-BY-SA