Go Down

Topic: external eprom issue (Read 117 times) previous topic - next topic

nilonha

Having some issues to communicate with eeprom 24C01 or 24C16 (tried both) chips.
Testing write value "0" to address "0". just a very simple thing, but I keep getting value 255, which is the initiated value for variable "rdata". Basically, code is node reading from mem, I suppose.
What am I doing wrong?
Thanks for any help.
on audio nano:
Mem pin 4 - GND
Mem pin 8 - VCC (5v from audio)
Mem pins 2,3,4 - GND
Mem pin 5 - arduino A4, with pullup 6.8K to VCC
Mem pin 6 - arduino A5, with pullup 6.8K to VCC
Mem pin 7 - GND

Code:
Code: [Select]
#include <Wire.h>   
 
#define disk1 0x50    //Address of 24LC16 eeprom chip
 
void setup(void)
{
  Serial.begin(9600);
  Wire.begin(); 

 
  unsigned int address = 0;
 
writeEEPROM(disk1, address, 0);

Serial.println(readEEPROM(disk1, address), DEC);


}

void loop(){}
 
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
 
  delay(10);
}
 
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;
 
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
 
  Wire.requestFrom(deviceaddress,1);
 
  if (Wire.available()) rdata = Wire.read();
 
  return rdata;
}


from I2C scanner, confirmed mom address (0x50).
"Scanning...
I2C device found at address 0x50  !
I2C device found at address 0x51  !
I2C device found at address 0x52  !
I2C device found at address 0x53  !
I2C device found at address 0x54  !
I2C device found at address 0x55  !
I2C device found at address 0x56  !
I2C device found at address 0x57  !
done"

DrAzzy

#1
Aug 24, 2019, 12:06 am Last Edit: Aug 24, 2019, 12:09 am by DrAzzy
You're using code that would work for a 32~512kbit part with a 1kbit or 16kbit part, that's what you're doing wrong.

Read the datasheet again.

The three high bits of the address of the 24c16 are sent as the low three bytes of the device address (hence why you see 8 devices with one part connected). Note also that the A0~A2 pins don't do anything, because the bits of the device address they'd normally control are used as part of the address.

So, after the device address, you send the remaining 8 bits of the address.

However, your code is sending two bytes of address...

In the case of write, this writes the low byte of the address to the address given by the three high bits of the intended address.

In the case of read, this... does the same thing. Then you try to read from it. I don't recall whether this results in returning nothing, or returns the value of the next byte in memory after the one you last wrote to; either way (assuming, for the second case, that you hadn't previously written to the next byte) you'd end up printing... 255!

In the case of 24c01, you're doing the same thing, except that the address written to is always 0 (assuming you give it a valid address).
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

nilonha

#2
Aug 24, 2019, 02:31 am Last Edit: Aug 24, 2019, 03:49 am by nilonha
OK, I got most of what you said. I changed the code, sending device address as 0x50 and only sending one byte of data address (0x00, in my test). The write/read worked this time.
As you said, the three bits before the LSB on the device address is used as part (three MSB) for the data address. So data address will be then 11 bits. That results in max 2048 positions or 2K memory, yes? How will it address 16634 positions or 16K, for the C24C16 (15 address bits needed, no?).

Thanks

cattledog

Quote
That results in max 2048 positions or 2K memory, yes? How will it address 16634 positions or 16K, for the C24C16
The eeprom specs need closer reading. They are 16K bits.

The 2K bytes is correct. The device presents as 8 separate devices of 256 byes each.

Go Up