Hola que tal, yo he seguido por mucho tiempo a este hilo, pero nunca tenia tiempo de ponerme a renegar con estas tarjetitas...

ahora que me hice un tiempito pude tocar este tema que tanto me intrigaba...
de hecho pude hacer la inicializacion, lectura y escritura de la tarjeta, pero todo esto con el spi por hard... pero la aplicacion que quiero hacer, tambien quiero que use el usb, y como todos saben las patitas del usb se superponen con la del spi por hardware (estoy hablando del 18f4550), por lo que en mi aplicacion no me molestaria realizarl la comunicacion spi por soft (como hizo el gran maestro diego).
para lo cual he intenetado implementar el soft de diego y probarlo, pero no me dio resultado, paso a destacar las diferencias que tienen (aunque son pocas porque trate de mantenerlo para ver si andaba)
1- yo uso el 18f4550 con un xtal de 20mhz, los fuses para el clock lo puse para tener el cloc de 48mhz y anda un relojito porque lo probe con parpadeo de unos led y anda (dicho sea de paso la placa que uso es la que tiene diego en la pagina de el (rrboard2 16f877/18f4550).
2- la comunicacion serie la realizo por el usart del pic (es decir por hardware rs232 del pic).
3- le cambie como hizo diego los pines del bus spi. en mi caso tengo a do->b2; ck->b1; di->b3; cs-b5;
pongo las modificaciones realizadas en el nutriax_mmc_spi.c
/////*** USER CONFIG ***/////
//SanDisk’s MultiMediaCards clock data in on the rising edge and out on the falling edge.
#ifndef MMC_CLK
#define MMC_CLK PIN_B1
#endif
#ifndef MMC_DI
#define MMC_DI PIN_B4
#endif
#ifndef MMC_DO
#define MMC_DO PIN_B2
#endif
#ifndef MMC_CS
#define MMC_CS PIN_B5
#endif
ahora pongo el programa que uso...
////////////////////////////////////////////////////////////////////////////////////
//
// MMC Card Test ...
// by RedPic
////////////////////////////////////////////////////////////////////////////////////
#include <18f4550.h>
//#fuses HS,MCLR,NOWDT,NOPROTECT,NOPUT,NOBROWNOUT,NOPBADEN,NOLVP,NOCPD,NODEBUG,NOWRT,NOVREGEN
#fuses HSPLL,MCLR,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,NOVREGEN,NOPBADEN,NOPUT,NOBROWNOUT,NOCPD,NOWRT
// el fuse que configuramos anteriormente
#use delay(clock=48000000)
#define LED PIN_e0
#define BUZZER PIN_e1
#define RELE PIN_e2
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
char cRec=0x00; // Último caracter recibido via serie
char Command=0x00; // Comando a procesar
int8 MMCBuffer[512];
int32 address=0;
#define MMC_CS PIN_B5
#define MMC_CLK PIN_B1
#define MMC_DI PIN_B4
#define MMC_DO PIN_B2
#include "pulpo_mmc_spi.c"
////////////////////////////////////////////////////////////////////////////////////
//
// Funciones ...
//
////////////////////////////////////////////////////////////////////////////////////
void Cursor(char c){
printf("%c\r\n>",c);
}
void Presenta_Hardware(void){
printf("\r\n\n");
printf("MMC MultiMedia Card Driver Test\r\n");
printf("Hardware iACCESS CONTROL V1 v.0.0.0\r\n\n");
printf("Commands when available:\r\n\n");
printf("[M] Init MMC Card\r\n");
printf("[F] Read MMC Card Block First\r\n");
printf("[R] Read MMC Card Block Actual\r\n");
printf("[ ] Read MMC Card Block Next\r\n\n");
Cursor(0x00);
}
////////////////////////////////////////////////////////////////////////////////////
//
// Interrupción por Recepción Serie RS232
//
////////////////////////////////////////////////////////////////////////////////////
#int_rda
void handle_rda_int(){
if(kbhit()){ // Si hay algo pdte de recibir ...
cRec=getc(); // lo recibo sobre cRec ...
if(cRec!=0x00){ // Si es distinto de \0 ...
Command=ToUpper(cRec); // cargo cRec sobre Command para procesarlo
} // pasándolo a Mayúsculas para no confundir.
}
}
////////////////////////////////////////////////////////////////////////////////////
//
// Main
//
////////////////////////////////////////////////////////////////////////////////////
void main() {
int16 f=0;
int16 size=512;
int8 col=0;
disable_interrupts(global);
disable_interrupts(int_timer1);
disable_interrupts(int_rda);
disable_interrupts(int_ext);
disable_interrupts(int_ext1);
disable_interrupts(int_ext2);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,RTCC_DIV_2);
setup_timer_0(RTCC_OFF);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
port_b_pullups(false);
// set_tris_a(0b00001000);
// set_tris_c(0b10000000);
enable_interrupts(global);
enable_interrupts(int_rda);
address=0;
Presenta_Hardware();
do {
if(Command!=0x00){ // Si he recibido un comando vía Serie ...
if(Command=='?'){ // Si el comando es '?' ...
Presenta_Hardware();
}
if(Command=='M'){ // Inicializa MMC Card
Cursor(Command);
if(mmc_init()==0)
printf("MMC init ok");
else
printf("MMC init fault");
Cursor(0x00);
}
if(Command=='F'){ // Read First Block MMC Card
address=0;
Command='R';
}
if(Command==' '){ // Read Next Block MMC Card
address+=512;
Command='R';
}
if(Command=='R'){ // Read Block MMC Card
Cursor(Command);
for(f=0;f<=511;f++) MMCBuffer[f]=0;
size=511;
col=0;
if(mmc_read_block(address, size,&MMCBuffer[0])==0){
printf("\r\n>MMC read ok from Address %LX to %LX\r\n",address,address+size);
for(f=0;f<=511;f++){
printf("%X ",MMCBuffer[f]);
if(++col==16){
col=0;
printf("\r\n");
}
}
}
else
printf("\n\rread fault");
Cursor(0x00);
}
Command=0x00; // Indico que ya he procesado el comando.
}
///////////////////////////////////////////////////////AGREGO NUTRIAX
////////////////////////////////////////////////////////////////////
Cursor(Command);
if(mmc_init()==0)
printf("MMC init ok");
else
printf("MMC init fault");
Cursor(0x00);
} while (TRUE);
}
como veran este es el codigo que tiene diego en la pagina, pero con una leve modificacion (como por ejemplo le saque el conector rj45 y todas sus funciones)...
el problema es que no me inicializa, me imprime init fault...
alguien me puede ayudar o podria decirme como hizo para que le ande el spi por soft? gracias...