Multiple SPI Devices

Posted on
  • Should we not be able to have multiple spi devices on the same channel and separately called (CS) ? I have a temperature sensor MAX32855 and a sd card on a Pico. The intent is to have a few temperature sensors recording data to the sd card. Anyways here is the code:

    SPI1.setup({sck:A5, miso:A6, mosi:A7, baud:1000000 });
    
    var max=require("MAX31855").connect(SPI1,B10­/*CS*/);
    console.log(max.getTemp());
    
    E.connectSDCard(SPI1,B1/*CS*/);
    console.log(require("fs").readdir()); 
    

    The problem is that the temps usually read fine (though sometimes they give random really high readings?) but when I access the sd card it errors

    ERROR: Unable to mount SD card : NOT_READY
    undefined
    

    As soon as I disconnect the MAX31855 then the sd card works fine.........??

  • Hum, that should definitely work.... Try digitalWrite()ing the cs Pins high before initializing the spi devices? In case they're floating and that's confusing the parts...

  • Tried a few combinations including writing cs to 0.

    digitalWrite(B1,1);
    digitalWrite(B10,1);
    
    SPI1.setup({sck:A5, miso:A6, mosi:A7, baud:1000000 });
    
    var max=require("MAX31855").connect(SPI1,B10­/*CS*/);
    console.log(max.getTemp());
    
    E.connectSDCard(SPI1,B1/*CS*/);
    console.log(require("fs").readdir()); 
    
    >echo(0);
    { "temp": 63.5, "fault": 0 }
    ERROR: Unable to mount SD card : NOT_READY
    undefined
    =undefined
    >digitalWrite(B1,0)
    =undefined
    >digitalWrite(B10,0)
    =undefined
    >digitalRead(B1)
    =1   // this is the sd card that we are having trouble with
    >digitalRead(B10)
    =0
    >console.log(max.getTemp());
    { "temp": 26, "fault": 0 }
    =undefined
    >console.log(require("fs").readdir());
    ERROR: Unable to mount SD card : NOT_READY
    undefined
    =undefined
    >digitalWrite(B1,1)
    =undefined
    >digitalWrite(B10,1)
    =undefined
    >digitalRead(B10)
    =1
    >digitalRead(B1)
    =1
    >console.log(max.getTemp());
    { "temp": 26.25, "fault": 0 }
    =undefined
    >console.log(require("fs").readdir());
    ERROR: Unable to mount SD card : NOT_READY
    undefined
    =undefined
    >digitalRead(B1)
    =1
    >digitalRead(B10)
    =1
    
  • Hmm, not sure what to suggest - it's not that it's intermittent? The SD card just refuses to work if the MAX31855 is connected?

    Are you using the MAX31855 on some kind of module? I'm wondering if maybe the module has level shifting circuitry that doesn't respect the value of CS - so it's always trying to put a voltage on the data line.

    I guess one way to check would be to leave the MAX31855 connected, but to disconnect just the data out line.

  • Attached is a picture of the unit. It is for two thermocouples. I disconnected the cs line and it still sends back data.


    1 Attachment

    • max31855.jpg
  • What if you disconnect SO? Does the SD card work then?

  • Yes it does!?.......

    >echo(0);
    { "fault": 7 } // error code for MAX31855 
    [
      "._.Trashes",
      "LOST.DIR",
      ".Trashes",
      ".Spotlight-V100",
      "hello.txt",
      "hello.csv",
      "DCIM",
      "MISC"
     ]
    =undefined
    
  • Ok, I think I know your problem. You've connected CS0 to B10, but have left CS1 disconnected?

    From the board it looks like there is no pull-up, so if you leave it disconnected it could be any value at all, which means that the second chip is probably trying to use the data pin occasionally - which might also explain your occasional bad readings.

    Try connecting CS1 to 3.3v. And if it still fails try disconnecting CS0 from B10 and connect it to 3.3v as well. That will stop the sensor working, but it'd be interesting to see if the SD card started working.

    Just so you know though:

    • When you do digitalRead(B10) to check it in your example above, that turns the output back into an input - so the value you read may not be the value that was on the pin - and it'll also then allow the CS pin to go to random values.
    • You can always just use software SPI on any pins of the Pico. It might be easier than trying to share pins between the SD card and the sensor)
  • Alrighty then....that worked! Thank you. Good to know.

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

Multiple SPI Devices

Posted by Avatar for Cale @Cale

Actions