Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Need help with 24bit addressing SPI EEPROM (25AA1024)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Need help with 24bit addressing SPI EEPROM (25AA1024)

by mngrif on Mon Jun 23, 2008 4:02 pm

I have an EEPROM (from Microchip, several of them) that takes a 24bit address. As best I can figure out there is no variable type that is made for 24 bits, the best match is 32. So I need a way to send only the bottom 24 bits of the 32 bit int. Or another way all around...

This is on the ATmega168. The EEPROM in question is the 25AA1024. It takes data MSB first.

Any help would be most appreciated since google is failing me on this one!
Last edited by mngrif on Tue Jun 24, 2008 3:28 am, edited 1 time in total.
mngrif
 
Posts: 47
Joined: Sat Jun 07, 2008 6:36 am

by adafruit on Mon Jun 23, 2008 11:29 pm

sounds fine to me
or 3 8 bit variables :)

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

by mngrif on Tue Jun 24, 2008 3:28 am

The problem with sending a 32bit int is that there is 8 extraneous bits being sent that are fouling things up (all writes go to sector 0 (until it gets in to high sectors) since the rest is considered a part of the actual data to be written).

3x8bit packets is an option that I'll explore though (might foul up timing???), but that's as ugly as perl. *MUCH* thanks for the idea though! It's what I'll use for now. Really, thanks!

I'm really looking for a custom 24bit int data type if someone has it laying around or can point me in the right direction. The search terms are just too broad for teh searchez to be of use :\
mngrif
 
Posts: 47
Joined: Sat Jun 07, 2008 6:36 am

by mtbf0 on Tue Jun 24, 2008 8:22 am

what you need is some casting, some shifting and some masking. all of these are covered with distressing lack of detail in the arduino reference or in any c or c++ book. i'm still recommending kernighan and ritchie.

Code: Select all | TOGGLE FULL SIZE
 uint32_t memaddr;
unit8_t msb = (uint8_t)(memaddr >> 16);        // most significant bits
uint8_t osb = (uint8_t)((memaddr >> 8) & 0xff);// some other significant bits
uint8_t lsb = (uint8_t)(memaddr & 0xff);       // least significant bits
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: Need help with 24bit addressing SPI EEPROM (25AA1024)

by ioniser on Sun Oct 16, 2011 7:58 pm

did you end up geting this to work? I am also having trouble using a 328p arduino with the 25AA1024
cant seem to get the coms working at all. tried a couple librarys, also wrote my own and still no luck.
ioniser
 
Posts: 1
Joined: Sun Oct 16, 2011 7:54 pm

Re:

by cstratton on Sun Oct 16, 2011 11:18 pm

mngrif wrote:The problem with sending a 32bit int is that there is 8 extraneous bits being sent that are fouling things up (all writes go to sector 0 (until it gets in to high sectors) since the rest is considered a part of the actual data to be written).


The address is usually preceded by a command byte - can you just make that bits 31-24 of your value? So for example, on the chip I'm playing with at the moment, using my debug tool, if I type

03 00 00 00 it starts reading from address 0
03 01 00 00 it starts reading the second 64KB
03 02 00 00 etc

Where "03" is the read command on my particular part.

But in my firmware, I'm dealing with the SPI one byte at a time, so I don't really have your problem. If I were dealing with it in 16 bit words, I could still solve it this way be combining the command and the high byte of the address into the high word, and then the lower two bytes in the low word.

That said, my chip does at times insist on getting only 8 clocks - try to give it a write enable command with a dummy byte following, and it won't accept it.

cstratton
 
Posts: 294
Joined: Wed Sep 29, 2010 3:52 pm

Re: Need help with 24bit addressing SPI EEPROM (25AA1024)

by ToBeFrank on Tue Oct 18, 2011 4:11 pm

This is how I do it when I want to handle a standard type in a byte oriented way:

Code: Select all | TOGGLE FULL SIZE
typedef union
{
  uint32_t value;
  uint8_t bytes[sizeof(uint32_t)];
} some_type_t;


You'd then access the 32 bit like this:

Code: Select all | TOGGLE FULL SIZE
some_type_t var;
var.value = 0x12345678;
uint32_t val32 = var.value;


And you'd access the individual bytes like this:

Code: Select all | TOGGLE FULL SIZE
uint8_t byte0 = var.bytes[0];
uint8_t byte1 = var.bytes[1];
uint8_t byte2 = var.bytes[2];
uint8_t byte3 = var.bytes[3];
ToBeFrank
 
Posts: 3
Joined: Tue Oct 18, 2011 4:03 pm

Please be positive and constructive with your questions and comments.