esint8 if_initInterface(hwInterface* file, eint8* opts) { euint32 sc; if_spiInit(file); /* init at low speed */ if(sd_Init(file)<0) { DBG((TXT("Card failed to init, breaking up...\n"))); return(-1); } if(sd_State(file)<0){ DBG((TXT("Card didn't return the ready state, breaking up...\n"))); return(-2); } // file->sectorCount=4; /* FIXME ASAP!! */ sd_getDriveSize(file, &sc); file->sectorCount = sc/512; if( (sc%512) != 0) { file->sectorCount--; } DBG((TXT("Drive Size is %lu Bytes (%lu Sectors)\n"), sc, file->sectorCount)); /* increase speed after init */ #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 ) SSPCR0 = ((8-1)<<0) | (0<<CPOL); #endif if_spiSetSpeed(SPI_PRESCALE_MIN); // if_spiSetSpeed(100); /* debug - slower */ DBG((TXT("Init done...\n"))); return(0); }
int8_t init_interface() { uint32_t sc; if_spiInit(file); /* init at low speed */ if(sd_Init(file)<0) { printf("Card failed to init, breaking up...\n\r"); return(-1); } if(sd_State(file)<0){ printf("Card didn't return the ready state, breaking up...\n\r"); return(-2); } // file->sectorCount=4; /* FIXME ASAP!! */ sd_getDriveSize(file, &sc); file->sectorCount = sc/512; if( (sc%512) != 0) { file->sectorCount--; } printf("Drive Size is %d Bytes (%d sectors)\n\r ", sc, file->sectorCount); if_spiSetSpeed(SPI_PRESCALE_MIN); // if_spiSetSpeed(100); /* debug - slower */ printf("Init done...\n\r"); return 0; }
void if_spiInit(hwInterface *iface) { euint8 i; // setup GPIO SPI_IODIR |= (1<<SPI_SCK_PIN)|(1<<SPI_MOSI_PIN)|(1<<SPI_SS_PIN); SPI_IODIR &= ~(1<<SPI_MISO_PIN); // set Chip-Select high - unselect card UNSELECT_CARD(); // reset Pin-Functions SPI_PINSEL &= ~( (3<<SPI_SCK_FUNCBIT) | (3<<SPI_MISO_FUNCBIT) | (3<<SPI_MOSI_FUNCBIT) | (3<<SPI_SS_FUNCBIT) ); #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 ) DBG((TXT("spiInit for SPI(0)\n"))); SPI_PINSEL |= ( (1<<SPI_SCK_FUNCBIT) | (1<<SPI_MISO_FUNCBIT) | (1<<SPI_MOSI_FUNCBIT) ); // enable SPI-Master S0SPCR = (1<<MSTR)|(0<<CPOL); // TODO: check CPOL #endif #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 ) DBG((TXT("spiInit for SSP/SPI1\n"))); // setup Pin-Functions - keep automatic CS disabled during init SPI_PINSEL |= ( (2<<SPI_SCK_FUNCBIT) | (2<<SPI_MISO_FUNCBIT) | (2<<SPI_MOSI_FUNCBIT) | (0<<SPI_SS_FUNCBIT) ); // enable SPI-Master - slowest speed SSPCR0 = ((8-1)<<0) | (0<<CPOL) | (0x20<<SCR); // (0xff<<SCR); SSPCR1 = (1<<SSE); #endif // low speed during init if_spiSetSpeed(254); /* Send 20 spi commands with card not selected */ for(i=0;i<21;i++) my_if_spiSend(iface,0xff); #if ( HW_ENDPOINT_LPC2000_SPINUM == 0 ) // SPI0 does not offer automatic CS for slaves on LPC2138 // ( the SSEL-Pin is input-only ) // SELECT_CARD(); #endif #if ( HW_ENDPOINT_LPC2000_SPINUM == 1 ) // enable automatic slave CS for SSP SSPCR1 &= ~(1<<SSE); // disable interface SPI_PINSEL |= ( (2<<SPI_SCK_FUNCBIT) | (2<<SPI_MISO_FUNCBIT) | (2<<SPI_MOSI_FUNCBIT) | (2<<SPI_SS_FUNCBIT) ); SSPCR1 |= (1<<SSE); // enable interface #endif }
void if_spiInit(hwInterface *iface) { euint8 i; SPI_Config(); MSD_CS_HIGH(); /* Send 20 spi commands with card not selected */ for(i=0;i<21;i++) my_if_spiSend(iface,0xff); /* Speed up */ if_spiSetSpeed(SPI_BaudRatePrescaler_2); }
void if_spiInit(BYTE drive) { int i; printf("spiInit for SPI(0)\n\r"); // Turn on the power LPC_SC->PCONP |= (1<<8); // PCSPI // Clock LPC_SC->PCLKSEL0 &= ~(3<<16); // PCLK_SPI LPC_SC->PCLKSEL0 |= (1<<16); // PCLK_periph = CCLK // setup GPIO LPC_GPIO0->FIODIR |= (1 << SPI_SCK_PIN) | (1 << SPI_MOSI_PIN) | (1 << SPI_SSEL_PIN); LPC_GPIO0->FIODIR &= ~(1 << SPI_MISO_PIN); //// reset Pin-Functions // P0.15 set to SCK LPC_PINCON->PINSEL0 &= ~SPI_SCK_FUNCMASK; LPC_PINCON->PINSEL0 |= SPI_SCK_FUNCBIT; // P0.16, P0.17, P0.18 set to SSEL,MISI, MOSI SPI_PINSEL &= ~(SPI_MOSI_FUNCMASK | SPI_MISO_FUNCMASK | SPI_SSEL_FUNCMASK); SPI_PINSEL |= (SPI_MOSI_FUNCBIT | SPI_MISO_FUNCBIT | SPI_SSEL_FUNCBIT); // enable SPI-Master LPC_SPI->SPCR = (1 << MSTR) | (0 << CPOL); // TODO: check CPOL UNSELECT_CARD(); // Code for GPIO setup /* Switch the SSI TX line to a GPIO and drive it high too. */ // P0.18 back to GPIO LPC_PINCON->PINSEL1 &= ~(SPI_MOSI_FUNCMASK); LPC_GPIO0->FIODIR |= (1<<SPI_MOSI_PIN); LPC_GPIO0->FIOSET = (1<<SPI_MOSI_PIN); // low speed during init if_spiSetSpeed(254); /* Send 20 spi commands with card not selected */ for(i=0;i<21;i++) my_if_spiSend(file, 0xff); // P0.18 back to SPI LPC_PINCON->PINSEL1 |= (SPI_MOSI_FUNCBIT); }