I need to use the number 4 eeprom I2C external bus from 2Mbis each of the type AT25M02 (262.144 x which is very complex, or M24M02 which is very simple. In these devices the address MSB occupies two bits of the first selection byte (device selection) because it requires an amplitude of 18 bits (2 + 8 + .
I think the EEPROM.BAS library can handle these types of EEprom, maybe I'm wrong and I would be happy. But if what I think is true, how can I solve my problem?
I use the PIC18F46K80
EEPROM exceeding 512Kbits
Moderators: David Barker, Jerry Messina
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: EEPROM exceeding 512Kbits
The EEPROM.bas library is for the internal eeprom memory of the 46K80, so that won't work for either of those chips.
You mention "I need to use the number 4 eeprom I2C" and both the 25M02 (which is SPI, not I2C) and the M24M02.
Do you need to use more that one of the M24M02 devices?
You mention "I need to use the number 4 eeprom I2C" and both the 25M02 (which is SPI, not I2C) and the M24M02.
Do you need to use more that one of the M24M02 devices?
Re: EEPROM exceeding 512Kbits
I need to use four Eprom M24M02 or AT25M03 or equivalent.
For the AT25M03 eeprom (SPI bus) I have no problem managing the Chip Select from the hardware, but I do not understand if the Swordfish SPI module manages the 24bit addresses, I searched in the documentation but I can not find useful references in the SPI library .
How can I manage a random access on 24bit address?
For the M24M02 eeprom (I2C bus) I think it's simple:
I2C.Start
I2C.WriteByte (I2C_EEPROM) - contains the device identifier and the two most significant bits of the address.
I2C.WriteByte (Address.Byte1)
I2C.WriteByte (Address.Byte0)
I2C.WriteByte(....)
I2C.Stop
I think it's correct this way
But .... what is the simple solution to write many bytes or a string in the eeprom via I2C?
Thanks
For the AT25M03 eeprom (SPI bus) I have no problem managing the Chip Select from the hardware, but I do not understand if the Swordfish SPI module manages the 24bit addresses, I searched in the documentation but I can not find useful references in the SPI library .
How can I manage a random access on 24bit address?
For the M24M02 eeprom (I2C bus) I think it's simple:
I2C.Start
I2C.WriteByte (I2C_EEPROM) - contains the device identifier and the two most significant bits of the address.
I2C.WriteByte (Address.Byte1)
I2C.WriteByte (Address.Byte0)
I2C.WriteByte(....)
I2C.Stop
I think it's correct this way
But .... what is the simple solution to write many bytes or a string in the eeprom via I2C?
Thanks
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: EEPROM exceeding 512Kbits
I assume you mean AT25M02
There are some examples for the SPI devices in the folder library\spiDevices that use the spiEEPROM.bas module,
but it currently only supports a 16-bit word as the address, so you'd have to change it to something like:
The I2C part is more difficult since part of the address has to be combined with the first device select
code byte with the following bits:
b7 = 1
b6 = 0
b5 = 1
b4 = 0
b3 = chip enable E2 pin setting (0 or 1)
b2 = A17 addr bit
b1 = A16 addr bit
b0 = i2c R_W
You would need multiple I2C busses since you can only have two M24M02 devices on a single I2C connection... one with E2 = 0 and another with E2 = 1
There are some examples for the SPI devices in the folder library\spiDevices that use the spiEEPROM.bas module,
but it currently only supports a 16-bit word as the address, so you'd have to change it to something like:
Code: Select all
dim
FCS as TPin,
FAddress as longword // need > 16-bits
public dim
Address as FAddress
{
****************************************************************************
* Name : ReadByte *
* Purpose : Read a byte from SPI EEPROM *
****************************************************************************
}
public function ReadByte() as byte
CSOn // chip select on
SPI.WriteByte(cmdRead) // read command
SPI.WriteByte(FAddress.Byte2) // write address (upper 24-bit addr)
SPI.WriteByte(FAddress.Byte1) // write address (high byte)
SPI.WriteByte(FAddress.Byte0) // write address (low byte)
Result = SPI.ReadByte // read the data
CSOff // chip select off
inc(FAddress) // increment address
end function
code byte with the following bits:
b7 = 1
b6 = 0
b5 = 1
b4 = 0
b3 = chip enable E2 pin setting (0 or 1)
b2 = A17 addr bit
b1 = A16 addr bit
b0 = i2c R_W
Code: Select all
dim Address as longword
// create the device select
dim devsel as byte
Address = $012345 // just an example
devsel = I2C_EEPROM // %10100000
if (Address.bits(16) = 1) then
devsel.bits(1) = 1
endif
if (Address.bits(17) = 1) then
devsel.bits(2) = 1
endif
devsel.bits(3) = E2_PIN // depends on the pin connection
I2C.Start
I2C.WriteByte (devsel) // contains the device identifier and the two most significant bits of the address.
I2C.WriteByte (Address.Byte1)
I2C.WriteByte (Address.Byte0)
I2C.WriteByte(....)
I2C.Stop
Re: EEPROM exceeding 512Kbits
Thanks for the quick and positive answers to my questions,
I'm glad you gave me a solution with the readbyte module modified in SPI bus.
In the case of the M24M02, I think I use E2-pin chip enable as chip select. The E2 pin of the selected device is brought down when selected. Then the logical state of E2 in the device selection code will be low.
The same hardware configuration can be used in the case of the AT25M02 which has the chip select pin.
Well! on the hardwaere side I use the same chip selection logic, from the software I have both solutions ... perfect!
Thanks for the examples you showed.
I'm really happy, wow ...... thank you very much David,
Umberto.
I'm glad you gave me a solution with the readbyte module modified in SPI bus.
In the case of the M24M02, I think I use E2-pin chip enable as chip select. The E2 pin of the selected device is brought down when selected. Then the logical state of E2 in the device selection code will be low.
The same hardware configuration can be used in the case of the AT25M02 which has the chip select pin.
Well! on the hardwaere side I use the same chip selection logic, from the software I have both solutions ... perfect!
Thanks for the examples you showed.
I'm really happy, wow ...... thank you very much David,
Umberto.
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: EEPROM exceeding 512Kbits
It's probably too late to be of any help, but I just posted a library for I2C EEPROMS.
See viewtopic.php?f=5&t=2085
See viewtopic.php?f=5&t=2085