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 support@ccsinfo.com

pic18f45k22 and MMC SD

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



Joined: 16 Mar 2009
Posts: 29

View user's profile Send private message

pic18f45k22 and MMC SD
PostPosted: Fri Apr 22, 2011 2:54 am     Reply with quote

Hi all.
I want to test reading/writing on a SD Card (tried 16MB and 1GB) with a pic18f45k22 running at 3,3v. I'm using pulldown and pullup resistors (http://2.bp.blogspot.com/_meF1KpGU79k/S_csFZP7s6I/AAAAAAAAAUM/0mM7eLn7uWg/s1600/PIC18F2550+WAV+Player.jpg).

The pic stop working on write command.


This is my code
Code:

#include <main.h>

#use fast_io(D)
#define MMCSD_PIN_SCL     PIN_D0 //o
#define MMCSD_PIN_SDI     PIN_D4 //i
#define MMCSD_PIN_SDO     PIN_D1 //o
#define MMCSD_PIN_SELECT  PIN_D6 //o
#include <mmcsd.c>

#define LED1   PIN_A0
#define LED2   PIN_A1
#define DELAY  500

void main()
{
   BYTE value = 0x01010101;
   BYTE valuer;
   int32 address = 0x00000000;

   setup_timer_4(T4_DISABLED,0,1); 
   
   if(mmcsd_init())
   {
      while(true)
      {
         output_high(LED1);
         delay_ms(DELAY);
         output_low(LED1);
         delay_ms(DELAY);
      }
   }
   
   output_high(LED1);
   delay_ms(DELAY);
   output_low(LED1);
   
   // Scrivo un dato
   mmcsd_write_byte(address, value);
   mmcsd_flush_buffer();
   
   output_high(LED1);
   delay_ms(DELAY);
   output_low(LED1);
   
   // leggo il dato scritto
   mmcsd_read_byte(address, &valuer);
   
   output_high(LED1);
   delay_ms(DELAY);
   output_low(LED1);
   
   if(value != valuer)
   {
      while(true)
      {
         output_high(LED2);
         delay_ms(DELAY);
         output_low(LED2);
         delay_ms(DELAY);
      }
   }
   
   output_high(LED1);
   output_high(LED2);
   
   while(true);
}


Thanks
collink



Joined: 08 Jan 2010
Posts: 137
Location: Michigan

View user's profile Send private message Visit poster's website

PostPosted: Fri Apr 22, 2011 5:29 am     Reply with quote

It seems like some of your pins are configured oddly. SDI should be PIN_D1 and SDO should be PIN_D4 not the other way around like you have it. The usual hardware select pin for SPI2 is PIN_D3 but I suppose you are allowed to use anything you want. Just make sure you actually have your select line run to PIN_D6 like you claim.

Also, does the mmcsd_init() function set up the SPI parameters? Because you otherwise don't seem to be doing that.
adalucio



Joined: 16 Mar 2009
Posts: 29

View user's profile Send private message

PostPosted: Fri Apr 22, 2011 5:57 am     Reply with quote

THANKS!!!!

the problem was PIN_D1 and PIN_D4.
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