Shop OBEX P1 Docs P2 Docs Learn Events
5 volt SD card not working with level shifter — Parallax Forums

5 volt SD card not working with level shifter

Boblow45Boblow45 Posts: 7
edited 2015-02-03 06:46 in Propeller 1
Hi Guys/Girls

I am currently working with a old SD card module that works on 5 volts. I am using two ''cd40109be'' chips for level shifting. I have sent PWM signals through each of the level shifting chips to see if they work correctly, the PWM worked as expected. I am stepping the ''SS,SCK and MOSI'' signals up to 5 V and the MISO down to 3.3 V so i can interface with the module. The SD card module is part of my introduction kit I got with my Arduino. The ''sd_mount'' function is not returning 0 as expected, but is returning 6. My code is as follows:-
/*
  SD Minimal.side


  Create test.txt, write characters in, read back out, display.
*/


#include "simpletools.h"                      // Include simpletools header    


int MOSI = 22;
int SCLK = 23;
int MISO = 24;
int SS   = 25;      // SD card pins on Propeller BOE


// DO  = MISO
// DI  = MOSI
// CLK = SCLK
// CS  = SS


// grey wire is MISO:     pin 24
// brown wire is SCLK:    pin 23 
// black wire is SS:      pin 25
// yellow wire is MOSI:   pin 22
 int pinRed = 22; 
  
int main(void)                                // main function
{
  
  //sd_mount (int doPin, int clkPin, int diPin, int csPin)




 int mout = sd_mount(MOSI, SCLK, MISO, SS);              // Mount SD card
 
 print("%d \n", mout);  
  FILE* fp = fopen("test.txt", "w");          // Open a file for writing
  fwrite("Testing 123...\n", 1, 15, fp);      // Add contents to the file
  fclose(fp);                                 // Close the file
 
  char s[15];                                 // Buffer for characters
  fp = fopen("test.txt", "r");                // Reopen file for reading
  fread(s, 1, 15, fp);                        // Read 15 characters
  fclose(fp);                                 // Close the file


  print("First 15 chars in test.txt:\n");     // Display heading
  print("%s", s);                             // Display characters
  print("\n");  








while (1)
{
}
    return 0;
  
 
  
/*
while (1)
{  
pwm_start(1000);
pwm_set(pinRed,1,500) ; 
//pwm_set(pinGreen,1,500) ; 
pause(500);


pwm_set(pinRed,1,000) ; 
//pwm_set(pinGreen,1,000) ; 
pause(500);


pwm_set(pinRed,1,000) ; 
//pwm_set(pinGreen,1,000) ; 
pause(500);
pwm_stop();
}
 */


}  

Comments

  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-01-29 09:32
    Does it work without a level shifter? I've never heard of an SD card needing a level shifter.
  • MauvaiMauvai Posts: 45
    edited 2015-01-29 09:44
    (I am working with Boblow45)
    The SD module was designed for an arduino, which obviously has its I/O pins operating at 5V. We tried originally wiring it without level shifters and got no response. as it required a 5V rail, we assumed the PCB circuitry dropped it to 3.3V, and that it required 5V I/O signals. This obviously didn't work

    Having scoped the pins this morning, it seems that the pins connected to the module aren't firing - the CLK line, for instance, flashes high briefly and then stays low. There is no communication with the module. About the only thing we haven't tried is a logic analyser
  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-01-29 13:45
    I suspect that the cd40109b can't switch fast enough. The specs say that at with 5V signals with a 10V power supply, the transition time is typically 100ns and can be up to 200ns. You're giving it 3.3V signals and a 5V power supply, so it's probably even slower than that. The propeller is switching your level shifter's inputs faster than it can switch its outputs (and vice-versa in the opposite direction), garbling all of the data.
  • MauvaiMauvai Posts: 45
    edited 2015-01-29 13:52
    Is the prop spi library not limited to 900kHz? far slower than 100ns delay
  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-01-29 14:10
    The delay is more than 100ns because you're powering it at less than 10V. Also, your chip might be from near the edge of the die it was made from, meaning it could be even worse.

    I'm pretty sure the simpletools SD card library is faster than 900kHz. There's a generic C SPI driver that can only do 900kHz, but there are SD card specific SPI drivers written in PASM that can do around 20Mb/s (50ns/bit) IIRC, and I can't imagine that simpletools doesn't use them.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-01-29 16:08
    The delay is more than 100ns because you're powering it at less than 10V. Also, your chip might be from near the edge of the die it was made from, meaning it could be even worse.

    I'm pretty sure the simpletools SD card library is faster than 900kHz. There's a generic C SPI driver that can only do 900kHz, but there are SD card specific SPI drivers written in PASM that can do around 20Mb/s (50ns/bit) IIRC, and I can't imagine that simpletools doesn't use them.

    I've scoped the Parallax SD utilities. They run at 4 MHz. Interestingly enough - I think it even *starts* at 4 MHz instead of the required < 400 kHz - but I could be wrong on that.

    PropWare's SD classes are no where near complete, but they are good enough to at least test your level shifter and the clock speed is configurable from 0 to 900 kHz. You could set the speed to 200 Hz if you really wanted. That might provide you a way to test it out.
  • MauvaiMauvai Posts: 45
    edited 2015-01-29 16:12
    Ah. That may well be it so. gonna have to buy different level shifters from america so >< That or get a different SD card reader from somewhere....
  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-01-29 19:00
    You'd probably be better with a normal SD card reader. There are less parts to break.
  • MauvaiMauvai Posts: 45
    edited 2015-01-29 19:03
    Ideally, but getting parts here is awkward. We are limited in who we are able to buy from - parallax, for instance, is not an option, unfortunately.
  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-01-30 09:24
    Could you somehow bypass the level shifters on the board you already have?
  • MauvaiMauvai Posts: 45
    edited 2015-02-01 13:31
    Sorry for taking so long to get back
    Could you somehow bypass the level shifters on the board you already have?

    Yeah, we tried that (its only a breadboard atm) - didnt work. Theres a new level shifter on the way.

    Random though: is the prop sd library expected and SDHC card instead of SD?
  • MauvaiMauvai Posts: 45
    edited 2015-02-03 06:46
    RobertPam wrote: »
    There are two rules of outpost with the scot corporation in Poland but with advance or our income is exempt from assessment and the sense of right of correlated inference (the takings is taxed in Poland). These rules apply to the basic forms of employment, such as not. Polish suite working abroad. Lessen us therefore several European countries in which we exploit and what sort of excise in Poland us then applies: Belarus (released), Czech Republic (released), pit 2014 rozliczenie Denmark (taxed), France (released), Greece (released), the Netherlands (taxed), Ireland (released), Iceland (taxed), Lithuania (released), Italy (released), Agreed Bailiwick (released), on the internet you intent get back a crowded columnar list of stage taxation of 19 April 2010. oecumenical Deal potent us that concerns us correlated diminution requires us we in the levy year in Poland also scrawled proceeds from widely (all things considered printed T-36 and Annex T / ZG). When it comes to tax countdown, here, we want to regard it. We knock off burden in the surroundings in which the dimensions earning no more than the pressure that we transmit in Poland. Reward that the octroi replace from abroad is also taxed in Poland. Reimbursement is added to all income received from abroad. DITCH / ZG is needed in the Annex to exact returns: PIT-36, PIT-36L, T-38 and T-39. We need to seize it one at a time to each encumbrance return if you bear several. The requirement to put out printing depends of way on the territory of cradle of our income. Foreigners working in Poland does not be undergoing the constraint to make the DITCH / ZG. Printing is made singly for each motherland in which we received earnings.

    I think you will find you have commented in the wrong thread/forum.... at least, I'm assuming you have, or i know a lot less than I though about SD cards
Sign In or Register to comment.