SPI woes

Posted on
  • I've been going through hell using SPI to communicate with a digital potentiometer.

    Check this out:
    I send this to Espruino:

    var digipot=require("MCP4xxxSPI").connect(SP­I2,C4,1,128);

    so digipot.getVal(0) should return 319 (actual value is 63, but it's adding 256 to it due to a bug in my module code - not accounting for differences between parts). Look what happens!

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v69 Copyright 2014 G.Williams

    I have had it in failing state for hours, then one file system access, and bam, it's fixed.

    Module code is here:

  • Could it be to do with the SPI clock speed? The SD card code sets it to 1000000, so you could try specifying that when initialising SPI2 and see if that helps?

  • Identical behavior when I changed my code to this:

    var digipot=require("MCP4xxxSPI").connect(SP­I2,C4,1,128);

    Interestingly enough, once it has worked, reset() doesn't make it stop working. IE, if I do the above, then fs.readdir(), then press "send to espruino" again (resetting the espruino), it works immediately without having to do anything.

    It's something in the espruino - if I power cycle the part after making it with with fs, it continues to work.

  • if I power cycle the part after making it with with fs, it continues to work

    Not sure I understand what you're saying?

    I think I know what the issue is. Try changing scl: to sck: :)

    It doesn't error because it's perfectly valid to not want sck to be brought out on a pin. If you don't mention it, it won't be set up.

    Strange that reset() doesn't stop it working though. The pin states are all set back to defaults so I'm not sure I get why it would then keep going.

  • Wow...

    Just wow. If that's what it is, I hang my head in shame! That's the code I was sending, copy/pasted out and all...

    And I checked that I had the right several times, but somehow I think I got the abbreviations backwards, and was explicitly checking that I had it saying scl, because I was convinced that was what it was.

    Very expensive error - over 5 hours of time spent debugging this. I was going crazy, doing things like ohming out the wires, checking every combination of pins for shorts, etc. Had it not been for this, I'd have two more modules tested and submitted, plus more sleep.

  • :( I've done the exact same thing before too. I suppose it would make a lot of sense to actually test for unexpected things in the object and warn about it... I'll file an issue.

    In this case it makes it worse that I2C uses scl and SPI uses sck :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

SPI woes

Posted by Avatar for DrAzzy @DrAzzy