PIC16f877 serial interface with Alfat SD memory card

Thread Starter

ranaz

Joined Mar 7, 2007
5
hi. i m trying to send and recieve data to and from memory card through PIC 16f877A.
PIC serial interrupts work fine if i use hyper terminal. also card works fine with hyperterminal. so this means there is no fualt as far as connections r concerned. also PIC succesfuly writes data on the card. BUT.............
when i try to retreive it !!!!!!!!!!!!!!!!!!!!! nothing happens. interrupt service routine is not even invoked once. here is the code i'm using:(by the way compiler is "CCS C"


#include <16F877A.h>
#fuses HS,NOLVP,NOWDT,PUT,NOBROWNOUT
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

char tester;
char str_ch[30];
int j;

//interrupt service routine
#int_rda
void serial_isr( ){
tester=getc( );
str_ch[j]=tester;
j=j+1;
}


//main programm
void main( )
{
int k;
j=0;


enable_interrupts(int_rda);
enable_interrupts(GLOBAL);

//read data from this file in memory card
printf("O 1R>DSAMP.LOG\X0d");
for(k=0;k<2;k++){
//read 2 bytes of data
printf("R 1^>2\X0d");
//at this point it should enter interrupt service routine.
// but tht does not happen


}


//write the read data to this file
printf("O 2W>VOLTASTR.LOG\X0d");
for(k=0;k<j;k++){
printf("character is %c\n",str_ch[k]);
}
delay_ms(1);
printf("C 1\X0d");

delay_ms(1);
printf("C 2\X0d");
}


any help wud be greatly appreciated.
 

SgtWookie

Joined Jul 17, 2007
22,230
Just re-indenting your source, and using CODE blocks to preserve the formatting.

Rich (BB code):
#include <16F877A.h>
#fuses HS,NOLVP,NOWDT,PUT,NOBROWNOUT
#use delay(clock=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

char tester;
char str_ch[30];
int j;

//interrupt service routine
#int_rda
void serial_isr( ){
	tester=getc( );
	str_ch[j]=tester;
	j=j+1;
}


//main programm
void main( )
{
	int k;
	j=0;

	enable_interrupts(int_rda);
	enable_interrupts(GLOBAL);

	//read data from this file in memory card
	printf("O 1R>DSAMP.LOG\X0d");
	for(k=0;k<2;k++){
		//read 2 bytes of data
		printf("R 1^>2\X0d");
		//at this point it should enter interrupt service routine.
		// but tht does not happen

	}

	//write the read data to this file
	printf("O 2W>VOLTASTR.LOG\X0d");
	for(k=0;k<j;k++){
		printf("character is %c\n",str_ch[k]);
	}
	delay_ms(1);
	printf("C 1\X0d");

	delay_ms(1);
	printf("C 2\X0d");
}
 
Top