Issue With SD Card

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
TheLearner
 
Posts: 10
Joined: Fri Mar 17, 2023 2:58 am

Issue With SD Card

Post by TheLearner »

Hello,
I am using a Feather M4 Express in conjunction with an Adalogger Featherwing to store collected data on a microSD card (swissbit 512 MB). The circuit I am using this in collects data from 8 sensors over SPI (and uses a line decoder - which takes 4 inputs to select one of 16 outputs - to generate the chip select signal) and 2 sensors over I2C. The SPI and I2C measurements are solid. The issue I am having is that when I run the code to initialize the SD card, I get the error message "OSError: Couldn't determine SD card version". What's weirder is that when I disconnect the MISO and SCK lines (the sensors have no MOSI pin), the SD card works perfectly. I am perplexed by this since I then connected the Feather/Featherwing assembly to an SPI circuit with just one sensor and that worked fine. To troubleshoot, I measured the voltage at each chip select pin and found that one of the sensors was at 1.2 V instead of 3.3 V during initialization of the SD card, but when I hardwired this chip select pin and ran the code again, I got the same error message (and yes, I did recheck all remaining chip select pins after this rerun). I have tried placing the initialization of the SD card before and after setting all chip select pins low, but to no avail. Any ideas of what I should try next?

Here is a snippet of my code for the 10 sensor setup. The error occurs at "sdcard = sdcardio.SDCard(spi, SD_CS)" - the third to last line.

Code: Select all

import board
import busio
import digitalio
import time
import adafruit_tmp117
import adafruit_mprls
import sdcardio
import microcontroller
import storage

# Use Pin A1 on Feather for Data 1 pin on Line Decoder
cs1 = digitalio.DigitalInOut(board.A1)
cs1.direction = digitalio.Direction.OUTPUT
cs1.value = False

# Use Pin A2 on Feather for Data 2 pin on Line Decoder
cs2 = digitalio.DigitalInOut(board.A2)
cs2.direction = digitalio.Direction.OUTPUT
cs2.value = False

# Use Pin A3 on Feather for Data 3 pin on Line Decoder
cs3 = digitalio.DigitalInOut(board.A3)
cs3.direction = digitalio.Direction.OUTPUT
cs3.value = False

# Use Pin A4 on Feather for Data 4 pin on Line Decoder
cs4 = digitalio.DigitalInOut(board.A4)
cs4.direction = digitalio.Direction.OUTPUT
cs4.value = False

# Use Pin A5 on Feather to toggle the Inhibit pin on Line Decoder
# Set Inhibit to True when not making measurements
# Set Inhibit to False after setting binary input for desired sensor
INH = digitalio.DigitalInOut(board.A5)
INH.direction = digitalio.Direction.OUTPUT
INH.value = True

# Use Pin A0 on Feather to control Strobe on Line Decoder
# Set Strobe low to latch Line Decoder Output
# Set Strobe high to unlatch outputs
STR = digitalio.DigitalInOut(board.A0)
STR.direction = digitalio.Direction.OUTPUT
STR.value = True

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)

# Configure SD Card
SD_CS = board.D10
sdcard = sdcardio.SDCard(spi, SD_CS)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

User avatar
barshatriplee
 
Posts: 200
Joined: Wed Mar 22, 2023 10:11 am

Re: Issue With SD Card

Post by barshatriplee »

Make sure that there are no conflicts in pin usage between the SD card and other sensors. It's possible that there may be a conflict on one of the shared pins.I think you need to check inside all the libraries that you are using.

User avatar
TheLearner
 
Posts: 10
Joined: Fri Mar 17, 2023 2:58 am

Re: Issue With SD Card

Post by TheLearner »

If I am understanding you correctly, it seems you are suggesting that the library for sdcardio uses a pin that I am using to send an input to the line decoder. To test this claim, I tried placing the block of code that configures the SPI bus/the SD card before my initialization of all my pins for the line decoder (ex. I took the code for the SPI bus and the last block of code and moved all that immediately after all my import statements) and still got the same error message. I also tried placing my Feather/Featherwing assembly in a circuit with just one sensor and running my code shown in my previous message (with pin initialization before SPI bus/ SD card pin initialization) and got no error message. Does this rule out the conflicting pin theory or have I misunderstood your suggestion?

User avatar
TheLearner
 
Posts: 10
Joined: Fri Mar 17, 2023 2:58 am

Re: Issue With SD Card

Post by TheLearner »

To be sure, I also tried hardwiring all CS pins to HIGH instead of to the output of the line decoder and running my code with the initialization of the SPI bus/SD card first and still got the same error message.

User avatar
TheLearner
 
Posts: 10
Joined: Fri Mar 17, 2023 2:58 am

Re: Issue With SD Card

Post by TheLearner »

Today I tried removing the Line Decoder from the circuit and hardwiring all the CS pins high, but still received the same error message when trying to initialize the SD card using sdcardio.

One other observation I had was when I disconnected the MISO line from half of the sensors. This gave me a different result. The SD card initialized. I then wrote a header to a txt file on the SD card using the code

Code: Select all

with open("/sd/BLDS_TestData.txt", "w") as f:
    f.write("P0[mbar], P1[mbar], P2[mabr], P3[mbar], P4[mbar], P5[mbar], P6[mbar], P7[mbar], P_abs[hPa], T[C]\n")
This worked fine. Then I collected a set of measurements and tried saving them to the file on the SD card using

Code: Select all

with open("/sd/BLDS_TestData.txt", "a") as f:
    f.write("%0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f, %0.2f\n" % (P0,P1,P2,P3,P4,P5,P6,P7,p_abs,t))
An error arises on the line that opens the file. The error is "OSError: [Errno 116] ETIMEDOUT". I have also tried writing instead of appending and get the same error message.

I guess my two questions are:
1. Why would the SD card initialize when half of the sensors are disconnected from MISO?
2. What am I supposed to glean from the timed out error message?

User avatar
TheLearner
 
Posts: 10
Joined: Fri Mar 17, 2023 2:58 am

Re: Issue With SD Card

Post by TheLearner »

I have not received a reply in a month and am still stumped on this issue. Does anyone have any suggestions?

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”