PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : کتابخانه fat32 برای خواندن ونوشتن بروی mmc/sd؟



siamakb
12-08-2011, 20:50
سلام.
نماز و روزتون قبول.
کسی از دوستان تونسته با استفاده از سیستم fat32ومیکروlpc2378روی mmc/sd بخونه و بنویسه؟
ممنون.

alibme87
20-12-2011, 17:22
سلام. من هم همین سوال رو دارم. ما یه پروژه داریم که باید تو اون واحد mmc میکروی lpc2148 رو تو مد fat32 راه اندازی کنیم. اگه کسی کتابخونه ای چیزی داره، لطفا کمک کنه. ممنون میشم...

msmut7020
20-12-2011, 17:36
سلام. من هم همین سوال رو دارم. ما یه پروژه داریم که باید تو اون واحد mmc میکروی lpc2148 رو تو مد fat32 راه اندازی کنیم. اگه کسی کتابخونه ای چیزی داره، لطفا کمک کنه. ممنون میشم...
سلام.امیدوارم این به دردتون بخوره:

#include "sdcard.h"

//===================
//SDCard/MMC functions
//for LPC2148 (assumed connected to SPI1)
//===================

//Initialise the SD card (must have initialised SPI1)
unsigned int SDCardInit()
{
static unsigned char ucSDCmd_Idle[SD_CMD_LEN] = {0x40,0x00,0x00,0x00,0x00,0x95};
static unsigned char ucSDCmd_GetOpCond[SD_CMD_LEN] = {0x41, 0x00,0x00,0x00,0x00, 0xFF};

//unsigned char ucRepeatCount = SD_CMD_REPEAT_MAX;
unsigned int uiCount;

IOSET0 = SDCARD_CS;

//Send the card lots of clocks to activate it
for( uiCount=0; uiCount<10; uiCount++)
SPI1Byte(0xFF);

//Select slave
IOCLR0 = SDCARD_CS;

//Send CMD0
SPI1Send(ucSDCmd_Idle,SD_CMD_LEN);

//Wait for idle state return byte
if(SDResponseMatch(R1_IN_IDLE_STATE))
{
IOSET0 = SDCARD_CS;
return SD_WAKE_FAIL;
}

//At this point the card is now in its IDLE state
//Unselect slave
IOSET0 = SDCARD_CS;

//Send some dummy clocks to allow SD card to finish task
SPI1Byte(0xFF);
IOCLR0 = SDCARD_CS;

//Now bring card up to full power

//Repeat the command sequence until the SD card reaches full power
uiCount = SD_CMD_REPEAT_MAX;
do
{
SPI1Send(ucSDCmd_GetOpCond,SD_CMD_LEN);
}while(SDResponseMatch(0x00) && --uiCount);

if(!uiCount)
{
IOSET0 = SDCARD_CS;
return SD_INIT_FAIL;
}


//Send some more dummy clocks
IOSET0 = SDCARD_CS;
SPI1Byte(0xFF);

//Generate the CRC table
CRC16Bit_GenTable();

return 0;
}


//Keeps clocking the SD card until the specified byte is returned from the card
unsigned char SDResponseMatch(unsigned char ucDesired)
{
unsigned int uiCount = 0xFF;

//Keep clocking the SD card until the desired response is met
while( (SPI1Byte(0xFF) != ucDesired) && --uiCount);

//Return zero on success, nonzero on fail
return !uiCount;

}


//keeps clocking the card until the response doesnt match the given byte
unsigned char SDResponseDontMatch(unsigned char ucByte)
{
unsigned int uiCount = 0xFFFF;

//Keep clocking the SD card until the desired response is met
while( (SPI1Byte(0xFF) == ucByte) && uiCount--);

//Returns zero on success
return !uiCount;
}


//Write a 512 byte block at a given location (according to Sandisk SD card product manual, 512 bytes is minimum block len see pp5-1)
unsigned int SDWriteBlock(unsigned char *ucData, unsigned int uiBlockNum)
{
//Block addr Arguments to the SD card --phillips
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
static unsigned char ucSDCmd_Write[SD_CMD_LEN] = {0x18, 0x00,0x00,0x00,0x00, 0xFF};
unsigned char ucStatus;
unsigned int uiCheckSum;
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
//Set up leading framing bits (must be done *before* CRC)
ucSDCmd_Write[0] = (ucSDCmd_Write[0] | (1 << 6)) &0x7F;


//Convert Block adressing into byte addressing (multiply by SD Block Size)
uiBlockNum=uiBlockNum<<9;

ucSDCmd_Write[1] = (unsigned char) (uiBlockNum >> 24);
ucSDCmd_Write[2] = (unsigned char) (uiBlockNum >> 16);
ucSDCmd_Write[3] = (unsigned char) (uiBlockNum >> 8);
ucSDCmd_Write[4] = (unsigned char) (uiBlockNum);
//Append command CRC
ucSDCmd_Write[5] = CRC_7Bit(ucSDCmd_Write,5) << 1;
IOCLR0 = SDCARD_CS;


SPI1Send(ucSDCmd_Write,SD_CMD_LEN);

if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
//Response match failed
return SD_WRITE_CMD_FAIL;
}

//Calculate Checksum
uiCheckSum = CRC_16Bit(ucData,SD_BLOCK_SIZE);

//Send data begin token (bit 0 = 0)
SPI1Byte(0xFE);
//Send the data
SPI1Send(ucData,SD_BLOCK_SIZE);
//Send checksum bytes
SPI1Byte(uiCheckSum >> 8);
SPI1Byte(uiCheckSum & 0xFF);

//Send dummy data to get response info
ucStatus = SPI1Byte(0xFF);

//Check to see if Data was accepted
if((ucStatus & 0x0F) != SD_DATA_WRITE_OK)
{
IOSET0 = SDCARD_CS;

//See pp5-15 Sandisk SD product man (rev 1.9)
if( (ucStatus&0x0F) == 11)
return SD_WRITE_CRC_FAIL;

return SD_WRITE_DATA_FAIL;
}

//Now wait for card to complete write cycle
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
return SD_WRITE_RESPONSE_FAIL;
}

IOSET0 = SDCARD_CS;

SPI1Byte(0xFF);

return SD_WRITE_OK;

}


//UNTESTED
unsigned int SDReadBlockPart(unsigned char *data, unsigned int uiBlockNum,
unsigned int offset, unsigned int numBytes)
{
unsigned int uiCheckRcv;
static unsigned char ucSDCmd_Read[SD_CMD_LEN] = {0x11, 0x00,0x00,0x00,0x00,0xFF};

ucSDCmd_Read[0] = 0x11;

//Set up leading framing bits (must be done *before* CRC)
//TODO: (this can be statically calced)
ucSDCmd_Read[0] = (ucSDCmd_Read[0] | (1 << 6)) &0x7F;


//Convert Block adressing into byte addressing (multiply by SD Block Size)
uiBlockNum=uiBlockNum<<9;

ucSDCmd_Read[1] = (unsigned char) (uiBlockNum >> 24);
ucSDCmd_Read[2] = (unsigned char) (uiBlockNum >> 16);
ucSDCmd_Read[3] = (unsigned char) (uiBlockNum >> 8);
ucSDCmd_Read[4] = (unsigned char) (uiBlockNum);

ucSDCmd_Read[5] = CRC_7Bit(ucSDCmd_Read,5) << 1 | 1;
IOCLR0 = SDCARD_CS;


SPI1Send(ucSDCmd_Read,SD_CMD_LEN);

//Check that we recieved the apropriate respnse ( 0 indicates no error)
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
return SD_READ_CMD_FAIL; //This could be CRC or some other error
}

//Check for incoming data token (this is SUPPOSEDLY 0xFE, but 0xFF appears to work)
//TODO: find out why (card version wierdness? 0xFE for sandisk.... 0xFF for kodak)
if(SDResponseMatch(0xFE))
{
IOSET0 = SDCARD_CS;
return SD_READ_DATA_FAIL;
}


unsigned int uiCRC;
unsigned int curPos;
curPos=0;
uiCRC=0;

//Use init bytes for CRCing
while(curPos < offset)
{
uiCRC=CRC_16Bit_AddByte(uiCRC,SPI1Byte(0xFF));
curPos++;
}

//Grab actual Bytes
while(numBytes--)
{
*data = SPI1Byte(0xFF);
uiCRC=CRC_16Bit_AddByte(uiCRC,*data);
data++;
curPos++;
}
while(curPos < SD_BLOCK_SIZE)
{
uiCRC=CRC_16Bit_AddByte(uiCRC,SPI1Byte(0xFF));
curPos++;
}

//Recieve Checksum
uiCheckRcv = SPI1Byte(0xFF) << 8;
uiCheckRcv |= SPI1Byte(0xFF);

if(uiCheckRcv != uiCRC)
{
//CRC error!
IOSET0 = SDCARD_CS;
return SD_READ_CRC_FAIL;
}

IOSET0 = SDCARD_CS;

//Provide some clocks to the SD card (pp 5-6 sandisk SD product manual)
SPI1Byte(0xFF);


return SD_READ_OK;
}

//UNTESTED
unsigned int SDWriteBlockHead(unsigned char *data, unsigned int uiBlockNum,
unsigned int numBytes, unsigned char padding)
{
//Block addr Arguments to the SD card --phillips
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
static unsigned char ucSDCmd_Write[SD_CMD_LEN] = {0x18, 0x00,0x00,0x00,0x00, 0xFF};
unsigned char ucStatus;
unsigned int uiCheckSum;
unsigned int temp;
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
//Set up leading framing bits (must be done *before* CRC)
ucSDCmd_Write[0] = (ucSDCmd_Write[0] | (1 << 6)) &0x7F;


//Convert Block adressing into byte addressing (multiply by SD Block Size)
uiBlockNum=uiBlockNum<<9;

ucSDCmd_Write[1] = (unsigned char) (uiBlockNum >> 24);
ucSDCmd_Write[2] = (unsigned char) (uiBlockNum >> 16);
ucSDCmd_Write[3] = (unsigned char) (uiBlockNum >> 8);
ucSDCmd_Write[4] = (unsigned char) (uiBlockNum);
//Append command CRC
ucSDCmd_Write[5] = CRC_7Bit(ucSDCmd_Write,5) << 1;
IOCLR0 = SDCARD_CS;


SPI1Send(ucSDCmd_Write,SD_CMD_LEN);

if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
//Response match failed
return SD_WRITE_CMD_FAIL;
}

//Calculate Checksum
uiCheckSum = CRC_16Bit(data,numBytes);

//Send data begin token (bit 0 = 0)
SPI1Byte(0xFE);
temp=0;
while(temp++ < numBytes)
SPI1Byte(*(data+temp));

while(temp< SD_BLOCK_SIZE)
{
uiCheckSum = CRC_16Bit_AddByte(uiCheckSum,padding);
SPI1Byte(padding);
}

//Send checksum bytes
SPI1Byte(uiCheckSum >> 8);
SPI1Byte(uiCheckSum & 0xFF);

//Send dummy data to get response info
ucStatus = SPI1Byte(0xFF);

//Check to see if Data was accepted
if((ucStatus & 0x0F) != SD_DATA_WRITE_OK)
{
IOSET0 = SDCARD_CS;

//See pp5-15 Sandisk SD product man (rev 1.9)
if( (ucStatus&0x0F) == 11)
return SD_WRITE_CRC_FAIL;

return SD_WRITE_DATA_FAIL;
}

//Now wait for card to complete write cycle
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
return SD_WRITE_RESPONSE_FAIL;
}

IOSET0 = SDCARD_CS;

SPI1Byte(0xFF);

return SD_WRITE_OK;
}


//UNTESTED
unsigned int SDWriteMultiBlock(unsigned char *buffer, unsigned int uiBlockNum,
unsigned int numBlocks)
{

//Block addr Arguments to the SD card --phillips
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
static unsigned char ucSDCmd_MultiWrite[SD_CMD_LEN] = {0x19, 0x00,0x00,0x00,0x00, 0xFF};
unsigned char ucStatus;
unsigned int uiCheckSum;
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
//Set up leading framing bits (must be done *before* CRC)
ucSDCmd_MultiWrite[0] = (ucSDCmd_MultiWrite[0] | (1 << 6)) &0x7F;


//Convert Block adressing into byte addressing (multiply by SD Block Size)
uiBlockNum=uiBlockNum<<9;

ucSDCmd_MultiWrite[1] = (unsigned char) (uiBlockNum >> 24);
ucSDCmd_MultiWrite[2] = (unsigned char) (uiBlockNum >> 16);
ucSDCmd_MultiWrite[3] = (unsigned char) (uiBlockNum >> 8);
ucSDCmd_MultiWrite[4] = (unsigned char) (uiBlockNum);
//Append command CRC
ucSDCmd_MultiWrite[5] = CRC_7Bit(ucSDCmd_MultiWrite,5) << 1;

IOCLR0 = SDCARD_CS;

SPI1Send(ucSDCmd_MultiWrite,SD_CMD_LEN);

if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
//Response match failed
return (unsigned int)(-1);
}

unsigned int curBlock=0;

while(curBlock < numBlocks)
{
//Calculate Checksum
uiCheckSum = CRC_16Bit(buffer,SD_BLOCK_SIZE);
//send data token "start transmission"
SPI1Byte(0xFC);


//send block
SPI1Send(buffer,SD_BLOCK_SIZE);
buffer+=SD_BLOCK_SIZE;
//Send checksum bytes
SPI1Byte(uiCheckSum >> 8);
SPI1Byte(uiCheckSum & 0xFF);

ucStatus = SPI1Byte(0xFF);
if((ucStatus & 0x0F) != SD_DATA_WRITE_OK)
{
IOSET0 = SDCARD_CS;
if(curBlock)
return curBlock;
else
return (unsigned int) -1;
}

//Send dummy data to get response info
ucStatus = SPI1Byte(0xFF);

//Now wait for card to complete write cycle
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
if(curBlock)
return curBlock;
else
return (unsigned int) -1;

}
curBlock++;
}

//send stop token
SPI1Byte(0xFD);

SDResponseMatch(0x00);

return 0;
}

//UNTESTED
unsigned int SDFillMultiBlock(unsigned int startBlock,unsigned int endBlock, unsigned char fillByte)
{

//Block addr Arguments to the SD card --phillips
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
static unsigned char ucSDCmd_MultiWrite[SD_CMD_LEN] = {0x19, 0x00,0x00,0x00,0x00, 0xFF};
unsigned char ucStatus;
unsigned int uiCheckSum=0;
unsigned int numBlocks = endBlock-startBlock+1;
unsigned int curBlock=startBlock;
//unsigned int uiArgHigh;
//unsigned int uiArgLow;
//Set up leading framing bits (must be done *before* CRC)
ucSDCmd_MultiWrite[0] = (ucSDCmd_MultiWrite[0] | (1 << 6)) &0x7F;

//Convert Block adressing into byte addressing (multiply by SD Block Size)
startBlock=startBlock<<9;

ucSDCmd_MultiWrite[1] = (unsigned char) (startBlock >> 24);
ucSDCmd_MultiWrite[2] = (unsigned char) (startBlock >> 16);
ucSDCmd_MultiWrite[3] = (unsigned char) (startBlock >> 8);
ucSDCmd_MultiWrite[4] = (unsigned char) (startBlock);
//Append command CRC
ucSDCmd_MultiWrite[5] = CRC_7Bit(ucSDCmd_MultiWrite,5) << 1;

IOCLR0 = SDCARD_CS;

SPI1Send(ucSDCmd_MultiWrite,SD_CMD_LEN);

if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
//Response match failed
return (unsigned int)(-1);
}

unsigned int tmp=0;

//Pre-Calculate Checksum
while(tmp++ < SD_BLOCK_SIZE)
uiCheckSum = CRC_16Bit_AddByte(uiCheckSum,fillByte);


while(curBlock < numBlocks)
{
//send data token "start transmission"
SPI1Byte(0xFC);
tmp=0;
//send block
while(tmp++ < SD_BLOCK_SIZE)
SPI1Byte(fillByte);

//Send checksum bytes
SPI1Byte(uiCheckSum >> 8);
SPI1Byte(uiCheckSum & 0xFF);

ucStatus = SPI1Byte(0xFF);
if((ucStatus & 0x0F) != SD_DATA_WRITE_OK)
{
IOSET0 = SDCARD_CS;
if(curBlock)
return curBlock;
else
return (unsigned int) -1;
}

//Send dummy data to get response info
ucStatus = SPI1Byte(0xFF);

//Now wait for card to complete write cycle
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
if(curBlock)
return curBlock;
else
return (unsigned int) -1;

}
curBlock++;
}

//send stop token
SPI1Byte(0xFD);

//wait for busy flag to clear
SDResponseMatch(0x00);

IOSET0 = SDCARD_CS;

return 0;
}

//Read a 512 block of data on the SD card (pointer must point to a writable 512byte array!)
unsigned int SDReadBlock(unsigned char *pData, unsigned int uiBlockNum)
{
unsigned int uiCheckRcv;
static unsigned char ucSDCmd_Read[SD_CMD_LEN] = {0x11, 0x00,0x00,0x00,0x00,0xFF};

ucSDCmd_Read[0] = 0x11;

//Set up leading framing bits (must be done *before* CRC)
//TODO: (this can be statically calced)
ucSDCmd_Read[0] = (ucSDCmd_Read[0] | (1 << 6)) &0x7F;


//Convert Block adressing into byte addressing (multiply by SD Block Size)
uiBlockNum=uiBlockNum<<9;

ucSDCmd_Read[1] = (unsigned char) (uiBlockNum >> 24);
ucSDCmd_Read[2] = (unsigned char) (uiBlockNum >> 16);
ucSDCmd_Read[3] = (unsigned char) (uiBlockNum >> 8);
ucSDCmd_Read[4] = (unsigned char) (uiBlockNum);

ucSDCmd_Read[5] = CRC_7Bit(ucSDCmd_Read,5) << 1 | 1;
IOCLR0 = SDCARD_CS;


SPI1Send(ucSDCmd_Read,SD_CMD_LEN);

//Check that we recieved the apropriate respnse ( 0 indicates no error)
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
return SD_READ_CMD_FAIL; //This could be CRC or some other error
}

//Check for incoming data token (this is SUPPOSEDLY 0xFE, but 0xFF appears to work)
//TODO: find out why (card version wierdness? 0xFE for sandisk.... 0xFF for kodak)
if(SDResponseMatch(0xFE))
{
IOSET0 = SDCARD_CS;
return SD_READ_DATA_FAIL;
}

//Recieve data
SPI1Recieve(pData,SD_BLOCK_SIZE);

//Recieve Checksum
uiCheckRcv = SPI1Byte(0xFF) << 8;
uiCheckRcv |= SPI1Byte(0xFF);

if(uiCheckRcv != CRC_16Bit(pData,SD_BLOCK_SIZE))
{
//CRC error!
IOSET0 = SDCARD_CS;
return SD_READ_CRC_FAIL;
}

IOSET0 = SDCARD_CS;

//Provide some clocks to the SD card (pp 5-6 sandisk SD product manual)
SPI1Byte(0xFF);


return SD_READ_OK;

}

//UNTESTED
unsigned int SDReadBlockHead(unsigned char *buffer, unsigned int uiBlockNum,
unsigned int numBytes)
{
unsigned int uiCheckRcv,tmp,runSum;
static unsigned char ucSDCmd_Read[SD_CMD_LEN] = {0x11, 0x00,0x00,0x00,0x00,0xFF};

ucSDCmd_Read[0] = 0x11;

//Set up leading framing bits (must be done *before* CRC)
//TODO: (this can be statically calced)
ucSDCmd_Read[0] = (ucSDCmd_Read[0] | (1 << 6)) &0x7F;


//Convert Block adressing into byte addressing (multiply by SD Block Size)
uiBlockNum=uiBlockNum<<9;

ucSDCmd_Read[1] = (unsigned char) (uiBlockNum >> 24);
ucSDCmd_Read[2] = (unsigned char) (uiBlockNum >> 16);
ucSDCmd_Read[3] = (unsigned char) (uiBlockNum >> 8);
ucSDCmd_Read[4] = (unsigned char) (uiBlockNum);

ucSDCmd_Read[5] = CRC_7Bit(ucSDCmd_Read,5) << 1 | 1;
IOCLR0 = SDCARD_CS;


SPI1Send(ucSDCmd_Read,SD_CMD_LEN);

//Check that we recieved the apropriate respnse ( 0 indicates no error)
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
return SD_READ_CMD_FAIL; //This could be CRC or some other error
}

//Check for incoming data token
//TODO: find out why sometimes 0xFE sometimes 0xFF(card version wierdness? 0xFE for sandisk.... 0xFF for kodak)
if(SDResponseMatch(0xFE))
{
IOSET0 = SDCARD_CS;
return SD_READ_DATA_FAIL;
}

//Receive data
tmp = 0;
while(tmp < numBytes)
{
*(buffer+tmp) = SPI1Byte(0xFF);
tmp++;
}
runSum = CRC_16Bit(buffer,tmp);

while(tmp<SD_BLOCK_SIZE)
{
runSum=CRC_16Bit_AddByte(runSum,SPI1Byte(0xFF));
tmp++;
}
//Recieve Checksum
uiCheckRcv = SPI1Byte(0xFF) << 8;
uiCheckRcv |= SPI1Byte(0xFF);

if(uiCheckRcv!=runSum)
{
//CRC error!
IOSET0 = SDCARD_CS;
return SD_READ_CRC_FAIL;
}

IOSET0 = SDCARD_CS;

//Provide some clocks to the SD card (pp 5-6 sandisk SD product manual)
SPI1Byte(0xFF);

return SD_READ_OK;
}

// Activates or disables CRC checking on SD card (0 = off 1 = on)
unsigned int SDSetCRC(unsigned int uiCRC)
{
static unsigned char ucSDSetCRC[SD_CMD_LEN] = {0x3B, 0x00,0x00,0x00,0x00,0xFF};

unsigned char ucCRC;
ucSDSetCRC[0]= 0x3B;
//tail bit of uiCRC sets or clears CRC mode
ucSDSetCRC[4] = uiCRC & 0x01;

//TODO: Can optimise this by examining two cases for CRC and recording them..
//Calculate CRC and framing bits
ucSDSetCRC [0] = (ucSDSetCRC[0] | (1 << 6)) &0x7F;
ucCRC =CRC_7Bit(ucSDSetCRC,5);
ucSDSetCRC[5] = ucCRC<< 1 | 1;



IOCLR0=SDCARD_CS;
SPI1Send(ucSDSetCRC,SD_CMD_LEN);

//Check that we recieved the apropriate respnse ( 0 indicates no error)
if(SDResponseMatch(0x00))
{
IOSET0 = SDCARD_CS;
return SD_CMD_FAIL; //This could be CRC or some other error
}

IOSET0 = SDCARD_CS;

//Provide some clocks to the SD card (pp 5-6 sandisk SD product manual)
SPI1Byte(0xFF);
return 0;
}

//CSD is 16bytes
//Returns 0 on sucess, nonzero on fail
unsigned int SDGetCSDRegister(unsigned char *cpBuffer)
{
static unsigned char ucSDCmd_GetCSD[SD_CMD_LEN] = {0x09,
0x00,0x00,0x00,0x00,0xFF};
ucSDCmd_GetCSD[0] = 0x09;

//Set up leading framing bits (must be done *before* CRC)
//TODO: (this can be statically calced)
ucSDCmd_GetCSD[0] = (ucSDCmd_GetCSD[0] | (1 << 6)) &0x7F;

//Set up trailing CRC byte (7 bit crc followed by stop bit)
ucSDCmd_GetCSD[5] = CRC_7Bit(ucSDCmd_GetCSD,5) << 1 | 1;
IOCLR0 = SDCARD_CS;


SPI1Send(ucSDCmd_GetCSD,SD_CMD_LEN);

//Wait for appropriate responset token (sd.c from efs project)
if(SDResponseMatch(0xFE))
{
IOSET0=SDCARD_CS;
return SD_GET_CSD_FAIL;
}

SPI1Recieve(cpBuffer,16);

IOSET0=SDCARD_CS;
return 0;
}


unsigned int SDCardGetBlockCount()
{
static unsigned char raw_csd[16];
unsigned short c_size=0;
unsigned short c_size_mult=0;
if( SDGetCSDRegister(raw_csd) )
return 0;


c_size = ((((unsigned short)raw_csd[6]) & 0x03) << 10) |
(((unsigned short)raw_csd[7]) << 2) |
(((unsigned short)raw_csd[8]) & 0xc0) >> 6;
c_size_mult = ((raw_csd[9] & 0x03) << 1) | ((raw_csd[10] & 0x80) >> 7);
return ((unsigned int)(c_size+1)) * (1 << (c_size_mult + 2));
}

unsigned int SDCardGetBlockSize()
{
static unsigned char raw_csd[16];

if( SDGetCSDRegister(raw_csd) )
return 0;

return 1 << (raw_csd[5] & 0x0f) ;
}

Aghaeifar
20-12-2011, 21:30
msmut7020 (You can see links before reply) اینی که الان گذاشتید برای Fat هست یا غیر Fat ؟

میشه اون هدر که در ابتدای سورس انکلود شده رو هم قرار بدید.

#include "sdcard.h"

msmut7020
21-12-2011, 00:38
msmut7020 (You can see links before reply) اینی که الان گذاشتید برای fat هست یا غیر fat ؟

میشه اون هدر که در ابتدای سورس انکلود شده رو هم قرار بدید.

#include "sdcard.h"

سلام.نمیدونم مال چی هست. این فایل توی دسکتاپم بود.میخاستم حذفش کنم که دیدم این سوال توی انجمن مطرح شده.اگه تونستم اسم سایتش را میذارم

shayanmelody
21-12-2011, 10:20
سلام.
مشخصه كه داره سكتوري كار ميكنه.

msmut7020
21-12-2011, 17:28
سلام.من برگشتم با یه خبر خوب.اسم سایته را پیدا کردم.خودم تعجب کردم.عجب سایت باحالیه.امیدوارم برای دوستان مفید باشه:
You can see links before reply

agape
21-12-2011, 19:00
سلام به تمام دوستان گلم !
خوب چرا اینقدر خودتون رو زحمت میدید ؟
چرا از rl-arm استفاده نمیکنید ؟
من قبلا باهاش کار کردم - کار میکنه و خوب هم جواب میده !

Amirkhan_0o0
02-12-2012, 17:04
سلام به تمام دوستان گلم !
خوب چرا اینقدر خودتون رو زحمت میدید ؟
چرا از rl-arm استفاده نمیکنید ؟
من قبلا باهاش کار کردم - کار میکنه و خوب هم جواب میده !
ببخشید من تازه کارم و با Cکد می زنم.
می شه توضیح بدین این rl-arm یعنی چی؟؟
لطفا نخندینا:0013:

Amirkhan_0o0
18-12-2012, 18:35
سلام به تمام دوستان گلم !
خوب چرا اینقدر خودتون رو زحمت میدید ؟
چرا از rl-arm استفاده نمیکنید ؟
من قبلا باهاش کار کردم - کار میکنه و خوب هم جواب میده !
یه سوال
mmc با بوت لودر مشکل داره؟؟
یعنی با بوت لودر نمی شه با mmc ارتباط برقرار کرد؟؟

bg_asa2000
30-12-2012, 12:03
سلام به تمام دوستان گلم !
خوب چرا اینقدر خودتون رو زحمت میدید ؟
چرا از rl-arm استفاده نمیکنید ؟
من قبلا باهاش کار کردم - کار میکنه و خوب هم جواب میده !

سلام مهندس مزارعی عزیز
من دارم با RL-ARM برای LPC1768 برنامه می نویسم، اما با این Error مواجه شدم و هیچ جور حل نمیشه:
identifier "mmcfg" is undefined
در حقیقت تعریف SDCardCfg را در کتابخانه پیدا نمیکنه. لایسنس KEIL و RL-ARM را هم نصب کردم.
شما چطور این مشکل را حل کردید ؟

majidma3000
02-01-2013, 02:10
برای استفاده از rl-ARM به RTX نیاز دارید، اگه میخوایین از RTX استفاده نکنین میتوند از ff.h استفاده کنین. من باهاش کار کردم و خوب هم جواب داده.
البته اگه بتونید از RL-ARM استفاده کنید خیلی بهتره.
اگه خواستین بگید تا آموزش ff.h رو شروع کنم

mahdi_el2000
18-01-2013, 17:44
اقا نیکی و پرسش . اقا خیلی خوبه که یه اموزش برای این باشه.

mzarkoob
18-01-2013, 19:49
اگه خواستین بگید تا آموزش ff.h رو شروع کنم
می خواهیم !! :wink::mrgreen:

Amirkhan_0o0
20-01-2013, 23:02
برای استفاده از rl-arm به rtx نیاز دارید، اگه میخوایین از rtx استفاده نکنین میتوند از ff.h استفاده کنین. من باهاش کار کردم و خوب هم جواب داده.
البته اگه بتونید از rl-arm استفاده کنید خیلی بهتره.
اگه خواستین بگید تا آموزش ff.h رو شروع کنم
شروع کن برادر!
این اپلیکیشن نوت همراهش یک کمی گنگه

majidma3000
21-01-2013, 16:53
آموزش ff.h یا RTL ؟
از ff.h برای AVR هم میتونید استفاده کنید.