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 support@ccsinfo.com

Atmel AT45DB041 write & read data problem -- CCS Driver

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



Joined: 23 Apr 2011
Posts: 11
Location: South Africa

View user's profile Send private message

Atmel AT45DB041 write & read data problem -- CCS Driver
PostPosted: Tue Nov 20, 2012 2:04 pm     Reply with quote

Hello Guys

My problem is as follows, using the CCS provided at45db041.c driver.

Writing a byte (int8) of 240 dec or 0b1111 0000 to the EEPROM returns 249 or 0b1111 1001 .

When I write data that change the lower nibble then the driver work correctly - 248 dec or 0b1111 1000 work perfect, or 0b1111 1010 works perfect.

Why will the lower nibble be changed to 1001 when its actual value is 0000 ?

Thank you.

Code as follow :
Code:

#ifndef AT45DB011_C
#define AT45DB011_C
#ifndef FLASH_SELECT
   #define FLASH_SELECT PIN_D7
   #define FLASH_CLOCK  PIN_C3
   #define FLASH_DI     PIN_C5
   #define FLASH_DO     PIN_C4
#endif

#define write_ext_eeprom_buf write_ext_eeprom
#define read_ext_eeprom_buf read_ext_eeprom
 
typedef int32 EEPROM_ADDRESS;

#ifndef FLASH_BUFFER_SIZE
   #define FLASH_BUFFER_SIZE    264     // bytes per page
   #define FLASH_BUFFER_COUNT   512     // page count
#endif

#define FLASH_SIZE ((int32)FLASH_BUFFER_SIZE*FLASH_BUFFER_COUNT)  // The size of the flash device in bytes

// Used in ext_flash_BufferToPage()
#define ERASE     1  // The flash device will initiate an erase before writing
#define NO_ERASE  0  // The flash device will not initiate an erase before writing

#ifndef EXT_FLASH_WRITE_BUFFER
   #define EXT_FLASH_WRITE_BUFFER   0
#endif

void ext_flash_sendData(int16 data, int8 size);
void ext_flash_sendBytes(BYTE* data, int16 size);
void ext_flash_getBytes(BYTE* data, int16 size);
void ext_flash_waitUntilReady();

#define init_ext_eeprom() init_ext_flash()

int16 g_ExtFlashCurrPage;
int16 g_ExtFlashCurrIndex;

// Purpose:       Initialize the pins that control the flash device.
//                This must be called before any other flash function is used.
// Inputs:        None
// Outputs:       None
// Dependencies:  None
void init_ext_flash()
{
   output_low(FLASH_CLOCK);
   output_high(FLASH_SELECT);
}


// Purpose:       This function will start reading a continuous stream of
//                data from the entire flash device.
// Inputs:        1) A page address
//                2) An index into the page
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady()
void ext_flash_startContinuousRead(int16 pageAddress, int16 pageIndex)
{
   ext_flash_waitUntilReady();
   output_low(FLASH_SELECT);                 // Enable select line
   ext_flash_sendData(0xE8, 8);              // Send opcode
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(pageIndex, 9);         // Send index and 32 bits
   ext_flash_sendData(0, 32);                // Send 32 don't care bits
}

//NEW:
// Purpose:       Given an absolute address of the EEPROM, find the page and
//                page index of that address.
// Inputs:        1) The absolute address
//                2) Pointer, where result page address will be saved
//                3) Pointer, where result page index will be saved.
// Outputs:       NONE
// Dependencies:  NONE
void ext_flash_findPage(int32 address, int16 *pageAddress, int16 *pageIndex)
{
   *pageAddress = (int32)address / FLASH_BUFFER_SIZE;
   *pageIndex = (int32)address % FLASH_BUFFER_SIZE;
}

//NEW:
// Purpose:       This function will start reading a continuous stream of
//                data from the entire flash device.
// Inputs:        1) An absolute address
// Outputs:       None
// Dependencies:  ext_flash_startContinuousRead(p,i)
void ext_flash_startContinuousRead(int32 address)
{
   int16 pageAddress, pageIndex;
   
   ext_flash_findPage(address, &pageAddress, &pageIndex);
   ext_flash_startContinuousRead(pageAddress, pageIndex);
}

// Purpose:       Get a byte of data from the flash device. This function is
//                meant to be used after ext_flash_startContinuousRead() has
//                been called to initiate a continuous read.
// Inputs:        None
// Outputs:       1) A byte of data
// Dependencies:  None
BYTE ext_flash_getByte()
{
   BYTE flashData;
   int i;
   for(i=0; i<8; ++i)                        // Get 8 bits of data
   {
      output_high(FLASH_CLOCK);
      shift_left(&flashData, 1, input(FLASH_DO));
      output_low(FLASH_CLOCK);
   }
   return flashData;
}


// Purpose:       Get a byte of data from the flash device. This function is
//                meant to be used after ext_flash_startContinuousRead() has
//                been called to initiate a continuous read. This function is
//                also used by ext_flash_readPage() and ext_flash_readBuffer().
// Inputs:        1) A pointer to an array to fill
//                2) The number of bytes of data to read
// Outputs:       None
// Dependencies:  None
void ext_flash_getBytes(BYTE* data, int16 size)
{
   int16 i;
   signed int8  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);
      }
   }
}

// Purpose:       Stop continuously reading data from the flash device.
// Inputs:        None
// Outputs:       None
// Dependencies:  None               
void ext_flash_stopContinuousRead()
{
   output_high(FLASH_SELECT);                // Disable select line
}

//NEW:
// Purpose:       Read len bytes from the flash device, saves to ptr.
//                Will start and stop a continous read.
// Inputs:        1) The absolute address in the flash to start reading
//                2) Where in PIC ram to save result.
//                3) Number of bytes to read.
// Outputs:       None (result saved to ptr)
// Dependencies:  ext_flash_startContinuousRead(), ext_flash_getBytes(),
//                ext_flash_stopContinuousRead()               
void ext_flash_readBytes(int32 address, int8 *ptr, int16 len)
{
   ext_flash_startContinuousRead(address);
   ext_flash_getBytes(ptr, len);
   ext_flash_stopContinuousRead();   
}


// Purpose:       Read data from a memory page.
// Inputs:        1) A page address
//                2) An index into the page to start reading at
//                3) A pointer to a data array to fill
//                4) The number of bytes of data to read
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady(), ext_flash_getBytes()
void ext_flash_readPage(int16 pageAddress, int16 pageIndex, BYTE* data, int16 size)
{
   ext_flash_waitUntilReady();               // Wait until ready
   output_low(FLASH_SELECT);                 // Enable select line
   ext_flash_sendData(0xD2, 8);              // Send opcode and 5 bits
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(pageIndex, 9);         // Send index
   ext_flash_sendData(0, 32);                // Send 32 don't care bits
   ext_flash_getBytes(data, size);           // Get data from the flash device
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Read data from a buffer
// Inputs:        1) A buffer number (0 or 1)
//                2) An index into the buffer to start reading at
//                3) A pointer to a data array to be filled
//                4) The number of bytes of data to read
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady(), ext_flash_getBytes()
void ext_flash_readBuffer(int1 bufferNumber, int16 bufferAddress, BYTE* data, int16 size)
{
   BYTE opcode;

   output_low(FLASH_SELECT);                 // Enable select line

   if(bufferNumber)
      opcode = 0xD6;                         // Opcode for second buffer
   else
      opcode = 0xD4;                         // Opcode for first buffer

   ext_flash_sendData(opcode, 8);            // Send opcode
   ext_flash_sendData(0, 15);                // Send 15 don't care bits
   ext_flash_sendData(bufferAddress, 9);     // Send buffer address
   ext_flash_sendData(0, 8);                 // Send 8 don't care bits
   ext_flash_getBytes(data, size);           // Get data from the flash device
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Return the status of the flash device
// Inputs:        None            ____
// Outputs:       The status: Rdy/Busy Comp 0101XX
// Dependencies:  ext_flash_sendData(), ext_flash_getByte()
BYTE ext_flash_readStatus()
{
   BYTE status;
   output_low(FLASH_SELECT);                 // Enable select line
   ext_flash_sendData(0xD7, 8);              // Send status command
   status = ext_flash_getByte();             // Get the status
   output_high(FLASH_SELECT);                // Disable select line

   return status;                            // Return the status
}


// Purpose:       Write data to a buffer
// Inputs:        1) A buffer number (0 or 1)
//                2) An index into the buffer
//                3) A pointer to the data to write
//                4) The number of bytes of data to write
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady(), ext_flash_sendBytes()
void ext_flash_writeToBuffer(int1 bufferNumber, int16 bufferAddress, BYTE* data, int16 size)
{
   BYTE opcode;

   output_low(FLASH_SELECT);                 // Enable select line

   if(bufferNumber)
      opcode = 0x87;                         // Opcode for second buffer
   else
      opcode = 0x84;                         // Opcode for first buffer

   ext_flash_sendData(opcode, 8);            // Send opcode
   ext_flash_sendData(0, 15);                // Send 15 don't care bits
   ext_flash_sendData(bufferAddress, 9);     // Send buffer address
   ext_flash_sendBytes(data, size);          // Write data to the buffer
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Write the data in a buffer to a page
// Inputs:        1) A page address
//                2) A buffer number (0 or 1)
//                3) The writing mode to use
//                   - Use ERASE to first erase a page then write
//                   - Use NO_ERASE to write to a previously erased page
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady()
void ext_flash_BufferToPage(int1 bufferNumber, int16 pageAddress, int1 mode)
{
   BYTE opcode;
   ext_flash_waitUntilReady();               // Wait until ready
   output_low(FLASH_SELECT);                 // Enable select line
   if(mode)
   {
      if(bufferNumber)
         opcode = 0x86;                      // Opcode for second buffer
      else
         opcode = 0x83;                      // Opcode for first buffer
   }
   else
   {
      if(bufferNumber)
         opcode = 0x89;                      // Opcode for second buffer
      else
         opcode = 0x88;                      // Opcode for first buffer
   }
   ext_flash_sendData(opcode, 8);            // Send opcode
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(0, 9);                 // Send 9 don't care bits
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Erase a page
// Inputs:        A page address
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady()
void ext_flash_erasePage(int16 pageAddress)
{
   ext_flash_waitUntilReady();
   output_low(FLASH_SELECT);                 // Enable select line
   ext_flash_sendData(0x81, 8);              // Send opcode
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(0, 9);                 // Send 9 don't care bits
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Erase a block of 8 pages
// Inputs:        A block address
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady()
void ext_flash_eraseBlock(int8 blockAddress)
{
   ext_flash_waitUntilReady();
   output_low(FLASH_SELECT);                 // Enable select line
   ext_flash_sendData(0x50, 8);              // Send opcode
   ext_flash_sendData(blockAddress, 12);     // Send block address
   ext_flash_sendData(0, 12);                // Send 12 don't care bits
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Write data to a page through a buffer
// Inputs:        1) The address of the page to write to
//                2) The number of the buffer to use (0 or 1)
//                3) The index into the buffer to start writing at
//                4) A pointer to the data to write
//                5) The number of bytes of data to write
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady(), ext_flash_sendBytes()
void ext_flash_writePageThroughBuffer(int16 pageAddress,
                                      int1 bufferNumber, int16 bufferAddress,
                                      BYTE* data, int16 size)
{
   BYTE opcode;
   ext_flash_waitUntilReady();
   output_low(FLASH_SELECT);                 // Enable select line

   if(bufferNumber)
      opcode = 0x85;                         // Opcode for second buffer
   else
      opcode = 0x82;                         // Opcode for first buffer

   ext_flash_sendData(opcode, 8);            // Send opcode
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(bufferAddress, 9);     // Send buffer address
   ext_flash_sendBytes(data, size);          // Write data to the buffer
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Get the data from a page and put it in a buffer
// Inputs:        1) A page address
//                2) A buffer number (0 or 1)
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady()
void ext_flash_PageToBuffer(int16 pageAddress, int1 bufferNumber)
{
   BYTE opcode;
   ext_flash_waitUntilReady();
   output_low(FLASH_SELECT);                 // Enable select line

   if(bufferNumber)
      opcode = 0x55;                         // Opcode for second buffer
   else
      opcode = 0x53;                         // Opcode for first buffer

   ext_flash_sendData(opcode, 8);            // Send opcode
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(0, 9);                 // Send 9 don't care bits
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Compare the data in a page to the data in a buffer
// Inputs:        1) A page address
//                2) A buffer number (0 or 1)
// Outputs:       1 if the data is the same, 0 if the data is not the same
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady()
int1 ext_flash_comparePageToBuffer(int16 pageAddress, int1 bufferNumber)
{
   int1 CompareFlag;
   BYTE opcode;
   ext_flash_waitUntilReady();
   output_low(FLASH_SELECT);                 // Enable select line

   if(bufferNumber)
      opcode = 0x61;                         // Opcode for second buffer
   else
      opcode = 0x60;                         // Opcode for first buffer

   ext_flash_sendData(opcode, 8);            // Send opcode
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(0, 9);                 // Send 9 don't care bits
   output_high(FLASH_SELECT);                // Disable select line

   output_low(FLASH_SELECT);                 // Enable select line
   ext_flash_sendData(0xD7, 8);              // Send status command
   while(!input(FLASH_DO));                  // Wait until ready
   output_high(FLASH_CLOCK);                 // Pulse the clock
   output_low(FLASH_CLOCK);
   CompareFlag = !input(FLASH_DO);           // Get the compare flag
   output_high(FLASH_SELECT);                // Disable select line

   return CompareFlag;
}


// Purpose:       Rewrite the data in a page.
//                The flash device does this by transfering the data to a
//                buffer, then writing the data back to the page.
// Inputs:        1) A page address
//                2) A buffer number (0 or 1)
// Outputs:       None
// Dependencies:  ext_flash_sendData(), ext_flash_waitUntilReady()
void ext_flash_rewritePage(int16 pageAddress, int1 bufferNumber)
{
   BYTE opcode;
   ext_flash_waitUntilReady();
   output_low(FLASH_SELECT);                 // Enable select line

   if(bufferNumber == 1)
      opcode = 0x58;
   else
      opcode = 0x59;

   ext_flash_sendData(opcode, 8);            // Send opcode
   ext_flash_sendData(pageAddress, 15);      // Send page address
   ext_flash_sendData(0, 9);                 // Send 9 don't care bits
   output_high(FLASH_SELECT);                // Disable select line
}


// Purpose:       Send some data to the flash device
// Inputs:        1) Up to 16 bits of data
//                2) The number of bits to send
// Outputs:       None
// Dependencies:  None
void ext_flash_sendData(int16 data, int8 size)
{
   int8 i;
   data <<= (16-size);
   for(i=0; i<size; ++i)
   {
      output_bit(FLASH_DI, shift_left(&data,2,0));    // Send a data bit
      output_high(FLASH_CLOCK);                       // Pulse the clock
      output_low(FLASH_CLOCK);
   }
}


// Purpose:       Send some bytes of data to the flash device
// Inputs:        1) A pointer to an array of data to send
//                2) The number of bytes to send
// Outputs:       None
// Dependencies:  None
void ext_flash_sendBytes(BYTE* data, int16 size)
{
   int16 i;
   signed int8  j;
   for(i=0; i<size; ++i)
   {
      for(j=7; j>=0; --j)
      {
         output_bit(FLASH_DI, bit_test(data[i], j));  // Send a data bit
         output_high(FLASH_CLOCK);                    // Pulse the clock
         output_low(FLASH_CLOCK);
      }
   }
}

// Purpose:       Wait until the flash device is ready to accept commands
// Inputs:        None
// Outputs:       None
// Dependencies:  ext_flash_sendData()
void ext_flash_waitUntilReady()
{
   output_low(FLASH_SELECT);                 // Enable select line
   ext_flash_sendData(0xD7, 8);              // Send status command
   while(!input(FLASH_DO));                  // Wait until ready
   output_high(FLASH_SELECT);                // Disable select line
}



//NEW:
// Purpose:       Increments the write pointer inc spaces.  If the write pointer
//                crosses a page boundry, increment to next page and reset index.
// Inputs:        1) The number of places to increment the write pointer.
// Outputs:       None
// Dependencies:  None
static void ext_flash_incrementWrite(int16 inc)
{
   g_ExtFlashCurrIndex += inc;
   
   if (g_ExtFlashCurrIndex >= FLASH_BUFFER_SIZE)
   {
      //recommended auto page rewrite when crossing a page boundry
      ext_flash_rewritePage(g_ExtFlashCurrPage, EXT_FLASH_WRITE_BUFFER);
      g_ExtFlashCurrIndex = 0;
      g_ExtFlashCurrPage++;
   }
}

//NEW:
// Purpose:       Given the current write pointer position, how many bytes can
//                we write before we cross a page boundry?
// Inputs:        None
// Outputs:       The number of bytes we can write before we cross a page.
// Dependencies:  NONE
static int16 ext_flash_incrementWritesLeft(void)
{
   return(FLASH_BUFFER_SIZE - g_ExtFlashCurrIndex);
}

//NEW:
// Purpose:       Loads the write pointer and the flash's buffer with the page
//                at the specified absolute address.
// Inputs:        1.) The absolute address to start writing.
// Outputs:       None
// Dependencies:  ext_flash_findPage()
void ext_flash_startWrite(int32 address)
{
   ext_flash_findPage(address, &g_ExtFlashCurrPage, &g_ExtFlashCurrIndex);

}

//NEW:
// Purpose:       Write bytes into the flash buffer.  If we cross a boundry,
//                flush the buffer and load the buffer with the next page.
// Inputs:        1.) Pointer in ram that contains bytes to write
//                2.) Number of bytes to write.
// Outputs:       None                                                         
// Dependencies:  ext_flash_incrementWritesLeft(), ext_flash_writeToBuffer(),
//                ext_flash_incrementWrite()
void ext_flash_putBytes(char *ptr, int16 n)                                                           
{
   int16 left;

   while(n)
   {
      left = ext_flash_incrementWritesLeft();

      left = left > n ? n : left;
      ext_flash_PageToBuffer(g_ExtFlashCurrPage, EXT_FLASH_WRITE_BUFFER);
      ext_flash_writePageThroughBuffer(g_ExtFlashCurrPage,
                                       EXT_FLASH_WRITE_BUFFER, g_ExtFlashCurrIndex,
                                       ptr, left);
      ptr+=left;
      n -= left;
           
      ext_flash_incrementWrite(left);                                     
   }
}

//NEW:
// Purpose:       Write a byte to the flash's buffer.  See ext_flash_putBytes()     
// Inputs:        1) Byte to write
// Outputs:       None
// Dependencies:  ext_flash_putBytes()
////  NOTE: This is in-effecient, use ext_flash_putBytes as much as
///         you can.
void ext_flash_putByte(char c)
{
   ext_flash_putBytes(&c, 1);   
}


//NEW:
// Purpose:       Writes data to the flash's NV memory.  Performs a complete
//                start/stop cycle.
// Inputs:        1.) Address in flash to write
//                2.) Location of data in PIC ram to save to flash
//                3.) Number of bytes to write
// Outputs:       None
// Dependencies:  ext_flash_startWrite(), ext_flash_putBytes(),
void ext_flash_writeBytes(int32 address, char *ptr, int16 n)
{
   ext_flash_startWrite(address);
   ext_flash_putBytes(ptr, n);
}




//functions for general purpose use.  The functions that r/w 1 byte are quite inefficient
//when possible, use the array/pointer functions.
void write_ext_eeprom(EEPROM_ADDRESS address, char c){
   ext_flash_writeBytes(address, &c, 1);
}

//#define write_ext_eeprom(a,b,c) ext_flash_writeBytes(a,b,c)
void write_ext_eeprom(EEPROM_ADDRESS address, char *ptr, int16 n){
   ext_flash_writeBytes(address, ptr, n);
}

char read_ext_eeprom(EEPROM_ADDRESS address){
   char retval;
   ext_flash_readBytes(address, &retval, 1);
   return retval;
}

//#define read_ext_eeprom(a,b,c) ext_flash_readBytes(a,b,c);
void read_ext_eeprom(EEPROM_ADDRESS address, char *ptr, int16 n){
   ext_flash_readBytes(address, ptr, n);
}

int1 ext_eeprom_ready(void){
   ext_flash_waitUntilReady();
   return TRUE;
}
#endif

_________________
The Definition of an Upgrade: Take old bugs out, put new ones in.
jacquesdejager



Joined: 23 Apr 2011
Posts: 11
Location: South Africa

View user's profile Send private message

PostPosted: Wed Nov 21, 2012 8:30 am     Reply with quote

No one have problems with this, or alternative driver ?

I'm using a Olimex board, if it was my own board I wouldn't have installed such an eeprom for my application.
_________________
The Definition of an Upgrade: Take old bugs out, put new ones in.
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Wed Nov 21, 2012 10:08 am     Reply with quote

Start with a simple correction to what you _say_. This is _not_ a "CCS provided at45db041.c driver". It is something you have found probably based on some posts here in the forum, modified from the 45db021 driver.

You don't tell us what compiler version you are using, or what PIC. Affects things a lot. You don't show us the code you are using to test this.

Seriously though, if you look at the code, some parts are going to be dreadfully slow. Basically the routines to send/receive bytes and words, using bit test is about the slowest way to do this. Better ways are:
1) Simply rotate the byte/word and test a fixed bit. About a dozen times faster.
2) Use the CCS supplied SPI library.
3) Use hardware SPI.
Why they don't do this is probably down to wanting to make the code easy to understand, rather than in any way 'well written'...

Now there is nothing obvious that would give bit problems (and especially not in only the low nibble). However using bit test the way they do, outputs will be faster as you move down the byte/word, which might have something to do with this. If so it possibly suggests a level problem with the voltages between your PIC and the ROM, and signals being very slow to actually cross a detection threshold. Back to what PIC.

Best Wishes
jacquesdejager



Joined: 23 Apr 2011
Posts: 11
Location: South Africa

View user's profile Send private message

PostPosted: Wed Nov 21, 2012 12:25 pm     Reply with quote

Hello Ttelmah -

I modified the at45db041 driver from CCS --

#define FLASH_BUFFER_SIZE 264 //bytes per page
#define FLASH_BUFFER_COUNT 4096 //page count

to this for the AT45DBD011 instead of AT45DB041

#ifndef FLASH_BUFFER_SIZE
#define FLASH_BUFFER_SIZE 264 // bytes per page
#define FLASH_BUFFER_COUNT 512 // page count
#endif

I agree, using the hardware SPI is much better, but first wanted to make the code work and then optimize for performance.

Like you indicated it is maybe best the just start the driver from scratch.

The code u used to test as follow --

Code:


struct _dataset
{
   int8  val_int;
   long  val_long;
};

struct _dataset set1, set2;

char buff [sizeof(set1)];

char buffrcv [sizeof(set2)];

   set1.val_int   =  2;
   set1.val_long  =  65520;

   memcpy(buff,&set1,sizeof(buff));

   ext_flash_erasePage(0);

   ext_flash_writeBytes(0x00000000, buff, sizeof(buff));
   
   ext_flash_readBytes(0x00000000, buffrcv, sizeof(buffrcv));
   
//   memcpy(buffrcv,buff,sizeof(buffrcv));
   
   memcpy(&set2, buffrcv, sizeof(set2));

/* Function Start */     
   for( ; ;)
   {
    //  menu();
     
      printf("set2.val_int:%u\r\n",set2.val_int);
      printf("set2.val_long:%Lu\r\n",set2.val_long);
     
      printf("\r\n");

      delay_ms(1000);
   
}//for

_________________
The Definition of an Upgrade: Take old bugs out, put new ones in.
jacquesdejager



Joined: 23 Apr 2011
Posts: 11
Location: South Africa

View user's profile Send private message

PostPosted: Wed Nov 21, 2012 12:28 pm     Reply with quote

I'm using the Olimex Maxi Web board based on PIC18F97J60.

The EEPROM does work with the Microchip Stack - loaded when you buy the board, pictures and html pages stored in the EEPROM.

I think from a hardware perspective all is ok ?
_________________
The Definition of an Upgrade: Take old bugs out, put new ones in.
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Wed Nov 21, 2012 3:47 pm     Reply with quote

You don't have to rewrite the whole driver to use hardware SPI. Only the actual routines that send data to/fro. Under 20 lines of code in all.
Again though you talk about modifying "the at45db041 driver from CCS". There is no at45db041 driver from CCS.....

Best Wishes
jacquesdejager



Joined: 23 Apr 2011
Posts: 11
Location: South Africa

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 1:09 am     Reply with quote

The AT45DB041 driver from CCS is included in the CCS TCP/IP stack.

This is the code I published online, from the TCP/IP stack add-on.
_________________
The Definition of an Upgrade: Take old bugs out, put new ones in.
jacquesdejager



Joined: 23 Apr 2011
Posts: 11
Location: South Africa

View user's profile Send private message

PostPosted: Fri Nov 23, 2012 3:55 pm     Reply with quote

Hello --

I finally found the problem, the flash chip used in the board im using is of a very old revision, the opcode's used in the driver is in some cases not recognized by the revision of the chip -- at45db011A compared to D revision opcodes used.

Thnx
_________________
The Definition of an Upgrade: Take old bugs out, put new ones in.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 4:49 pm     Reply with quote

Bad move from Atmel; a letter in the device ID normally suggests a minor change. Breaking backwards compatibility doesn't make them new friends among developers.
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