PDA

View Full Version : Another attempt for I2C eeprom, this time - 25C256.



CuriousOne
- 14th January 2022, 19:00
Hello.
I decided to give it another try, now with this module.

https://www.elecrow.com/i2c-eeprom-module-at24c256-p-736.html

Pull up resistors installed, and following code configured.
when properly working, it should produce chirp up, chirp down sound. But it does not
of course, chirp up - write, works fine, because here it chirps directly, but in read routine
I'm getting zeros.

Only what I've found out, that if I set read address to 160 (A0) it returns 255, for any other address, it returns 0.
So somehow, chip responds, right? but not completely.
What I'm missing?





x var byte
y var byte
z var byte
sda var portb.1
scl var portb.0


ehmo:
for X=0 to 12
I2CWrite sda, scl, 160, x, [x]
hpwm 1,127,1000+x*10
pause 1
next
hpwm 1,0,1000 'mute
pause 500


for x=12 to 0 step -1
i2cread sda, scl, 160,x,[y]
hpwm 1,127,1000+Y*10
pause 1
next
hpwm 1,0,1000
pause 500
goto ehmo

aerostar
- 14th January 2022, 20:29
For read try 161 address

CuriousOne
- 14th January 2022, 20:40
No difference - already tried all combos like 159+160, 160+161 and so on....

HenrikOlsson
- 14th January 2022, 21:07
The 25C265 as mentioned in the title is a SPI EEPROM. That won't ever work with the I2C command.
If, on the other hand, it's the 24C256 then the state of the A0-A2 pins will have an effect on the address. Anyway, looking at the 24C256 datasheet:

In Byte Write mode the Master sends a START, followed
by Slave address, two byte address and data to be written
(Figure 6).

And then your code:

I2CWrite sda, scl, 160, x, [x]

You're using the x-variable as the address (and data) but have it defined as a byte.

With that said, I have not ever used I2C so I'm certainly no expert.

CuriousOne
- 14th January 2022, 21:09
Yes I made an error in tittle, chip is certainly 24C256.

richard
- 14th January 2022, 22:19
you need to do it properly

9152

mpgmike
- 14th January 2022, 22:47
C1, if you have the spare cash, I would recommend a cheap logic analyzer. Saelig sells one for (I think I paid) around $80 US. I haven't used mine in several years, as I now have a Pico Scope that does much more, and better. I am in the northeast US. If you're willing to cover shipping, you can have my old Saelig. It will help you to verify communication protocols and baud rates for situations like this. If interested, PM me & we can take it from there. You might be able to find one on eBay, Amazon, or Craigslist (or whatever local online sellers site you have) for next to nothing, and with cheaper or even no shipping.

CuriousOne
- 15th January 2022, 05:53
So what's wrong with 160? it is chip address, A0, and isn't that fixed?

Regarding the logic analyzer. I have that saelae thing.
I can't get it work as I understand it should work - run continuously, monitor bytes, like scope does. it only has "run", it runs, fills up buffer in couple of seconds and stops - that's all. For that purposes, I bought a scope with built-in logic analyzer, which can run infinitely - Hantek DSO2D10 - but was able it to work only very low speeds, for protocol decoding.

richard
- 15th January 2022, 06:53
it a constant , pbp constants are 16 bits , i2c address are 8 bit
use your logic analyzer

CuriousOne
- 15th January 2022, 07:23
So what should I write instead of 160?

I've searched this forum, and people do use plain numbers in I2C eeprom write/read?

richard
- 15th January 2022, 07:28
Address var byte
Address = 160

HenrikOlsson
- 15th January 2022, 08:44
Yeah, you really should spend some time getting that logic analyzer working and understand what it does. It's NOT an oscilloscope and although newer versions of the software does allow it to continously stream and display that's not really its intended purpose.

Anyway, here's what I'd try (and I'd have the logic analyzer hooked up)

Chip_Address VAR BYTE
Mem_Address VAR WORD
sda VAR portb.1
scl VAR portb.0

Chip_Address = 160

' The chip address must be a BYTE, this is the 160 + whatever A0-A2 is set to.
' The memory address must be a WORD for the 24C256, this is the address of the byte to written (or read)
' The data to be written is, in this case, a BYTE but it does not have to be, you can write words or arrays - which are obviously just multiple bytes...

FOR Mem_Address = 0 to 12
' I/O I/O BYTE WORD BYTE
I2CWrite sda, scl, Chip_Address, Mem_Address, [Mem_Address.LOWBYTE]
NEXT

And I'd like to thank Richard for the primers on PBP I2C the last couple of days, much appreciated!

CuriousOne
- 15th January 2022, 16:33
WOW! Finally it works!



x var word
y var byte
adr var byte
sda var portc.0
scl var portc.1
lcdout $fe, $01, " "
adr=160


for X=0 to 5
I2CWrite sda, scl, adr, x, [x.lowbyte]
lcdout $fe, $14, dec x


pause 100
next
pause 500
lcdout $fe, $1, "Complete:"
lcdout $fe, $c0, " "
pause 500


for x=0 to 5
i2cread sda, scl, adr, x, [y]
lcdout $fe, $14, dec y
pause 100
next
stop


That's very good, this means now I can do a lot of LCD things!

Thanks everyone!

by the way, I tried to write 160 directly, instead of adr - also works.

CuriousOne
- 15th January 2022, 19:03
Now I need bitwise hex editor - one that allows editing hex file by bits, not by bytes. Any ideas :)

HenrikOlsson
- 16th January 2022, 08:02
Not directly and the following isn't a hex editor but if it's intended purpose is to create "content" for LCDs then https://www.mikroe.com/glcd-font-creator might be what you're looking for.
Here's another one https://www.buydisplay.com/lcd-font-maker and another https://kapusta.cc/2020/03/20/fontedit/

I've not used any of them, I know Richard is using the one from MikroE.

CuriousOne
- 16th January 2022, 08:29
Yes I know all these :)
The issue with Mikroe "creation" is it, as everything else done by them, is written with left feet- need admin priviledges to run it, and it outputs fonts rotated by 90 degrees :D
But currently I don't need font editor or graphics editor, I already have all that done, just need some hex editor to put everything into single file and adjust bits as necessary.

Oh and another issue, which deserves separate topic is how to emulate LCDOUT statement, because it can't send $FE to display :)

CuriousOne
- 16th January 2022, 08:38
Not exact match, but HxD hex editor does the job almost in the way I see it.

richard
- 16th January 2022, 09:34
The issue with Mikroe "creation" is it, as everything else done by them, is written with left feet- need admin priviledges to run it, and

make an icon and assign admin to it , not a problem. running in compatibility mode can help if it wont save stuff w10 is ok without it


it outputs fonts rotated by 90 degrees

glcd mode is data by column, tft mode is data by row , there is no problem
you need to massage the data a little for pbp but its no big deal

CuriousOne
- 16th January 2022, 13:48
I don't see any mode selector in GLCD font creator from their website.

richard
- 16th January 2022, 21:13
don't think you looked too hard

9172

CuriousOne
- 18th January 2022, 17:49
Thanks a lot !
At my system, that menu bar was not visible at all
and in file/edit menu, they have no such setting...