|
|
View previous topic :: View next topic |
Author |
Message |
temopic
Joined: 20 Feb 2008 Posts: 27 Location: mexico
|
Driver / help required for atmel AT45DB161D |
Posted: Sat Feb 14, 2009 8:48 pm |
|
|
Could some one help regarding a driver for a AT45DB161D, I am using a pic18f4520 and the PCWHD 4.065 but waiting for my latest version licence for upgrade, already bought |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Sat Feb 14, 2009 9:24 pm |
|
|
A search with google turned up some Dataflash info that may help you get started:
Additionally, the below page has links to Dataflash driver C code that should give you a framework for how it's done and looks like it will translate fairly easily.
http://blog.blockos.org/?tag=arduino
It appears the CCS command spi_xfer() would be the equivalent to thier command spi_transfer()
. |
|
|
drdelphi
Joined: 22 Apr 2007 Posts: 22 Location: Romania
|
|
Posted: Sun Feb 15, 2009 4:19 am |
|
|
try this :
Code: | #define FLASH_SELECT PIN_... // output
#define FLASH_CLOCK PIN_... // output
#define FLASH_DI PIN_... // output
#define FLASH_DO PIN_... // input
void init_ext_flash(void);
void ext_flash_startContinuousRead(int pageAddress);
void ext_flash_sendData(int data, int size);
void ext_flash_sendBytes(char* data, int size);
void ext_flash_getBytes(char* data, int size);
void ext_flash_readPage(int pageAddress, int pageIndex, char* data, int size);
void ext_flash_writePageThroughBuffer(int pageAddress, char* data, int size);
int ext_flash_getByte(void);
void ext_flash_waitUntilReady(void);
void init_ext_flash(void) {
output_low(FLASH_CLOCK);
output_high(FLASH_SELECT);
}
void ext_flash_startContinuousRead(int pageAddress) {
ext_flash_waitUntilReady();
output_low(FLASH_SELECT);
ext_flash_sendData(0xE8, 8);
ext_flash_sendData(pageAddress, 14);
ext_flash_sendData(0, 10);
ext_flash_sendData(0, 16);
ext_flash_sendData(0, 16);
}
int ext_flash_getByte(void) {
int flashData = 0;
output_high(FLASH_CLOCK); flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
return(flashData);
}
void ext_flash_getBytes(char* data, int size) {
int i, j;
for(i = 0; i < size; i++) {
for(j = 0; j < 8; j++) {
output_high(FLASH_CLOCK);
shift_left(data + i, 1, input(FLASH_DO));
output_low(FLASH_CLOCK);
}
}
}
void ext_flash_readPage(int pageAddress, int pageIndex, char* data, int size) {
ext_flash_waitUntilReady();
output_low(FLASH_SELECT);
ext_flash_sendData(0xD2, 8);
ext_flash_sendData(pageAddress, 14);
ext_flash_sendData(pageIndex, 10);
ext_flash_sendData(0, 16);
ext_flash_sendData(0, 16);
ext_flash_getBytes(data, size);
output_high(FLASH_SELECT);
}
void ext_flash_writePageThroughBuffer(int pageAddress, char* data, int size) {
int i;
ext_flash_waitUntilReady();
output_low(FLASH_SELECT);
ext_flash_sendData(0x82, 8);
ext_flash_sendData(pageAddress, 14);
ext_flash_sendData(0, 10);
for (i = 0; i < size; i++)
ext_flash_sendData((int)data[i], 8);
output_high(FLASH_SELECT);
}
void ext_flash_sendData(int data, int size) {
do {
size--;
output_bit(FLASH_DI, (data >> size) & 1);
output_high(FLASH_CLOCK);
output_low(FLASH_CLOCK);
} while(size > 0);
}
void ext_flash_sendBytes(char* data, int size) {
int i;
for (i = 0; i < size; i++)
ext_flash_sendData((int)data[i], 8);
}
void ext_flash_waitUntilReady(void) {
int flashData;
output_low(FLASH_SELECT);
output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
output_bit(FLASH_DI, 0); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
output_bit(FLASH_DI, 0); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
output_bit(FLASH_DI, 1); output_high(FLASH_CLOCK); output_low(FLASH_CLOCK);
for(;;) {
flashData = 0;
output_high(FLASH_CLOCK); flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
output_high(FLASH_CLOCK); flashData *= 2; flashData += input(FLASH_DO); output_low(FLASH_CLOCK);
if (flashData == 172) break;
}
output_high(FLASH_SELECT);
} |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|