I want to write and read an SD Card connected to the PIC18F47K42.
I have read the datasheets and now I know that this PIC uses the Peripheral pin select so I worte this code:
Code: Select all
// MMC module connections
sfr sbit Mmc_Chip_Select at RD0_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISD0_bit;
void main() {
TRISC3_bit = 0; // Output
TRISC5_bit = 0; // Output
TRISD0_bit = 0; // Output
TRISC4_bit = 1; // Input
Unlock_IOLOCK();
// Output
RC3PPS = 0b011110; // SCK
RC5PPS = 0b011111; // SDO
RD0PPS = 0b100000; // SS
// Input
SPI1SDIPPS = 0b10100;
Lock_IOLOCK();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
if (Mmc_Fat_Init() == 0) {
// reinitialize spi at higher speed
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
}
}
PIN 23 SDI
PIN 18 SCK
PIN 24 SDO
PIN 19 CS
This code doesn't work and it blocks when SPI1_Init_Advanced is called.
Some idea?
Thank you.