Someone Electro
New Member
Oh and if you are using the SD card, try not to write to the first sectors on it, since that will crash the entire file system and you might have trouble formating it again.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
I don't see how that would make the card unformattable. Definitely unreadable by a PC or camera though. I wrote a FAT hex editor in 6809 assembler for the TRS-80 Color Computer back in the 80's and then one for PC, so I have a real good idea how FAT works. That's the next phase of this project.Oh and if you are using the SD card, try not to write to the first sectors on it, since that will crash the entire file system and you might have trouble formating it again.
Just do what I said. Rewrite so you use the same buffers for read and write. You aren't doing both at the same time anyway (yet). Saves 512 bytes of RAM. Easy to do too.i still cant seem to compile due to memory thing with C18 this sux. I guess boostc is the way to go. Gota put on hold then
i still cant seem to compile due to memory thing with C18 this sux. I guess boostc is the way to go. Gota put on hold then
Phantom breakpoint. MPLAB buglet. Happens all the time. I save the source and header files somewhere and wipe the rest of the project. Start a new project and put the source/header back in and it's fixed.So many issues lol Now its halting when it tries to writeSPI
writeSPI(a>>8);
There isnt a break point there. What gives.
Hey Eurisko. Sounds like a very cool project.Hello everyone!
My project uses the PIC with a MAX541 16 bit DAC to output audio wav files from the SD card. 22050 Hz at 16 bits sounds great. The PIC is using the internal 8Mhz oscillator with a 4X PLL == 32 MHz. Works fine at 3.3 volts, though I may be pushing it a bit.
Eurisko thanks for the tips. Ill be sure to get my hands on a low voltage 18LF4620 and a normal one...
...I'm currently writing a hex sector editor for SD cards, using the 18F4620. I don't know what use it will be, (maybe I'll think of something) but I'm amusing myself.
#include <p18f2550.h>
#include <stdio.h>
#include <delays.h>
#pragma config WDT = OFF, FOSC = HS, LVP = OFF
//Funtions
void main(void);
void initSD( void);
void delay_s(unsigned char);
void delay_ms(unsigned char);
void delay_us(unsigned char);
unsigned char writeSPI( unsigned char b);
int sendSDCmd( unsigned char c, unsigned a);
int initMedia( void);
// I/O definitions
#define SDCS LATCbits.LATC6
#define SDCS_T TRISCbits.TRISC6
#define LED LATBbits.LATB2
// Macros
#define readSPI() writeSPI( 0xFF)
#define clockSPI() writeSPI( 0xFF)
#define disableSD() SDCS = 1; clockSPI()
#define enableSD() SDCS = 0
// SD card commands
#define RESET 0 // a.k.a. GO_IDLE (CMD0)
#define INIT 1 // a.k.a. SEND_OP_COND (CMD1)
#define READ_SINGLE 17
#define WRITE_SINGLE 24
#define I_TIMEOUT 10000
#define RI_TIMEOUT 10000
#define FAIL FALSE
#define E_COMMAND_ACK 0x80
#define E_INIT_TIMEOUT 0x81
typedef unsigned LBA; // logic block address, 32 bit wide
void initSD( void)
{
ADCON1 = 0x0F;
TRISB = 0x01;
TRISC = 0;
SDCS = 1; // initially keep the SD card disabled
SDCS_T = 0; // make Card select an output pin
// init the SPI2 module for a slow (safe) clock speed first
SSPSTAT = 0b00000000; //SMP(7)=0, CKE(6)=0 (clock edge idle to active), others don't care
SSPCON1 = 0b00010010; //CKP(4)=1 clock polarity (idle high)
//SSPM3:SSPM0(3:0)=010 spi clock FOSC/64 (<400kHz)
SSPCON1bits.SSPEN=1; //SSPEN(5)=1 enable SPI
}
unsigned char writeSPI( unsigned char b)
{
// send one byte of data and receive one back at the same time
SSPBUF=b; // write to buffer for TX
while( !SSPSTATbits.BF); // wait transfer complete
return SSPBUF; // read the received value
}
int sendSDCmd( unsigned char c, unsigned a)
// c command code
// a byte address of data block
{
int i, r;
// enable SD card
enableSD();
// send a comand packet (6 bytes)
writeSPI( c | 0x40); // send command
writeSPI( a>>24); // msb of the address
writeSPI( a>>16);
writeSPI( a>>8);
writeSPI( a); // lsb
writeSPI( 0x95); // send CMD0 CRC
// now wait for a response, allow for up to 8 bytes delay
for( i=0; i<8; i++)
{
r=readSPI();
if ( r != 0xFF)
break;
}
return ( r);
// NOTE CSCD is still low!
}
int initMedia( void)
// returns 0 if successful
// E_COMMAND_ACK failed to acknowledge reset command
// E_INIT_TIMEOUT failed to initialize
{
int i, r;
// 1. with the card NOT selected
disableSD();
// 2. send 80 clock cycles start up
for ( i=0; i<10; i++)
clockSPI();
// 3. now select the card
enableSD();
// 4. send a single RESET command
r = sendSDCmd( RESET, 0); disableSD();
if ( r != 1) // must return Idle
return E_COMMAND_ACK; // comand rejected
// 5. send repeatedly INIT until Idle terminates
for (i=0; i<I_TIMEOUT; i++)
{
r = sendSDCmd( INIT, 0); disableSD();
if ( !r)
break;
}
if ( i == RI_TIMEOUT)
return E_INIT_TIMEOUT; // init timed out
// 6. increase speed
SSPCON1bits.SSPEN=0; // disable the SPI module
SSPCON1 = 0x30;
SSPCON1bits.SSPEN=1; // enable SPI
return 0;
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
void main(void)
{
int result;
initSD();
result = initMedia();
while(result != 0) {
result = initMedia();
}
while(1);
}
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
void delay_s(unsigned char x)
{
char var1;
for(var1=0;var1<x;var1++)
{
Delay10KTCYx(200);
}
}
void delay_ms(unsigned char x)
{
char var1;
for(var1=0;var1<x;var1++)
{
Delay1KTCYx(2);
}
}
void delay_us(unsigned char x)
{
char var1;
for(var1=0;var1<x;var1++)
{
//Delay10TCYx(2);
Delay1TCY();
Delay1TCY();
}
}