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

Using PIC18F452 with SD card

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



Joined: 18 Mar 2012
Posts: 3

View user's profile Send private message

Using PIC18F452 with SD card
PostPosted: Sun Mar 18, 2012 5:28 pm     Reply with quote

Hi everyone,
I'm trying to set a code using 18F452. This code allows you to save data to an SD card from an ECG device then retrieve them on PC. I have already begun to do but I'm stuck.
Where is the problem ? Can you please help me ?

PROGRAM:
Code:

#include "18f452.h"
#fuses H4,NOWDT,NOPROTECT,NOWRT,NOWRTD,NOLVP,NOOSCSEN,BORV27,PUT,STVREN,NODEBUG,NOWRTB
#use delay(clock=40000000,RESTART_WDT)
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS)

#include "HDD Driver.c"

void main(){

int r1,i,j,error,error0,error1;
int16 rec_no;
int16 index,rec_size;
int32 offset;
char fname[32],buff0[MMC_BUFF_SIZE+1],buff1[MMC_BUFF_SIZE+1];
char c;

setup_adc_ports(NO_ANALOGS);

set_tris_c(0b10010011); //c7=rx I, c6=tx O, c5 SDO O,c4 SDI I

output_high(_CS); //Sets the specified pin to a logic 1 (about 5 volts).

printf("\r\n**** SD / MMC FAT16  Read Demo for Sonsivri **** ");
printf("\r\n");
Delay_ms(1000);
printf("\r\Now Open COUNTRY.TXT File on SD Card  ");
printf("\r\n");
Delay_ms(3000);

SETUP_SPI (SPI_MASTER |  SPI_SS_DISABLED |SPI_H_TO_L| SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H);

buff0[MMC_BUFF_SIZE]=0;
buff1[MMC_BUFF_SIZE]=0;
rec_no=0;

///////// init MMC ////////////////////////////////////////
error=init_MMC(10);
if (error>0) {
goto mmc_exit;
}

printf("\n\r MMC initialized \n\r");
rec_size=MMC_BUFF_SIZE;

//strcpy(fname,"HOME\\HOME.TXT");
strcpy(fname,"COUNTRY.TXT");
rec_size=MMC_BUFF_SIZE;
error0=open_file(0,fname,rec_size);

if (error0>0) {
printf("\n\r fopen as 0 failed error=%U\n\r",error);
goto mmc_exit;
}
else printf("\n\r opened as 0 file %s with rec size %lu \n\r",fname,rec_size);

do {

error0=file_read(0,buff0);

if (error0>0 && error0<255 ) {
printf("\n\r fread 0 failed error=%U\n\r",error0);
break;
}

printf("%s",buff0);

rec_no++;

} while (error0==0);

mmc_exit:
printf("\n\r done winhex adj= %lu \n\r",winhex_adj);

while(true);


}
temtronic



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

View user's profile Send private message

PostPosted: Sun Mar 18, 2012 6:00 pm     Reply with quote

What is the configuration of your hardware ?
Show us a link to your schematic.
mannou



Joined: 18 Mar 2012
Posts: 3

View user's profile Send private message

PostPosted: Mon Mar 19, 2012 2:52 pm     Reply with quote

I work on a portable ECG device. I want concepter a map using the peak 16F452. The participation can use this card alone because it automatically saves the data on an SD memory card.I hope that it's clear now.

http://www.equipmedical.com/p-electrocardiographe-ecg-portable-omron--heart-scan--hcg-801-e-p2448.html

http://www.shopwiki.fr/d/746229/850722255/ECG-PORTABLE-HEART-SCAN-HCG-801E[/url]
temtronic



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

View user's profile Send private message

PostPosted: Mon Mar 19, 2012 3:09 pm     Reply with quote

OK...
You cannot directly interface an SD card to a PIC18F452, or ANY other PIC running at 5 volts.

You have 2 viable options, 1 bad one

1) Use an 'L' version of a PIC, designed to run at 3 volts which will interface with the SD card..

or

2) Use a logic level conversion chip to allow proper communications.

Either option works.

The bad one, wiring up the 3 volt SD card to a 5 volt PIC, poof, there goes the card AND all the data on it. Maybe not the first time, or fourth, but sooner or later it will go poof.

This topic has been covered here, ad nauseam, just search on the forum, you'll see why.
mannou



Joined: 18 Mar 2012
Posts: 3

View user's profile Send private message

PostPosted: Mon Mar 19, 2012 4:42 pm     Reply with quote

I think that I can use a battery 3.6V ?
What did you think about this ?
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Mar 19, 2012 6:52 pm     Reply with quote

Personally, I will not use any voltage over the "maximum" stated in a spec sheet - what does the spec sheet say for the SD card?. Your choice ... personally, I don't like it when things go poof and let the magic smoke out. One thing you could do is add a diode in series with the 3.6 volt battery supply making sure you had good bypass caps on the processor side - this would add a roughly 0.7 volt drop in the supply voltage. The advantage to that is it prevents hooking up the battery backwards. The downside is that it means you will get to the low voltage end of your operating range faster as the battery discharges. Pushing the design limits on parts may get you a passing grade this quarter, but will cause you nothing but trouble when you are designing devices for a living (and any decent peer review will nail you for it).
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
temtronic



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

View user's profile Send private message

PostPosted: Mon Mar 19, 2012 8:39 pm     Reply with quote

What do I think ???
I could go on for hours, shoot after 25 years of working with PICs, I've learned a few things.Heck, even my first project, now a 1/4 century old, a wirewrapped PIC16C71 voltmeter still works.

1) Read the datasheets !! Show me WHERE in the 332 pages of the PIC18F452 info, does it actually say you can use that PIC at 3.6 volts at 20MHz.

2)Don't believe me? Fine,buy the chips, program them, try it out.Sooner or later you might discover that no matter how many countless hours of cutting code, if you can't get simple hardware right, it ain't NEVER going to work.

3) This is really,really simple code for a board with TWO 'major' chips.At most it should take 4 or 5 evenings to get it 'up and running',far less than 2 weeks for sure !
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