Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SD card interfacing with Atmega8

Status
Not open for further replies.

sukhdeepmankoo

Member level 2
Joined
May 14, 2009
Messages
47
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
1,616
Hi,
I am trying to interface SD Card with Atmega8. I have made the following connections on hardware side.

SD Card Atmega8

Pins Pins
1)CS 16(SS)

2)DI 17(MOSI)

3)GND

4)3.24V

5)SCK 19(SCK)

6)GND

7)DO 18(MISO)

Through MicroSD Adaptor.

On software Side, I have made Atmega8's software. Where Atmega8 is operating at 8Mhz.

void spi_init(void)
{ SPI_DDR|=(1<<MOSI)|(1<<SS_LOW)|(1<<SCK);
SPI_DDR&=~(1<<MISO);
SPI_PORT|=(1<<MOSI)|(1<<SS_LOW)|(1<<SCK)|(1<<MISO);
SPI_PORT&=~(1<<SS_LOW);
SPSR|=(1<<SPI2X);
SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR1);
}
unsigned char spi_transmit(unsigned char data)
{ SPDR=data;
while(!(SPSR & (1<<SPIF)));
data=SPDR;
return data;
}
void sd_spi_init(void)
{ unsigned char count,response=0;
unsigned int retry;
/***********wait for 74 clock cycles**********/
lcd_command_register(0x01);
delay(1500);
lcd_char_display("Initialization",LINE1+3);
SPI_PORT|=(1<<SS_LOW);
for(count=0;count<10;count++)
spi_transmit(0xff);
SPI_PORT&=~(1<<SS_LOW);
spi_transmit(0x40);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0x95);
for(retry=0;retry<0xfffe;retry++)
{ response=spi_transmit(0xff);
if(response==1)
{ SPI_PORT|=(1<<SS_LOW);
break;
}
}
lcd_value_display(response,LINE4);
SPI_PORT|=(1<<SS_LOW);
spi_transmit(0xff);

SPI_PORT&=~(1<<SS_LOW);


lcd_value_display(response,LINE4);
for(retry=0;retry<0xfffe;retry++)
{ spi_transmit(0x41);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0);
spi_transmit(0xff);
response=spi_transmit(0xff);
if(response==0)
{ SPI_PORT|=(1<<SS_LOW);
break;
}
}
lcd_value_display(response,LINE4+10);
SPI_PORT|=(1<<SS_LOW);
spi_transmit(0xff);


}

I am getting 255 on LCD Screen. why SD is not able to Initialize? Kindly tell me to find where i have done mistake.

Thanks & Regards
 

Hi,

only to say you, that some cards can cause troubles.

example :

I have interfaced a sdcard DAN-ELEC with my atmega 8 ==> ERROR (error initialisation).

Voltage was 3.3v

Everything seems OK (with electronic oscilloscope) : SCK,MOSI,MISO,SS

I spend a lot of time...

Finally, I tried another SCARD , and , it was OK !! (3,3V and 5V too)

So, I'd like to find the datasheet of the sdcard DAN-ELEC 2Go, to understand what was the problem.

Perhaps no, you found the solution...

Good luck.

BErt
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top