![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
BATACO Guest
|
PIC 18F458 WITH SD CARD |
Posted: Tue Jul 25, 2006 3:42 pm |
|
|
Hi ¡ :)
I´m using a PIC18F458 with a SD CARD 512MB, the problem is:
I don´t see where is my code HEX ¡¡¡¡. I loaded a 512 block into the the pic´S RAM, then I wrote the block into de SD, then i read it.... by USART.
But when i read the SD CARD with DISKEDIT, I don´t found nothing......
Why????
Anybody, have idea? |
|
![](templates/subSilver/images/spacer.gif) |
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Tue Jul 25, 2006 7:02 pm |
|
|
I assume DISKEDIT expects to see some sort of file system (i.e. FAT or NTFS) on the card. Did you create a file system on the card? |
|
![](templates/subSilver/images/spacer.gif) |
dmendesf
Joined: 31 Dec 2005 Posts: 32
|
|
Posted: Tue Jul 25, 2006 8:19 pm |
|
|
Can you show the code you used to talk with the SD card? |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
Re: PIC 18F458 WITH SD CARD |
Posted: Wed Aug 02, 2006 10:08 am |
|
|
BATACO wrote: | Hi ¡
I´m using a PIC18F458 with a SD CARD 512MB, the problem is:
I don´t see where is my code HEX ¡¡¡¡. I loaded a 512 block into the the pic´S RAM, then I wrote the block into de SD, then i read it.... by USART.
But when i read the SD CARD with DISKEDIT, I don´t found nothing......
Why????
Anybody, have idea? |
Code: |
#include <18F458>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <stdio.h>
#include <input.c>
#define BUFFSIZE 512
#use fast_io(C)
#byte SSPBUF = 0xFC9
#byte SSPCON = 0xFC6
#byte SSPSTAT = 0xFC7
#bit BF = SSPSTAT.0
#bit SMP = SSPSTAT.7
#bit CKE = SSPSTAT.6
#bit CKP = SSPCON.4
#bit SSPM1 = SSPCON.1
#bit SSPEN = SSPCON.5
#byte PORTC = 0xF82
#bit CS = PORTC.2
//****************************************//
// Store in RAM
byte buffer1[BUFFSIZE];
// buffer ( array element)
// memory locations
// one large array.
void write_buffer( int16 index, char value) {
if(index<BUFFSIZE)
buffer1[index]=value;
}
char read_buffer( int16 index) {
if(index<BUFFSIZE)
return(buffer1[index]);
}
//****************************************//
// To Store in 512 array RAM
int16 i; //initialize the variable
char a;
char BLOCK_SD()
{
for(i=0; i <499>> 8);
SPI(AdrH);
SPI(AdrL >> 8);
SPI(AdrL);
SPI(befH);
SPI(0xFF);
return SPI(0xFF); // Return with the response
}
//********************************************
char MMC_Init()
{
char i;
// Init SPI
SMP=0;
CKE=0;
CKP=1;
SSPM1=1;
//SSPM0=1;
SSPEN=1;
CS=1; // MMC-Disabled
// MMC in SPI Mode -- start and Reset.
for(i=0; i < 10; i++) SPI(0xFF); // 10*8=80 clocks
CS=0; // MMC-Enabled
// CMD0
if (Command(0x40,0,0,0x95) !=1) goto Error; // Reset
st:
// CMD1
if (Command(0x41,0,0,0xFF) !=0) goto st ; // CMD1
return 1;
Error:
return 0;
}
//*********************************************
void main(void)
{
int16 i;
printf("\n **STARTING**\n\n\n");
putc(0xD);
if(BLOCK_SD())
printf("\n\n ***CONNECT THE SD-CARD***\n\r");
setup_port_a(NO_ANALOGS);
set_tris_c(0b11010011); // sck rc3-0, sdo rc5-0, CS rc2-0.
puts(" ***PROGRAMA QUE MANDA 512 DATOS A LA SD Y LOS MUESTRA POR USART***\n\r");
puts(" ***INICIALIZACION DE PUERTOS DEL PIC***\n\r");
if(MMC_Init())
puts(" ***EN ESTE MOMENTO SE INICIALIZA LA SD***\n\r"); // MMC Init OK
//*****************************************
//Write in 512 Byte-Mode
if (Command(0x58,0,512,0xFF) !=0) puts("Write error ");
SPI(0xFF);
SPI(0xFF);
SPI(0xFE);
SPI("Inicio\n\r"); // 8 characters
for(i=0; i < 499; i++) // Was 512, but used 13 for text
{
SPI(read_buffer(i));
}
SPI("\n\rFin"); // 5 characters
SPI(255); // Send two bytes of 0xFF at the end
SPI(255);
i=SPI(0xFF);
i &=0b00011111;
if (i != 0b00000101) puts("Write Error ");
while(SPI(0xFF) !=0xFF); // Wait for end of Busy condition
//*************************************
// Read in 512 Byte-Mode
if (Command(0x51,0,512,0xFF) !=0) puts("Read Error ");
while(SPI(0xFF) != 0xFE);
for(i=0; i < 512; i++)
{
putc(SPI(0xFF)); // Send data
}
SPI(0xFF); // Send two bytes of 0xFF at the end
SPI(0xFF);
//**********************************************
while(1); // The program stops here.
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
dmendesf
Joined: 31 Dec 2005 Posts: 32
|
|
Posted: Wed Aug 02, 2006 10:22 am |
|
|
Probably you are not writing to the same address that you are reading in your PC program. This happened to me too. Do the follwing: white a routine to put a number in ascending order in each page of the SD card (page 0 -> 0, page 1-> 1, etc...) Then read them in the PC. Probably i´ll see them in another order. This happened to me when i was playing with an MMC card. |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Aug 02, 2006 10:41 am |
|
|
I have no experience with Diskedit, but as Rberek already suggested it might be that Diskedit expects some kind of file system on the disk (bootblock, partition table, etc). This would cause Diskedit to start reading data with an address offset, when you tell it to read from address 0 it actually reads from something like 0x1234.
I've experienced similar behaviour with another disk editing tool and was able to find my data when I tried another tool: http://hexplorer.sourceforge.net
Suggestion: use the search function of Hexplorer. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|