|
Вот Вам библиотека работы с MMC для CodeVisionAVR делал на Меге16 работает. А вот где бы достать либу для поддержки FAT... Братцы - помогите, поделитесь исходничком. Может у кого есть"FlashFile - SD/MMC FAT12/16 File Systems for AVR" от www.prllc.com ?
Может кто успел скачать у них файлики но не смог раскриптовать?
Пришлите мне есть кряк.
Вот мыло "anoshin [ coбaчka ] bk,ru" (только поправить надо)
Другие исходники также приму с благодарностью.
Ну правда, очень надо.
/*
_______________________________________________
Icc-avr mailing list
Icc-avr@imagecraft.com
http://www.dragonsgate.net/mailman/listinfo/icc-avr
*/
//=======================================
#define SPIDDR DDRB
#define SPIPORT PORTB
#define SPIPIN PINB
#define SCLK 0x80
#define MOSI 0x20
#define MISO 0x40
#define CS 0x10
//#define MMCPOWER 0x10
int MMCInit(void);
void MMCInfo(void);
int MMCReadSector(unsigned long lba, char *s);
int MMCWriteSector(unsigned long lba, char *s);
unsigned char MMCGet(void);
unsigned char MMCDataToken(void);
void MMCCommand(unsigned char command, unsigned int px, unsigned int py);
unsigned char SpiByte(unsigned char byte);
/*************************************************************
* MMC Init function
*
* - flushes card receive buffer
* - selects card
* - sends the reset command
* - sends the initialization command, waits for card ready
*************************************************************/
int MMCInit(void)
{
unsigned int i;
//unsigned char Byte;
SPIDDR = SCLK + MOSI + CS;// + MMCPOWER; // start off with 80 bits of high data with card deselected // send CMD1 until we get a 0 back, indicating card is done initializing SPIPORT |= CS; /************************************************************ MMCCommand(10,0,0); printf("Manufacturer ID: %X %X %X\r",SpiByte(0xff),SpiByte(0xff),SpiByte(0xff)); // Skip 3 byte Manufacturer ID printf("MMC: Product Name : "); for (i=0;i<9;i++) SpiByte(0xff); // Read 9 left byte SPIPORT |= CS; /************************************************************ MMCCommand(17,(lba>>7) & 0xffff, (lba<<9) & 0xffff); for (i=0;i<512;i++) // read the sector /************************************************************ MMCCommand(24, (lba>>7)& 0xffff, (lba<<9)& 0xffff); SpiByte(0xfe); // Send Start Byte i = 0xffff; /************************************************************ while((Byte == 0xff) && (i--)) Byte = SpiByte(0xff); /************************************************************ while((Byte != 0xfe) && (i--)) Byte = SpiByte(0xff); /************************************************************ SpiByte(0xff); /*****************************************************
E-mail:
info@telesys.ru
SPIPORT = 0x00;
//delay_ms(500);
//SPIPORT |= MMCPOWER;
SPIPORT |= CS;
//Bit 7 6 5 4 3 2 1 0
//SPCR: SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0
// enable SPI as master, set clk divider
//SPCR = (1<
delay_ms(250);
for(i=0;i<10;i++)
SpiByte(0xff);
SPIPORT &= ~CS; // select card
// now send CMD0 - go to idle state
MMCCommand(0,0,0);
if (MMCGet() != 1)
{
SPIPORT |= CS;
return -1; // MMC Not detected
}
i = 0xffff;
while ((SpiByte(0xff) != 0) && (i--))
{
MMCCommand(1,0,0);
#asm("wdr");//WDR();
}
if (i == 0)
{
SPIPORT |= CS;
return -2; // Init Fail
}
return 0;
}
* void MMCInfo(void)
*
* - gets and prints formatted CID and CSD info from card
************************************************************/
void MMCInfo(void)
{
int i;
if (MMCDataToken() != 0xfe) printf("MMC: error during CID read\r");
else printf("MMC: CID read\r");
// SpiByte(0xff);
// SpiByte(0xff);
// SpiByte(0xff);
for (i=0;i<7;i++) printf("%c",SpiByte(0xff));//TxChar(SpiByte(0xff));
printf("\r");
}
* int MMCReadSector(unsigned long lba, unsigned char * s)
*
* - reads a sector from the card (512 bytes)
* - takes sector # as param
************************************************************/
int MMCReadSector(unsigned long lba, char *s)
{
unsigned int i;
if (MMCDataToken() != 0xfe) return -1;
{
*s++ = SpiByte(0xff);
}
SpiByte(0xff); // checksum -> don't care about it for now
SpiByte(0xff); // checksum -> don't care about it for now
SPIPORT |= CS;
return 0;
}
* int MMCWriteSector(unsigned long lba, unsigned char * s)
*
* - reads a sector from the card (512 bytes)
* - takes sector # as param
************************************************************/
int MMCWriteSector(unsigned long lba, char *s)
{
unsigned int i;
if (MMCGet() == 0xff) return -1;
for (i=0;i<512;i++) // read the sector
{
SpiByte(*s++);
}
SpiByte(0xff); // checksum -> don't care about it for now
SpiByte(0xff); // checksum -> don't care about it for now
SpiByte(0xff); // Read "data response byte"
while ((SpiByte(0xff) == 0x00) && (i--)); // wait for write finish
if (i == 0x00) return -1; // Error
SPIPORT |= CS;
return 0;
}
* unsigned char MMCGet(void)
*
* - pings the card until it gets a non-0xff value
* - returns one byte of read info
************************************************************/
unsigned char MMCGet(void)
{
unsigned int i;
unsigned char Byte = 0xff;
return Byte;
}
* int MMCDataToken(void)
*
* - pings the card until it gets data token
* - returns one byte of read info (data token)
************************************************************/
unsigned char MMCDataToken(void)
{
unsigned int i = 0xffff;
unsigned char Byte = 0xff;
return Byte;
}
* void MMCCommand(unsigned char command, unsigned int px, unsigned int py)
*
* - send one byte of 0xff, then issue command + params + (fake) crc
* - eat up the one command of nothing after the CRC
************************************************************/
void MMCCommand(unsigned char command, unsigned int px, unsigned int py)
{
SPIPORT &= ~CS;
SpiByte(0xff);
SpiByte(command | 0x40);
SpiByte((unsigned char)((px >> 8)&0x0ff)); // high byte of param y
SpiByte((unsigned char)(px & 0x00ff)); // low byte of param y
SpiByte((unsigned char)((py >> 8)&0x0ff)); // high byte of param x
SpiByte((unsigned char)(py & 0x00ff)); // low byte of param x
SpiByte(0x95); // correct CRC for first command in SPI
// after that CRC is ignored, so no problem with
// always sending 0x95
}
* Main SPI routine
* - transmits a byte and receives a byte simultaneously
* - received byte is returned
* - if you only want to read a byte, put a dummy
* (say 0xff) in the transmit slot
****************************************************/
unsigned char SpiByte(unsigned char byte)
{
#asm("wdr");//WDR();
SPDR = byte; // put byte to send in SPDR, which initiates xmit
while(!(SPSR & (0x80)));//(1<
}
Ответы