Pic FSInit();CE“坏分区”;
我使用的是PIC18F26K80和XC8编译器。我正在尝试初始化SD卡并创建一个文件。我只是在Windows上格式化SD卡,使其具有“FAT32”文件系统和512字节的“分配单元大小”。SD卡的容量为2GB。我正在使用MLA遗留版本中的MDD库。我的主要意见如下:Pic FSInit();CE“坏分区”;,pic,spi,fat32,Pic,Spi,Fat32,我使用的是PIC18F26K80和XC8编译器。我正在尝试初始化SD卡并创建一个文件。我只是在Windows上格式化SD卡,使其具有“FAT32”文件系统和512字节的“分配单元大小”。SD卡的容量为2GB。我正在使用MLA遗留版本中的MDD库。我的主要意见如下: FSFILE * file; char sendBuffer[22] = "This is test string 1"; //************************************************** /
FSFILE * file;
char sendBuffer[22] = "This is test string 1";
//**************************************************
// main function
//**************************************************
int main()
{
initIO();
LATBbits.LATB0 = 0;
// Initialise SPI and SD-card
while ( !MDD_MediaDetect() );
// Initialize the device
while ( !FSInit() );
// Initialize
#ifdef ALLOW_WRITES
// Create a new file
file = FSfopenpgm ( "FILE.TXT", "w" );
if ( file == NULL )
while(1);
// Write 21 1-byte objects from sendBuffer into the file
if ( FSfwrite ( (void *) sendBuffer, 1, 21, file ) != 21 )
while(1);
// Close the file
if ( FSfclose ( file ) )
while(1);
#endif
LATBbits.LATB0 = 1; //LED
while(1) {}
return (0);
}
//==============================================================================
// void initIO( void );
//==============================================================================
// Sets the pins on the PIC to input or output and determines the speed of the
// internal oscilaltor
// input: none
// return: none
//==============================================================================
void initIO()
{
OSCCON = 0x75; // Clock speed = 32MHz (4x8Mhz)
TRISA = 0;
TRISB = 0;
TRISC = 0;
TRISBbits.TRISB0 = 0; //LED
TRISCbits.TRISC3 = 0; // set SCL pin as output
TRISCbits.TRISC4 = 1; // set RC4 pin as input
TRISCbits.TRISC5 = 0;
TRISAbits.TRISA5 = 0;
}
程序卡在函数“FSInit()”中,我从函数中得到的错误是“CE_BAD_PARTITION”,这意味着“引导记录不好”
“initIO()”函数如下所示:
FSFILE * file;
char sendBuffer[22] = "This is test string 1";
//**************************************************
// main function
//**************************************************
int main()
{
initIO();
LATBbits.LATB0 = 0;
// Initialise SPI and SD-card
while ( !MDD_MediaDetect() );
// Initialize the device
while ( !FSInit() );
// Initialize
#ifdef ALLOW_WRITES
// Create a new file
file = FSfopenpgm ( "FILE.TXT", "w" );
if ( file == NULL )
while(1);
// Write 21 1-byte objects from sendBuffer into the file
if ( FSfwrite ( (void *) sendBuffer, 1, 21, file ) != 21 )
while(1);
// Close the file
if ( FSfclose ( file ) )
while(1);
#endif
LATBbits.LATB0 = 1; //LED
while(1) {}
return (0);
}
//==============================================================================
// void initIO( void );
//==============================================================================
// Sets the pins on the PIC to input or output and determines the speed of the
// internal oscilaltor
// input: none
// return: none
//==============================================================================
void initIO()
{
OSCCON = 0x75; // Clock speed = 32MHz (4x8Mhz)
TRISA = 0;
TRISB = 0;
TRISC = 0;
TRISBbits.TRISB0 = 0; //LED
TRISCbits.TRISC3 = 0; // set SCL pin as output
TRISCbits.TRISC4 = 1; // set RC4 pin as input
TRISCbits.TRISC5 = 0;
TRISAbits.TRISA5 = 0;
}
尝试使用SD卡格式化程序格式化SD卡。选择选项为“完全擦除”,然后它将擦除SD卡的所有部分,这是普通格式选项无法做到的。从这个链接下载:@Amol我试过了。它确实抹掉了一切,但我仍然得到同样的错误。