SPI\SD Card Query

Status
Not open for further replies.
Nothing leaps out, can we take a look at the circuit?

Your SD logic seems ok (apart from the MISO).

Mark
 
Hang on, am I reading your MISO right - is it all 0xFF's. do you have your MISO set as an input?


Is this a PIC?

Mark

p.s. nice logic analyzer by the way
 
Last edited:
Here's the circuit for the full size SD breakout board. I made this a couple years ago and never got around to it again, so it's kinda messy, but I've confirmed all the pins connect properly. The pullup resistors on the MISO and MOSI lines in the schematic are not attached on the board, so they are not active. Pullups for line 8 and 9 are attached.

Otherwise the other side of the lines are connected directly to the uC. There is obviously nothing wrong with the CLK, SS, and MOSI lines as they are working fine. I would think that even if there was an issue with the MISO line, I would still see data transmitted on the Logic, it just wouldn't process on the uC. For some reason that data line is just held high.

**broken link removed**
 
Last edited:
Yes, MISO is an input. It's a hardware SPI block and I just set it to go. I will double check everything in the code to make sure I'm not resetting that pins function or anything.

If I disconnect MISO from the uC all together, I get the same result. MISO is held high the entire time.

This is not a PIC, it's a Z8 Encore.
 
Remember the SPO on the SD card is driven not open collector so pullups won't help.

Sparkfun uses this design on one of their level converter designs.
**broken link removed**
 
Last edited:
Thanks Bill, I can't easily source a BSS138 - would any n-channel mosfet do the trick. (sorry I barely understand trasnsistor operation)

Mark
 
I Like the mosfet solution, for my solution i would only be using one "bit" of the 74x125 (that if i understand it's operation).

Mark
 
I still haven't figured this out. I even pulled the shield off of the card slot to make sure the contacts were touching the right spots on the card and detect continuity all the way from the contact to the uC pin.

I'm going to leave this for a while and work on some other projects.

I realized my setup picture above points to my Logic analyzer screen shot.
**broken link removed**
 
Well you will need a level shifter when using the SPI in hardware for the SDI pin. 3.3V is just not high enough for the Schmitt inputs on a 5V PIC. I'd have to check the datasheet but I recall it's something like VCC-0.8 (4.2V) is a 1.

Hi Bill,

I have had a look at the data sheet but the page doesnt make a lot of sense.

What does it mean?

Thanks

Mark
 

Attachments

  • 18f2550-DC-Characteristics.JPG
    76.4 KB · Views: 272
Last edited:
To better explain that page. It basically shows you the voltage at any given pin (left side aka characteristics) .

So you look for the pin in question in this case I/O PORTS (Except RC4/RC5 in USB MODE)

Then you figure out if its a SCHMITT PIN or TTL or is it RC3 and RC4

If its a SCHMITT pin then the LOW = VSS to .2 from VDD (1v)
The SCHMITT pin HIGH = .8(4v) from VDD to VDD itself (if a pic with 5v source then 5v)

As bill said below:
.8v * 5v = 4v (HIGH)
.2v * 5v = 1v (LOW)
 
Last edited:
I found my problem. Phase was set incorrectly, so it was clocking data in and out on the wrong edges. I knew it was something stupid like this.

Thanks for giving it a look.
 
Remember the SPO on the SD card is driven not open collector so pullups won't help.

Sparkfun uses this design on one of their level converter designs.
**broken link removed**

Ok, just pretend I know very little about electronics (there already? good ).

I have just grabbed a spare breadboard and wired up the above circuit with a 5 volt and 3 volt regulator, I wasn't able to source a BSS138 but used a 2N7000 (literally because they are both n-channel mosfet - I still don't understand mosfet operation at all)

With a multimeter and with no inputs on TX-3.3V I measured 3.3 volts on TX-3.3V and 5 volts on TX-5V.

Is this correct? I am guessing yes, but please correct me.

Next, I ground the TX-3.3V . I now measure 0 volts on TX-3.3V and 0 volts on TX-5V.

Is this correct? is this what Bill described as:-
the SPO on the SD card is driven not open collector

Thanks in advance.

Mark
 
regarding interfacing sd card

**broken link removed**

this is the circuit diagram i followed, and my code is

#if defined(__PCM__)
#if defined(__PCH__)
#endif
#endif

#include <stdio.h>
#include <string.h>
#include <mmcsd.c>
#include <input.c>
#fuses XT,NOWDT,NOPROTECT,NOLVP

#use delay(clock=4000000)
#use standard_io(B)
#use standard_io(C)
#use standard_io(D)


#define LCD_ENABLE_PIN PIN_B0
#define LCD_RS_PIN PIN_B2
#define LCD_RW_PIN PIN_B1
#define LCD_TYPE 2

#define SPI_SDI PIN_C4 //PIN 23
#define SPI_SDO PIN_C5 //PIN 24
#define SPI_SCK PIN_C3 //PIN 18
#define SPI_SS PIN_C2 //PIN 07

#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)


void lcd_init();
void lcd_cmd(cmd);
void lcd_data(data);
void nibbel_split(unsigned long DataIn);

int mmc_init();
int mmc_response(unsigned char response);
int mmc_get_status();
int mmc_write_block(unsigned long block_number);
int mmc_read_block(unsigned long block_number);



unsigned char cmd,data;
int i,j=0;
int res,rcvdat;
char send_data[]={"TRANSINNOVA INSTRUMENTS PVT LTD"};
int read[32];
int DDLN,DDUN,LN,UN;
int errvalue;

void main()
{

set_tris_b(0x00);
set_tris_d(0x00);
set_tris_c(0x10);

lcd_init();
lcd_data((mmc_init()+0x30));
output_low(PIN_C2);
}

int mmc_init()
{

setup_spi(SPI_MASTER|SPI_MODE_0|SPI_CLK_DIV_16);

output_high(PIN_C2); // set high slave select signal before sending cmd0
output_high(PIN_C5);

for(i=0;i<10;i++) // initialise the MMC card into SPI mode by sending clks on
{
SPI_WRITE(0xFF);
}

output_low(PIN_C2);

spi_write(0x40);
spi_write(0x00);
spi_write(0x00);
spi_write(0x00);
spi_write(0x00);
spi_write(0x95);

if( mmc_response(0x01)==1)
return 1 ;

i = 0;
while((i < 255) && (mmc_response(0x00)==1)) // if = 1 then there was a timeout waiting for 0x01 from the mmc

// must keep sending command if response
{
SPI_WRITE(0x41); // send sd command 41 to bring out of idle state
SPI_WRITE(0x00); // all the arguments are 0x00 for command one
SPI_WRITE(0x00);
SPI_WRITE(0x00);
SPI_WRITE(0x00);
SPI_WRITE(0xFF); // checksum is no longer required but we always send 0xFF
i++;
}
if(i >= 254)
return 1; // if >= 254 then there was a timeout waiting for 0x00 from the mmc


OUTPUT_HIGH(PIN_C2); // set SS = 1 (off)

SPI_WRITE(0xFF); // extra clocks to allow mmc to finish off what it is doing

OUTPUT_LOW(PIN_C2); // set SS = 0 (on)

SPI_WRITE(0X7A);
SPI_WRITE(0X00);
SPI_WRITE(0X00);
SPI_WRITE(0X00);
SPI_WRITE(0X00);
SPI_WRITE(0XFF);


OUTPUT_HIGH(PIN_C2); // set SS = 1 (off)
SPI_WRITE(0xFF); // extra clocks to allow mmc to finish off what it is doing
OUTPUT_LOW(PIN_C2); // set SS = 0 (on)
if((mmc_response(0x00))==1)
return 1;
OUTPUT_HIGH(PIN_C2); // set SS = 1 (off)

return 0;
}
int mmc_response(unsigned char response)
{
unsigned long count = 0xFFFF;

while(SPI_READ(0xFF) != response && --count > 0);
if(count==0) return 1; // loop was exited due to timeout
else return 0; // loop was exited before timeout
}
void lcd_init()
{
cmd=0x38;
lcd_cmd(cmd);
delay_ms(250);
cmd=0x0E;
lcd_cmd(cmd);
delay_ms(250);
cmd=0x01;
lcd_cmd(cmd);
delay_ms(250);
cmd=0x06;
lcd_cmd(cmd);
delay_ms(250);
return;
}
void lcd_cmd(cmd)
{
output_d(cmd);
output_low(PIN_b2);//rs
output_low(PIN_b1);//read write
output_high(PIN_b0);
delay_ms(250);
output_low(PIN_b0);//enabel
return;
}
void lcd_data(data)
{
output_d(data);
output_high(PIN_b2);//rs
output_low(PIN_b1);//read write
output_high(PIN_b0);
delay_ms(250);
output_low(PIN_b0);//enabel
delay_ms(250);
return;

}


i am expecinh 0x00 in my lcd display it shows blank or i am suspecting that my sd card is working or not. if any one having the test program kindly send to me.kindly help me out of this problem.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…