Go to the documentation of this file.00001
00002
00003
00004 #ifndef DataFlash_h
00005 #define DataFlash_h
00006
00007
00008 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
00009 #define DF_DATAOUT 51 // MOSI
00010 #define DF_DATAIN 50 // MISO
00011 #define DF_SPICLOCK 52 // SCK
00012 #define DF_SLAVESELECT 53 // SS (PB0)
00013 #define DF_RESET 31 // RESET (PC6)
00014 #else // normal arduino SPI pins...
00015 #define DF_DATAOUT 11 //MOSI
00016 #define DF_DATAIN 12 //MISO
00017 #define DF_SPICLOCK 13 //SCK
00018 #define DF_SLAVESELECT 10 //SS
00019 #endif
00020
00021
00022 #define DF_TRANSFER_PAGE_TO_BUFFER_1 0x53
00023 #define DF_TRANSFER_PAGE_TO_BUFFER_2 0x55
00024 #define DF_STATUS_REGISTER_READ 0xD7
00025 #define DF_READ_MANUFACTURER_AND_DEVICE_ID 0x9F
00026 #define DF_PAGE_READ 0xD2
00027 #define DF_BUFFER_1_READ 0xD4
00028 #define DF_BUFFER_2_READ 0xD6
00029 #define DF_BUFFER_1_WRITE 0x84
00030 #define DF_BUFFER_2_WRITE 0x87
00031 #define DF_BUFFER_1_TO_PAGE_WITH_ERASE 0x83
00032 #define DF_BUFFER_2_TO_PAGE_WITH_ERASE 0x86
00033 #define DF_PAGE_ERASE 0x81
00034 #define DF_BLOCK_ERASE 0x50
00035 #define DF_SECTOR_ERASE 0x7C
00036 #define DF_CHIP_ERASE_0 0xC7
00037 #define DF_CHIP_ERASE_1 0x94
00038 #define DF_CHIP_ERASE_2 0x80
00039 #define DF_CHIP_ERASE_3 0x9A
00040
00041 class DataFlash_Class
00042 {
00043 private:
00044
00045 unsigned char df_BufferNum;
00046 unsigned char df_Read_BufferNum;
00047 unsigned int df_BufferIdx;
00048 unsigned int df_Read_BufferIdx;
00049 unsigned int df_PageAdr;
00050 unsigned int df_Read_PageAdr;
00051 unsigned char df_Read_END;
00052 unsigned char df_Stop_Write;
00053
00054 unsigned char BufferRead (unsigned char BufferNum, unsigned int IntPageAdr);
00055 void BufferWrite (unsigned char BufferNum, unsigned int IntPageAdr, unsigned char Data);
00056 void BufferToPage (unsigned char BufferNum, unsigned int PageAdr, unsigned char wait);
00057 void PageToBuffer(unsigned char BufferNum, unsigned int PageAdr);
00058 void WaitReady();
00059 unsigned char ReadStatus();
00060
00061 public:
00062 unsigned char df_manufacturer;
00063 unsigned char df_device_0;
00064 unsigned char df_device_1;
00065
00066 DataFlash_Class();
00067 void Init();
00068 void ReadManufacturerID();
00069 int GetPage();
00070 int GetWritePage();
00071 void PageErase (unsigned int PageAdr);
00072
00073 void StartWrite(int PageAdr);
00074 void WriteByte(unsigned char data);
00075 void WriteInt(int data);
00076 void WriteLong(long data);
00077
00078 void StartRead(int PageAdr);
00079 unsigned char ReadByte();
00080 int ReadInt();
00081 long ReadLong();
00082 };
00083
00084 extern DataFlash_Class DataFlash;
00085
00086 #endif