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

Unable to write on a SD card

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



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

Unable to write on a SD card
PostPosted: Fri Mar 14, 2008 3:00 am     Reply with quote

Hello, I'm trying to write on a SD card, with the CCS library.

Here's my code :

Code:
#include <18F4580.h>
#device PASS_STRINGS = IN_RAM

#fuses XT, NOWDT, NOPROTECT
#use delay(clock = 4000000)
#use rs232(baud=38400, xmit=PIN_C6,rcv=PIN_C7)

#use fast_io(c)
#use fast_io(e)

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<mmcsd.h>
#include<fat.h>

#byte   PORTB  =  6

void main()
{
FILE fichier;

char temp_buff[10];
char wcmd[]="w";

printf("\n\r*******Test writing on fat ...******************\n\r");

printf("Initialisation\n\r");

if (fat_init()) printf("Init error\n\r");
else {
   printf("Initialisation OK\n\r");

    strcpy(temp_buff,"toto");
   if(fatopen(temp_buff, wcmd,&fichier))  printf("Error opening the file\n\r");
   else printf("File opened\r");

   strcpy(temp_buff,"coucou");
   fatputc(temp_buff, &fichier);

   fatclose(&fichier);
}

set_tris_b(0);

PORTB=0;
while(1)

   {

   output_high(PIN_B1);
   output_low(PIN_B0);
   delay_ms(200);
   output_low(PIN_B1);
   output_high(PIN_B0);
   delay_ms(200);
   }


}


The initialisation returns 0, but I can't open the file.
If I look to the electrical signals, there's no signal on the clock wire when I try to open the file (I've put a fopen command in the infinite loop tho see that).
While the fat_init, I can see the clock signal.

I've searched on this forum, but I didn't find anything...

Can you help me??

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 14, 2008 11:30 am     Reply with quote

1. Add NOLVP your #fuses. Do this in all of your programs. If the LVP
fuse is set and pin B5 (on this PIC) goes high, the PIC will lockup.
In recent versions of the compiler, CCS is automatically using NOLVP
if you don't specify it. In other words, they now use NOLVP as the default
setting. But you didn't give your version, so just to be sure, I mentioned
this.

2. You are setting the TRIS for Port B, but you didn't specify #fast_io
mode for Port B. So why set the TRIS ? The compiler will set it
automatically for you, if you use the CCS i/o functions.

Quote:

#include <18F4580.h>
#byte PORTB = 6

set_tris_b(0);
PORTB=0;

3. You are setting PortB = 0 by writing to the register directly. When you
did this, you showed a reason why this is a bad programming method.
You are using the PortB address for the 16F-series PICs. The 18F-series
uses a different register address. Look in the PIC data sheet to see it.
You can avoid making a mistake like this if you use the CCS output_b()
function. That function will automatically use the correct register address
for Port B. When you write code in this way, by using output_b(), it's
called making the code "portable". It can more easily be compiled for
different PICs and it will still work.
gremi



Joined: 11 Mar 2008
Posts: 20
Location: Toulouse, France

View user's profile Send private message

PostPosted: Mon Mar 17, 2008 3:07 am     Reply with quote

Hi,

1. I'm using CCS V4, so NOLVP is the default seeting.

2 and 3 : I'm using Port B only to toogle the led, I've changed my soft with output_b(0); .. but the result didn't change.


I acces to the memory card through port E and C (software SPI port).

I've also tryed with the hardware spi port, did'nt worked either.

This is the corfiguration part of the mmcsd driver :

Code:
#ifndef MMCSD_PIN_SCL
 #define MMCSD_PIN_SCL     PIN_C3
 #define MMCSD_PIN_SDI     PIN_E1
 #define MMCSD_PIN_SDO     PIN_E0
 #define MMCSD_PIN_SELECT  PIN_E2
#endif

#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, stream=mmcsd_spi)


I work with a Picdem2 plus board RoH compliant (Microchip), and CCS V4 through MPLAB 8.02.
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