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

Reading and writing problem with SD card

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



Joined: 21 Feb 2010
Posts: 17

View user's profile Send private message

Reading and writing problem with SD card
PostPosted: Sun Mar 28, 2010 4:25 am     Reply with quote

I have compiled this code:
Code:

#include <18f452.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT                 //Reset when brownout detected
#FUSES NOPUT                    //No Power Up Timer
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=20000000)
#include <HDM64GS12x.c>
#include <graphics.c>
#include <stdlib.h> // for atoi32
#use rs232(baud=9600,parity=N,xmit=PIN_A3,rcv=PIN_B7,bits=8)
#use fast_io(c)

#define MMCSD_PIN_SCL     PIN_C3 //o
#define MMCSD_PIN_SDI     PIN_C4 //i
#define MMCSD_PIN_SDO     PIN_C5 //o
#define MMCSD_PIN_SELECT  PIN_C6 //o

#include <mmcsd.c>
#include <input.c>

   BYTE value, cmd,a;
   int32 address;

   void main()
   {
   char deg1[32];
   char deg2[]="Value";

   glcd_init(ON);
   glcd_fillScreen(off);
   a=0;

   while(true)
   {
   glcd_init(ON);
   address=0;
   value=100;
   glcd_text57(0, 50, deg2, 1, ON);
   delay_ms(1000);
   mmcsd_write_byte(address, value);
   mmcsd_flush_buffer();
   delay_ms(1000);
   mmcsd_read_byte(address, &a);
   delay_ms(1000);   
   sprintf(deg1, "%d",a);
   glcd_text57(0, 30, deg1, 1, ON);
   delay_ms(1000);
   }   
   }

And I have seen the correct value (100) on Graphic LCD. When I add this code shown below to this program I couldn't see anyvalue on graphic lcd:
Code:

   address=512;
   value=300;
   glcd_text57(0, 50, deg2, 1, ON);
   delay_ms(1000);
   mmcsd_write_byte(address, value);
   mmcsd_flush_buffer();
   delay_ms(1000);
   mmcsd_read_byte(address, &a);
   delay_ms(1000);   
   sprintf(deg1, "%d",a);
   glcd_text57(0, 30, deg1, 1, ON);
   delay_ms(1000);

What should I do?
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 2:03 am     Reply with quote

This is probably not related to your problem but

value=300;

What size is value ?

mmcsd_write_byte(address, value);

By the name of the function I would say that you cannot write the value 300 Smile
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Mar 29, 2010 5:45 am     Reply with quote

When debugging try to narrow down the problem to as small a change as possible. Now you have changed the two variables 'address' and 'value', what happens if you change only one of these?

As Wayne already indicated a byte can only contain a maximum value of 255, your 300 will not fit.

Most likely the problem is caused by the write to the SD card failing. The read and write functions do return a result code. Add a check in your program to test for this result value and show an error code on failure.

Also post your compiler version number.
lokken



Joined: 21 Feb 2010
Posts: 17

View user's profile Send private message

PostPosted: Thu Apr 01, 2010 7:51 am     Reply with quote

I will ask one more simple question.
Are these explanations true?(MY compiler version is 4.068)
Code:

mmcsd_write_byte(address, value); ///  0.adress=value
mmcsd_read_byte(address, &a); /// a=0.adress
theasus



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

PostPosted: Thu Apr 01, 2010 12:43 pm     Reply with quote

I have same problem with lokken.I want to use SD card as a large EEPROM. But I couldn't understand usage of these codes:
Code:

mmcsd_write_byte(address, value);
mmcsd_read_byte(address, &a);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 01, 2010 12:54 pm     Reply with quote

Quote:

I have same problem with lokken. I want to use SD card as a large
EEPROM. But I couldn't understand usage of these codes:

mmcsd_write_byte(address, value);
mmcsd_read_byte(address, &a);


Look at the comments in this file:
Quote:
c:\program files\picc\drivers\mmcsd.c

It says:
Quote:

//// mmcsd_flush_buffer()
//// The two user write functions (mmcsd_write_byte() and
//// mmcsd_write_data()) maintain a buffer to speed up the writing
//// process. Whenever a read or write is performed, the write
//// buffer is loaded with the specified page and only the
//// contents of this buffer is changed. If any future writes
//// cross a page boundary then the buffer in RAM is written
//// to the MMC/SD and then the next page is loaded into the
//// buffer. mmcsd_flush_buffer() forces the contents in RAM
//// to the MMC/SD card. Returns 0 if OK, non-zero if errror.
theasus



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

PostPosted: Sat Apr 03, 2010 11:23 am     Reply with quote

Ok I have read the functions but i didn't understand one point.
Why are we using pointer for getting a value from any address?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Apr 04, 2010 6:26 am     Reply with quote

theasus wrote:
Why are we using pointer for getting a value from any address?
You mean, why was the function not defined as: value = mmcsd_read_byte(int32 address)

Only the original author can answer this question, but I think it was implemented like this because there is also the error code to be returned. You can only return a single value and because all other functions return an error code it made more sense to do the same here as well.
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