Searching \ for '[PIC]: Routine for AT45D161 Flash using PIC' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/memory.htm?key=flash
Search entire site for: 'Routine for AT45D161 Flash using PIC'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Routine for AT45D161 Flash using PIC'
2001\01\29@202128 by David Huisman

flavicon
face
Does anyone here have experience with the AT45xx Flash Memory device ?
The following code is what I have written to write and read to memory using
an absolute address. It does not function. The spi_write routines work on
other devices.

//   *** AT45D161 Memory Routines ***
// format is cccccccc   rrpppppp      ppppppaa     aaaaaaaa
// cccccccc = command,rr = reserved,pppppppppppp = page address,aaaaaaaaaa =
byte location on page
// page size is 528 bytes

void AT45D161_Write(long abs_address,char Flash_Data)
{
  unsigned int page;
  unsigned int location;

  page     = ((unsigned int) (abs_address  / 528)) << 2;    //  page
address into 2 bytyes and shift left 2
  location = (unsigned int) abs_address % 528;              //  byte
address and store in integer

  AT45D161_EN = false;                                      // select
AT45D161 using CE
  Bit_Delay;                                                //  allow >
280ns settling time for CE

  cDummy = spi_io(ABS_WRITE_CMD);                         // issue write
cmd (0x82)
  cDummy = spi_io(hi_byte(page));                           // 6 MSB of
page
  cDummy = spi_io(lo_byte(page)|hi_byte(location));        // 6 LSB of page
and 2 MSB of byte location
  cDummy = spi_io(lo_byte(location));                       //  8 LSB of
byte location

  cDummy = spi_io(Flash_Data);                              //  write data

  AT45D161_EN = true;                                       // de-select
AT45D161
}

// format for read is cccccccc rrpppppp  ppppppaa aaaaaaaa xxxxxxxx xxxxxxxx
xxxxxxxx xxxxxxxx dddddddd
// cccccccc = command,rr = reserved,pppppppppppp = page address,aaaaaaaaaa =
address
// xxxxxxx ...  = Don't care,dddddddd = read data

char AT45D161_Read(long abs_address)
{
  unsigned int page;
  unsigned int location;

  page     = (unsigned int) (abs_address  / 528)<<2;      //  store page
address into 2 bytyes and shift left 2
  location = (unsigned int) abs_address % 528;             // calculate
byte address and store in integer

  AT45D161_EN = false;                                     // select
AT45D161 using CE
  Bit_Delay;                                               //  allow >
280ns settling time for CE

  cDummy = spi_io(READ_CMD);                               // issue write
cmd (0x52)
  cDummy = spi_io(hi_byte(page));                          // send 6 MSB of
page
  cDummy = spi_io(lo_byte(page)|hi_byte(location));        // 6 LSB of page
and 2 MSB of byte location
  cDummy = spi_io(lo_byte(location));                      // 8 LSB of byte
location
  cDummy = spi_io(NULL);                                   // 0x00 - ie.
Don't care byte
  cDummy = spi_io(NULL);                                   // 0x00 - ie.
Don't care byte
  cDummy = spi_io(NULL);                                   // 0x00 - ie.
Don't care byte
  cDummy = spi_io(NULL);                                   // 0x00 - ie.
Don't care byte
  cDummy = spi_io(NULL);                                  // read data

  AT45D161_EN = true;                                      // de-select
AT45D161

  return (cDummy);                                         // pass read
data back to main program
}

regards

David Huisman

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...