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

Small 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
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

Small problem with SD card
PostPosted: Fri Dec 14, 2012 5:36 am     Reply with quote

Hi, everyone. I`m trying to make a simple program using mmcsd.c and fat.c libraries. My hardware is working because I test it with the mdd stack. I made a simple program:
Code:

#include <18F66J60.h>
#FUSES HS,NOWDT
#device PASS_STRINGS = IN_RAM
#use delay(clock=25M)
#use rs232(baud=9600, UART1, errors)
#include <string.h>

#include <stdlib.h>
#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_C2 //o
#include <mmcsd.c>
#include "fat.c"

void main()
{
   char FileName[]="text.txt";

   delay_ms(1000);

   if(fat_init()!=GOODEC)
   {
      printf("error");
   }

   delay_ms(50);
   if(mk_file(FileName) != GOODEC)
   {
      printf("error");
   }
   
   while(1);
}

The fat_init() and mk_file() return 0(I think this means everything is OK). But in the card there isn`t new file.
I think it`s something simple, but I don`t have alot of expirience with this libraries. I saught in the forum some bugfixing changes for the fat.c file. My library is without anychanges. Should I do them?
Help!
Thanks!
temtronic



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

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 6:33 am     Reply with quote

comments...
1)From a programming viewpoint..you should really change those 'printf's. Having BOTH say the same thing is not good...if the error is a fat_init error, you should say 'fat init error',same holds true for all possible error messages. Right now you only have 2 possible error messages and can't say which displays 'error' so when your program grows to 20-30 possible 'errors' you'll never be able to say what the 'error' is.

2) what card size? It's well known here that some cards work, others don't and size does matters! Are you only using one card? Have you tried say, 3 different cards.Does the card read correctly in a PC?

2a) you should search the forums for related topics and code,there is a LOT posted!

3) for mass storage, I eliminated the MMCSD nonsense by using a Viniculum and any flashdrive on the bench.No hardware issues, no data problems,any drive size,etc.Yes, it costs more 'up front', but 100% compatible with any PC(all have USB,most don't have 'card reader'.


hth
jay
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 6:46 am     Reply with quote

I don`t know that is going on here. I run a few more tests with the debugger and sometimes everything is OK - sometimes fat_init() returns error.
As I said I have mdd stack 22.06.2012 and when I`m working with it everything is fine. So I assume the problem is not in the card or in the hardware. It could be only in the firmware.
I tried to use mmc_spi.c but it throws an error:
\mmc_spi.c" Line 892(13,14): Expecting an identifier
And it points here:
Code:

void mmc_send_data(int8 data) {
   int8 null; // here
   mmc_spi_exchange(data,&null);
}

Is there a mistake in my main program or in the file loading?
ckielstra



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

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 9:32 am     Reply with quote

I'm surprised you can't fix the problem yourself. You have run into similar problems before when you had two variables with the name 'buffer'...
Poor programming from CCS, I would never create a variable with the name 'null' as this name is often reserved. My guess is that somewhere in your code there is a '#define NULL' and with the CCS compiler being case insensitive this creates your error.
Easy to fix by renaming the variable, it is just a temporary variable, so name it 'temp'.

Quote:
My hardware is working because I test it with the mdd stack.
You didn't answer Temtronic's question for the card size you use... CCS doesn't support > 2Gb cards so that could be one explanation for your problem.

What I don't understand:
Why do you want to use the CCS driver when you have the Microchip MDD running? The CCS driver is smaller but contains bugs (see the Code Library for fixes) and it doesn't support memory cards > 2Gb.
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Fri Dec 14, 2012 11:22 am     Reply with quote

The SD card is 2G. The code(this with null) is from the mmc_spi.c. I haven`t wrote it.
I want to use this library because I want to use it with TCPIP stack, but mmd library uses p18cxxx.h which disturbs the stack. But if I use mmcsd.c there is no redefinition of the register, ports and so on.
Best regards!
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 3:42 am     Reply with quote

OK.
Key is your setup in the program you are using to compile mmc_spi.c. It _requires_ that the compiler is set to ANSI mode. So (minimum useless compile test):
Code:

#include <18F66J60.h>
#FUSES HS,NOWDT
#device PASS_STRINGS = IN_RAM
#device ANSI
#use delay(clock=25M)
#use rs232(baud=9600, UART1, errors)
#include <string.h>

#include <stdlib.h>
#define MMCSD_CLK     PIN_C3 //o
#define MMCSD_DI     PIN_C4 //i
#define MMCSD_DO     PIN_C5 //o
#define MMCSD_CS  PIN_C2 //o
#include <mmc_spi.c>

void main()
{
   delay_ms(1000);
   mmc_init();
   
   while(1);
}


Will compile, but if you remove the 'ANSI' declaration, it won't.
ANSI, requires the 'null' declarator to be supported.

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 9:14 am     Reply with quote

Yes! It compiles now. Thanks!
Can I use Fat.c with mmc_spi.c?
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Sat Dec 15, 2012 2:22 pm     Reply with quote

You'd need to #define the functions from the mmc handler to have the names wanted by fat.c. If you read fat,c, it calls just four functions, and the names and data definitions are given in the comments. You need to make these calls access the corresponding ones in mmc_spi. So (for instance:
Code:


#define mmcsd_read_bytes(a, s, p) mmc_read_block(a, s, p)


etc..

Best Wishes
stoyanoff



Joined: 20 Jul 2011
Posts: 375

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 2:45 am     Reply with quote

Thanks, Ttelmah!
I ran a few test with mmcsd.c and I found that the TRISC register contains 0xFF after the initialization. As far as I know only SDI must be configured as input signal.
In the MMCSD_err mmcsd_init() there is:
Code:

output_drive(MMCSD_PIN_SCL);
output_drive(MMCSD_PIN_SDO);
output_drive(MMCSD_PIN_SELECT);
output_float(MMCSD_PIN_SDI);

but it seems this code is not working!
Does anyone has a idea why is so?
Thanks!
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Dec 17, 2012 4:23 am     Reply with quote

Er.
You were asking about using mmc_spi.c, not have shifted to mmcsd.
Have you changed the pin definitions to match the different names used in this?.
Realise, that it _won't_ set the tris, if the SPI hardware is being used. This is done automatically in the SPI driver.

Best Wishes
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