void dfmemRead (unsigned int page, unsigned int byte, unsigned int length, unsigned char *data) { while(!dfmemIsReady()); // Restructure page/byte addressing // 1 don't care bit + 13 page address bits + byte address bits MemAddr.address = (((unsigned long)page) << dfmem_geo.byte_address_bits) + byte; // Read data from memory dfmemSelectChip(); dfmemWriteByte(READ_PAGE); dfmemWriteByte(MemAddr.chr_addr[2]); dfmemWriteByte(MemAddr.chr_addr[1]); dfmemWriteByte(MemAddr.chr_addr[0]); dfmemWriteByte(0x00); // 4 don't care bytes dfmemWriteByte(0x00); dfmemWriteByte(0x00); dfmemWriteByte(0x00); unsigned int read_bytes; read_bytes = spic2MassTransmit(length, NULL, 2*length); dfmemSelectChip(); // Busy wait spic2ReadBuffer(read_bytes, data); // reads DMA buffer //while (length--) { *data++ = dfmemReadByte(); } dfmemDeselectChip(); }
void dfmemReadPage2Buffer (unsigned int page, unsigned char buffer) { unsigned char command; while(!dfmemIsReady()); // Choose command dependent on buffer choice if (buffer == 1) { command = READ_PAGE_TO_BUFFER_1; } else { command = READ_PAGE_TO_BUFFER_2; } // 1 don't care bit + 13 page address bits + don't care bits MemAddr.address = ((unsigned long)page) << dfmem_geo.byte_address_bits; // Write data to memory dfmemSelectChip(); dfmemWriteByte(command); dfmemWriteByte(MemAddr.chr_addr[2]); dfmemWriteByte(MemAddr.chr_addr[1]); dfmemWriteByte(MemAddr.chr_addr[0]); dfmemDeselectChip(); }
void dfmemWriteBuffer2MemoryNoErase (unsigned int page, unsigned char buffer) { unsigned char command; while(!dfmemIsReady()); // Choose command dependent on buffer choice if (buffer == 1) { command = WRITE_BUFFER1_TO_PAGE_NO_ERASE; } else { command = WRITE_BUFFER2_TO_PAGE_NO_ERASE; } // Restructure page/byte addressing // 1 don't care bit + 13 page address bits + don't care bits MemAddr.address = ((unsigned long)page) << dfmem_geo.byte_address_bits; // Write data to memory dfmemSelectChip(); dfmemWriteByte(command); dfmemWriteByte(MemAddr.chr_addr[2]); dfmemWriteByte(MemAddr.chr_addr[1]); dfmemWriteByte(MemAddr.chr_addr[0]); currentBufferOffset = 0; dfmemDeselectChip(); }
void dfmemWriteBuffer (unsigned char *data, unsigned int length, unsigned int byte, unsigned char buffer) { unsigned char command; // Choose command dependent on buffer choice if (buffer == 1) { command = WRITE_TO_BUFFER1; } else { command = WRITE_TO_BUFFER2; } // Restructure page/byte addressing // 14 don't care bit + byte address bits MemAddr.address = (unsigned long)byte; // Write data to memory dfmemSelectChip(); dfmemWriteByte(command); dfmemWriteByte(MemAddr.chr_addr[2]); dfmemWriteByte(MemAddr.chr_addr[1]); dfmemWriteByte(MemAddr.chr_addr[0]); spic2MassTransmit(length, data, 2*length); }
void dfmemWrite (unsigned char *data, unsigned int length, unsigned int page, unsigned int byte, unsigned char buffer) { unsigned char command; while(!dfmemIsReady()); // Choose command dependent on buffer choice if (buffer == 1) { command = WRITE_PAGE_VIA_BUFFER1; } else { command = WRITE_PAGE_VIA_BUFFER2; } // Restructure page/byte addressing // 1 don't care bit + 13 page address bits + byte address bits MemAddr.address = (((unsigned long)page) << dfmem_geo.byte_address_bits) + byte; // Write data to memory dfmemSelectChip(); dfmemWriteByte(command); dfmemWriteByte(MemAddr.chr_addr[2]); dfmemWriteByte(MemAddr.chr_addr[1]); dfmemWriteByte(MemAddr.chr_addr[0]); spic2MassTransmit(length, data, 2*length); //while (length--) { dfmemWriteByte(*data++); } //dfmemDeselectChip(); }
void dfmemRead (unsigned int page, unsigned int byte, unsigned int length, unsigned char *data) { while(!dfmemIsReady()); // Restructure page/byte addressing // 1 don't care bit + 13 page address bits + byte address bits MemAddr.address = (((unsigned long)page) << dfmem_byte_address_bits) + byte; // Read data from memory dfmemSelectChip(); dfmemWriteByte(READ_PAGE); dfmemWriteByte(MemAddr.chr_addr[2]); dfmemWriteByte(MemAddr.chr_addr[1]); dfmemWriteByte(MemAddr.chr_addr[0]); dfmemWriteByte(0x00); // 4 don't care bytes dfmemWriteByte(0x00); dfmemWriteByte(0x00); dfmemWriteByte(0x00); while (length--) { *data++ = dfmemReadByte(); } dfmemDeselectChip(); }
void dfmemResumeFromDeepSleep() { dfmemSelectChip(); dfmemWriteByte(0xAB); dfmemDeselectChip(); }
void dfmemDeepSleep() { dfmemSelectChip(); dfmemWriteByte(0xB9); dfmemDeselectChip(); }
// The manufacturer and device id command (0x9F) returns 4 bytes normally // (including info on id, family, density, etc.), but this functions returns // just the manufacturer id and discards the rest when de-selecting the chip. unsigned char dfmemGetManufacturerID (void) { unsigned char byte; dfmemSelectChip(); dfmemWriteByte(0x9F); byte = dfmemReadByte(); dfmemDeselectChip(); return byte; }
unsigned char dfmemGetStatus (void) { unsigned char byte; dfmemSelectChip(); dfmemWriteByte(0xD7); byte = dfmemReadByte(); dfmemDeselectChip(); return byte; }
void dfmemEraseChip (void) { while(!dfmemIsReady()); dfmemSelectChip(); dfmemWriteByte(0xC7); dfmemWriteByte(0x94); dfmemWriteByte(0x80); dfmemWriteByte(0x9A); dfmemDeselectChip(); }
// The manufacturer and device id command (0x9F) returns 4 bytes normally // (including info on id, family, density, etc.), but this functions returns // only the 5 bits pertaining to the memory density. unsigned char dfmemGetChipSize (void) { unsigned char byte; dfmemSelectChip(); dfmemWriteByte(0x9F); byte = dfmemReadByte(); // Manufacturer ID, not needed byte = dfmemReadByte() & 0b00011111; dfmemDeselectChip(); return byte; }
void dfmemEraseSector (unsigned int page) { while(!dfmemIsReady()); // Restructure page/byte addressing MemAddr.address = ((unsigned long)page) << dfmem_geo.byte_address_bits; // Write data to memory dfmemSelectChip(); dfmemWriteByte(ERASE_SECTOR); dfmemWriteByte(MemAddr.chr_addr[2]); dfmemWriteByte(MemAddr.chr_addr[1]); dfmemWriteByte(MemAddr.chr_addr[0]); dfmemDeselectChip(); }