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

PIC18F452 Interfacing with 4GB SD Card

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
adnan jafar



Joined: 26 Sep 2014
Posts: 11

View user's profile Send private message

PIC18F452 Interfacing with 4GB SD Card
PostPosted: Tue Dec 02, 2014 12:39 pm     Reply with quote

I want to Interface the PIC18F452 with 4GB SD Card. i used the PIC CCS library to interface it. The Problem that i am using is SD Is correctly initialized but nothing is written and read from SD Card.
I am using PIC18F452 microcontroller, PIC is running at 5V. For level conversion between SD Card and PIC, i used Resistor network that converts the PIC output pin 5v logic to 3V logic.
Here below, my Code is

++++++++++++++++++++++++
Code mostly removed.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers
http://www.ccsinfo.com/forum/viewtopic.php?t=26245
- Forum Moderator
++++++++++++++++++++++++

Code:

/////////////////////////////////////////////////////////////////////////
////                      ex_mmcsd.c                                 ////
#include <18F67J60.h> // I here used PIC18F5452
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=25M)

#use rs232(baud=9600, UART1, errors)

      if(cmd=='W') {
         printf("\r\nNew value: ");
         value = gethex();
         printf("\n\r");
         mmcsd_write_byte(address, value);
// i have added two lines below to check whether there is some thing written to that memory location or not. but when i see it at computer terminal after reading the SD Card , nothing is received just 00 even that i have entered some different value at this location
          mmcsd_read_byte(address, &value);
         printf("\r\nValue: %X\r\n", value);
         mmcsd_flush_buffer();
      }
   } while (TRUE);   
}


Kindly fix my this problem, because when i write some thing on some address on SD Card and at the same time when i try to read this memory location, nothing is read from that location just received 00. Can any one tell me that whats the problem is. or anyone kindly provide me the final SD Card interfacing code with PIC. i have exhausted all my searches and tries on it. but nothing is achieved. I have correcly verified the PIN Connection between PIC and SD Card.


Your help will be highly appreciated
Regards
Adnan Jafar
Electronics Engineer in EWI islamabad,Pakistan
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 3:07 pm     Reply with quote

To fix the problem you MUST use PROPER logic level interface between ANY 5 V PIC and the 3V mem card. YOU MUST !!

NO amount of software 'tweaking',recoding,etc. will fix the problem....

If you search this forum you'll find hundreds of postings related to this 'problem'. Bottom line is you have to read the datasheets and understand that ALL SD cards are 3 volt and will never,ever interface to 5 V PICs.

The easy 'fix' is to use a 3V rated PIC. Any that have 'L' in the part number will work as well as several PICs rated for 2-5 volts BUT check the VDD vs Freq. chart !! Usually the lower the Vdd, the slower the PIC will run.

The next 'fix' is to use proper 'logic level' translation using either a chip or discrete transistors. Regular resistors WILL NOT WORK.

Also... the drivers CCS supplies are good for 'old' mem cards, <=2GB, though there are patches listed on the forum I've never used them. For mass storage I bought Vinculum modules and did away with all the frustration of SD cards...

jay
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: PIC18F452 Interfacing with 4GB SD Card
PostPosted: Tue Dec 02, 2014 5:45 pm     Reply with quote

adnan jafar wrote:
I want to Interface the PIC18F452 with 4GB SD Card. i used the PIC CCS library to interface it. The Problem that i am using is SD Is correctly initialized but nothing is written and read from SD Card.
I am using PIC18F452 microcontroller, PIC is running at 5V. For level conversion between SD Card and PIC, i used Resistor network that converts the PIC output pin 5v logic to 3V logic.
Here below, my Code is

++++++++++++++++++++++++
Code mostly removed.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers
http://www.ccsinfo.com/forum/viewtopic.php?t=26245
- Forum Moderator
++++++++++++++++++++++++

Code:

/////////////////////////////////////////////////////////////////////////
////                      ex_mmcsd.c                                 ////
#include <18F67J60.h> // I here used PIC18F5452
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=25M)

#use rs232(baud=9600, UART1, errors)

      if(cmd=='W') {
         printf("\r\nNew value: ");
         value = gethex();
         printf("\n\r");
         mmcsd_write_byte(address, value);
// i have added two lines below to check whether there is some thing written to that memory location or not. but when i see it at computer terminal after reading the SD Card , nothing is received just 00 even that i have entered some different value at this location
          mmcsd_read_byte(address, &value);
         printf("\r\nValue: %X\r\n", value);
         mmcsd_flush_buffer();
      }
   } while (TRUE);   
}


Kindly fix my this problem, because when i write some thing on some address on SD Card and at the same time when i try to read this memory location, nothing is read from that location just received 00. Can any one tell me that whats the problem is. or anyone kindly provide me the final SD Card interfacing code with PIC. i have exhausted all my searches and tries on it. but nothing is achieved. I have correcly verified the PIN Connection between PIC and SD Card.


Your help will be highly appreciated
Regards
Adnan Jafar
Electronics Engineer in EWI islamabad,Pakistan


Did you remember to use a pull-up resistor on DO of the card?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Dec 03, 2014 1:26 am     Reply with quote

As Temtronic says level translation.

The resistors can be made to work OK, for translating the 5v PIC signals 'down' to the 3.3v SD card, but they will not handle translating the outputs from the card up to the level needed to drive the PIC....
The 5v PIC requires it's input to go up to 3.5v for the data input on the SPI bus. A 3.3v SD card cannot do this....

On Brush Electronic's site, there is an example interface.
Go to:
<http://www.smallridge.com.au/index.php?page=projects#HWREF>

Select the ethernet reference designs (4620/2620). On the third page of the circuit, there is probably about the best reference design for connecting a 3.3v SD to a 5v PIC. Shows the resistors needed, uses a 74ACT125D to give the voltage translation 'up', and shows the decoupling etc., that is needed. This design works 99.9% of the ones published on the web, don't.

The site also does rather better SD card drivers if you are prepared to pay, which are more sophisticated than the CCS ones, but the CCS ones can be made to work fine.

Unfortunately, some years ago, somebody published an interface between a 5v PIC and an SD card, using software SPI, on a TTL level input pin. This has been copied since by thousands of posters who don't realise that it won't work with the PIC SPI hardware, and results in post after post like yours.

Almost becoming a 'sticky'.
adnan jafar



Joined: 26 Sep 2014
Posts: 11

View user's profile Send private message

Interfacing of SD Card with PIC
PostPosted: Thu Dec 04, 2014 4:00 am     Reply with quote

Hello sir! i have successfully completed the read and write operation with 4GB card interfacing with PIC. but one thing i am not understood in code that from where to where address i can put value in SD card and read. i am working on logger and i need information about starting and last memory address.
can anyone help me that where in the code there is written about it.
I am using Ex_mmc.c, fat.c PIC CCS compiler Library.

Regards,
Adnan
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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