CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18F4520 SD CARD INIT PROBLEM --WITH SD CARD ADAPTER !!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
boraciner



Joined: 29 Jul 2009
Posts: 9

View user's profile Send private message

18F4520 SD CARD INIT PROBLEM --WITH SD CARD ADAPTER !!
PostPosted: Sat Jan 16, 2010 12:08 pm     Reply with quote

Hi! I'm using a sd card adapter but I cannot initialize it, I'm using 20mhz cyristal and the codes are :
Card capacity is 1gb

Code:

#include "r mmc 452.h"

#define MMC_CLK   PIN_C3
#define MMC_DI    PIN_C4
#define MMC_DO    PIN_C5
#define MMC_CS    PIN_C2



#DEFINE _CS PIN_C2

#DEFINE MAX_FILES 2 /// max number of open files
#DEFINE MMC_BUFF_SIZE 32 /// 32 for PCM


//#include <mmc_spi_rft.c>

#include <mmc_spi.c>


void main()
{

char data[512];
int16 i,j,k,l;

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(spi_master | spi_l_to_h | spi_clk_div_64 | spi_xmit_l_to_h);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_oscillator(True);



   set_tris_c(0b10010011);         //c7=rx IN, c6=tx OUT, c5 SDO OUT ,c4 SDI IN

   output_high(MMC_CS);

   printf("I HOPE IT WILL WORK  \r\r");

if(mmc_init ()!=0) printf("\r\n ERROR\r\n");
else printf("\r\n OK\r\n");
   










   while(true)
   {

   }
}



AND the header is

Code:
#include <18F4520.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected

#FUSES NOPUT                    //No Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOCPD                    //No EE protection
#FUSES NOCPB                    //No Boot Block code protection
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads

#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)





I'M WAITINg for your reply!! Thanks A LOT!!! Rolling Eyes
Xeno_jimmy



Joined: 16 Jan 2010
Posts: 1

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 1:00 pm     Reply with quote

hi
can you tell me the name of that adapter?
_________________
My Pic based applications channel:
http://www.youtube.com/user/Jimmy333x2
boraciner



Joined: 29 Jul 2009
Posts: 9

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 1:13 pm     Reply with quote

I bought it from ebay ( Gravitech )

http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=390108947839&ssPageName=STRK:MEWNX:IT

Code:
This is a simple MicroSD adapter card. It allows you to interface with any microcontrollers. It is perfect for mass storage, WAV/MP3 player and data logging. The adapter breaks out the MicroSD socket to a standard 0.1" 8-pin header. It can be plug directly onto the boardboards. This adapter features innovations that set it apart from other SD card adapter. Innovations feature like on-board card detect LED, Push-Push socket, and 3.3V regulator. Which mean either 3.3V or 5.0V microcontroller can be connected directly with the board. You can even use this 3.3V to power external circuits up to 250mA.
Pinout:

VIN: Input power to the SD card (3.3V to 6.0V)
GND: Common (Connects to the housing of the SD socket)
3V3: Output voltage from the on-board 3.3V regulator (250mA)
CS: Chip select
DI: Serial input data
SCK: Serial clock
DO: Serial output data
CD: Card detect (active low)


Features:

• On-board 3.3V regulator
• Connect directly to 3.3V or 5.0V microcontroller
• Card detect LED
• Include 8-pin male header
• Board dimension: 1.4”x0.8”





I'M still waiting for any help .. ! please help me Rolling Eyes
boraciner



Joined: 29 Jul 2009
Posts: 9

View user's profile Send private message

WITH A DIFFERENT PIC..
PostPosted: Sat Jan 16, 2010 1:38 pm     Reply with quote

I used 18F452 and I made the circuit in isis file and the codes.. but
the output doesn't come the same.. !!

my output like this:
Code:

Hadi hayirlisi UMARIM CALISIR 

cmd1cmd1cmd1cmd1cmd1cmd1cmd1cmd1cmd1cmd1Gelen Cevap: 11

HEX olarak okunan datalar                          CHAR olarak okunan datalar
04 20 00 00 00 0A 00 00 00 0A 04 00 00 02 00 00                D    €  0     00 00       00 02 00     00 00 00 00     0 00 00 00 00 14 10     1 00 04 C0 00 00 40       06 01 40 00 00 08 00 00 00         00 00 00 00 01 00 0C 00 00 00 00      08 80 08 00 A0 00 00 00 80 80 18 00     56 00 00 00 01 84 00 00 06 00 80 80 00       00 00 60 00 00 00 00 00 00 40 00 00 20 00 40 00     
06 00 82 00 04 20 20 00 00 00 01 08 10 00 00 00             À     @  4     0 20      80 00     ˆ  08 00 00 00 00           1 02 00 00 08 00      00 00 00 00 01 00 80     


the source codes and isis file
the source codes and isis file
www.dreamrobotics.com/mmc.rar
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 2:41 pm     Reply with quote

What is the Vdd voltage on the PIC, and what is the Vin voltage on the
SD/MMC adapter card ?

Also, what's the purpose of setting the #use rs232() to 9 bits ?
The standard is 8 data bits.
Guest








PostPosted: Sat Jan 16, 2010 3:21 pm     Reply with quote

there is a 5 to 3.3V voltage regulator on this card adapter. and I think that the 9 bits is not a problem 'cause the string that I wrote message to inform me via serial port does work..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 3:26 pm     Reply with quote

To repeat:

1. What is the Vdd voltage on the PIC ?

2. What is the Vin voltage on the SD/MMC adapter card ?
Guest








PostPosted: Sat Jan 16, 2010 4:17 pm     Reply with quote

Vcc is 5V its connected pic and sd adapter. Sd adapter regulates this voltage to 3.3 V in itself.So, I don't have to connect 3.3V externally to the SD card adapter
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 4:34 pm     Reply with quote

According to the MicroSD adapter schematic, it has an on-board voltage
regulator that converts the +5v input down to +3.3v. Every chip on
the board runs off +3.3v.
http://gravitech.us/MicroResearch/Others/MICROSD-ADP/MicroSD-ADP_Schematic.pdf

The schematic also shows that the Data Out pin "DO" on the SD card
connects directly to the header. This means that the "DO" signal going
to the PIC has voltage levels of +3.3v and ground.

However, your PIC is running at +5v. In the 18F4520 data sheet,
in the Overview section, it says that the PIC's SDI pin has a Schmitt
Trigger input "ST". In the Electrical Characteristics section, it says
that the "Input High Voltage" "Vih", must be at least 0.8 x Vdd.
In your case, with a +5v Vdd, the Vih must be at least 4.0v, but your
Micro-SD adapter only puts out 3.3v max as the Vih. Therefore it won't
work.
Guest








PostPosted: Sat Jan 16, 2010 4:41 pm     Reply with quote

owww.. you're the Master!
Sir, now... how can I supply that voltage level?
Can I take 3.3V from the adapter in any way?
Guest








PostPosted: Sat Jan 16, 2010 4:44 pm     Reply with quote

If I apply a resistor ,can I decrease the voltage level?
boraciner



Joined: 29 Jul 2009
Posts: 9

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 4:48 pm     Reply with quote

there is a voltage regulator on the board. so, I can directly connect the 5V then It works .
I also talked with the seller about it ,he says that I don't have to supply 3.3v
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 4:49 pm     Reply with quote

What type of 18F4520 PIC do you have ? Do you have the normal "F"
version or do you have the 18LF4520 ? Look at the top of the
chip and see. If you have the LF version, you could run the PIC at +3.3v.
It would work with the MicroSD adapter. The only other problem would
be the serial port connection to the PIC. It would have to work with
the +3.3v cmos levels to/from the PIC.

-or-

Do you have any logic gate chips available in the "HCT" or "ACT", etc.,
families ? Something like 74HCT125A, or 74HCT08, or even 74HCT04 ?
If you so, you could run that chip at +5v, and use it as a level translator.
You could put the MicroSD's +3.3v SDO signal into it and you would get
+5v cmos levels as the output. This +5v cmos SDO signal could then go
to the PIC's SDI pin. Then it would work.

If you use the 74HCT04, you would need to put two gates in series, so
there would be no inversion, overall.
boraciner



Joined: 29 Jul 2009
Posts: 9

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 4:56 pm     Reply with quote

It's a property of this board.. my seller said
Code:
Dear boraciner,

Just the 5V is enough. There is an on-board 3.3V regulator so you don't need to supply 3.3V.

Tony
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 16, 2010 5:19 pm     Reply with quote

Your MicroSD board runs at +3.3v. We already established that.

The problem is that the PIC (running at +5v) requires at least a 0 to 4v
signal coming into its SDI pin. Your MicroSD board only puts out 0 to
3.3v.

Therefore, a level translator is needed between the MicroSD board and
the PIC for that one signal.

I suggest that you order a 74HCT125 chip and use it as a level translator.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group