eeprom M24M02

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
nicoco
Posts: 34
Joined: 04 Oct 2008 09:20

eeprom M24M02

#1 Post by nicoco » 08 Jun 2023 17:43

Hi, i have a project that use AT24c512, all worked fine with the code below :

Code: Select all

sub procedure AT24_write(dim adress as word, dim dta as byte)

I2C1_Start()
I2C1_Wr(0xA0)
I2C1_Wr(hi(adress))
I2C1_Wr(lo(adress))
I2C1_Wr(dta)
I2C1_Stop()

end sub


sub function  AT24_read (dim adress as word)as byte

I2C1_Start()
I2C1_Wr(0xA0)
I2C1_Wr(hi(adress))
I2C1_Wr(lo(adress))
'I2C1_Stop()

I2C1_Start()
I2C1_Wr(0xA1)

result=I2C1_Rd(0)
while (I2C1_Is_Idle() = 0)
      nop                      ' Wait for the read cycle to finish
wend
'result=I2C1_Rd(0)
I2C1_Stop()

end sub
But using this code with M24M02, this not work, the eeprom don't respond. I check the datasheet, it is the same as at24CM02, do you have any idea ?

I have not already modified code to insert A17 and A16 MSB bits in adress byte, but this should work for adresses lower than 65k

robertolsen
Posts: 2
Joined: 22 Feb 2024 09:50

Re: eeprom M24M02

#2 Post by robertolsen » 22 Feb 2024 09:52

Hello,
I think you should set the three most significant bits (A17, A16, and A15) to the appropriate values. Here's an updated version of your code that includes these modifications:

Code: Select all

basic
sub procedure M24M02_write(dim address as word, dim data as byte)
    I2C1_Start()
    I2C1_Wr(0xA2)  ' Device address with A17, A16, and A15 set to 0
    I2C1_Wr(hi(address))
    I2C1_Wr(lo(address))
    I2C1_Wr(data)
    I2C1_Stop()
end sub

sub function M24M02_read(dim address as word) as byte
    I2C1_Start()
    I2C1_Wr(0xA2)  ' Device address with A17, A16, and A15 set to 0
    I2C1_Wr(hi(address))
    I2C1_Wr(lo(address))
    
    I2C1_Start()
    I2C1_Wr(0xA3)  ' Device address with A17, A16, and A15 set to 1
    
    result = I2C1_Rd(0)
    while (I2C1_Is_Idle() = 0)
        nop            ' Wait for the read cycle to finish
    wend
    
    I2C1_Stop()
end sub
In the modified code, the device address for writing (0xA2) and reading (0xA3) has the A17, A16, and A15 bits set accordingly. Make sure to update your code with these changes and test it with the M24M02 EEPROM.

Post Reply

Return to “mikroBasic PRO for PIC General”