CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Driver / help required for atmel AT45DB161D

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
temopic



Joined: 20 Feb 2008
Posts: 27
Location: mexico

View user's profile Send private message MSN Messenger

Driver / help required for atmel AT45DB161D
PostPosted: Sat Feb 14, 2009 8:48 pm     Reply with quote

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: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Feb 14, 2009 9:24 pm     Reply with quote

A search with google turned up some Dataflash info that may help you get started:

Quote:
A free example which uses a generic approach, suitable for most microcontrollers, can be found as a driver for BeRTOS, and is available from http://www.bertos.org/doxygen/reference/dataflash_8c.html?path=%2Fvar%2Fwww%2Fhtml%2Fbertos%2Freference%2Fdataflash_8c.html


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

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Feb 15, 2009 4:19 am     Reply with quote

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);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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