Discussion in "8051 Discussion Forum" started by    SGH    Mar 29, 2007.
Thu Mar 29 2007, 05:19 AM
#1
Hi all, I'm trying to write a code so I can store some data to AT24C01A.

What is the write and read address for AT24C01A ?. For example, DS1307 write = 0D0H and read = 0D1H.

1). I have read the datasheet, but could figure out what is the address.

2). To Rickey : I have downloaded your I2C routine from 8052.cm. Can I use this routine to write and read AT24C01A ?. What modifications to be made ?.

3). If I want to store (write) data to AT24C01A, how to define the address register in AT24C01A ?. I couldn't find it in the datasheet. For example, in DS1307, I saw code defining alarm equ 08H (08H = first register address in DS1307 RAM).

Thanks all.
SGH
Thu Mar 29 2007, 12:41 PM
#2
well.. i hope you've seen the datasheet carefully
http://www.selectronic.fr/includes_selectronic/pdf/ATMEL/24C16.pdf
on page 8 you can find the address for the EEPROM.
on page 7 you will information regarding how to write program.

yes you can use my I2C program, those are the basic things required for I2C communication. rest of the program you can write yourself as i mentioned see page 7 for more details about how to read, write and poll for acknowledgment. poll for ack coz its EEPROM so when you write something it will take time to store it, and you wont get ack unless its written. I hope you understood. please see page 7 carefully
and page 8,9 for reading and writing to particular address. as its 1K (AT24C01) EEPROM, so address will be from 0000 to 03FF so that can be anywhere u want.. see page 8,9 for sequential write and random write
enjoy programming!
Fri Mar 30 2007, 02:00 AM
#3
Hi Rickey,

Thanks for the info. I'll read the datasheet again.
Fri Mar 30 2007, 06:28 PM
#4
Yes If anymore problem you may ask anytime
Mon Apr 02 2007, 03:12 AM
#5
1). Referring to AT24C01A, I'm confused (as I'm newbie in microcontroller), is it 128 bytes or 1 K bytes ?. If 128 bytes, then last address is 7FH, and if 1024 bytes, then last address is 3FF ?.

2). Below is the quote you posted in other thread for DS1307.

You wrote :
i am writing some steps how to read from DS1307
Start
Send slave address with write bit
send the subaddress from where you want to read
start condition again [NOTE:dont send stop before this]
send slave address with read bit
start reading.
So the above steps are applied in the code as..

run1: acall startc
mov a,#0d0h
acall send
mov a,#00h
acall send
mov r6,#3fh
acall startc
mov a,#0d1h
acall send
mov r0,#40h
here: acall recv
djnz r6,here
acall stop

If I understand it correctly, 3FH = last address in DS1307 and we inserted 40H into R0 simply to tell the microcontroller it is the last data to be read ?.

In DS1307, normally only two data were stored inside, that is hour and minute (alarm) time. Even only two data were stored into the DS1307, the microcontroller will read the entire memory from 00H to 3FH and end the process if reach 40H ?.

Can this procedures (read the entire address) applied to AT24C01A ?. What about when writing to AT24C01A ?.

3). If I have 10 data to be stored into the AT24C01A, for example : Data_1,............, Data_10, do I need to make a descriptions like this : Data_1 equ 00H, Data_2 equ 1H,..........Data_10 equ 9H (to specify each data address in AT24C01A RAM) ?.

Sorry for the long post.

Thanks,
SGH
Mon Apr 02 2007, 09:43 AM
#6


1). Referring to AT24C01A, I'm confused (as I'm newbie in microcontroller), is it 128 bytes or 1 K bytes ?. If 128 bytes, then last address is 7FH, and if 1024 bytes, then last address is 3FF ?.

SGH


AT24C01 is 1Kbytes see in the datasheet the first page its mentioned there.


2). Below is the quote you posted in other thread for DS1307.

You wrote :
i am writing some steps how to read from DS1307
Start
Send slave address with write bit
send the subaddress from where you want to read
start condition again [NOTE:dont send stop before this]
send slave address with read bit
start reading.
So the above steps are applied in the code as..

run1: acall startc
mov a,#0d0h
acall send
mov a,#00h
acall send
mov r6,#3fh
acall startc
mov a,#0d1h
acall send
mov r0,#40h
here: acall recv
djnz r6,here
acall stop

If I understand it correctly, 3FH = last address in DS1307 and we inserted 40H into R0 simply to tell the microcontroller it is the last data to be read ?.

In DS1307, normally only two data were stored inside, that is hour and minute (alarm) time. Even only two data were stored into the DS1307, the microcontroller will read the entire memory from 00H to 3FH and end the process if reach 40H ?.

Can this procedures (read the entire address) applied to AT24C01A ?. What about when writing to AT24C01A ?.

SGH


you are not reading in a correct way, there is only 40 bytes of ram in the DS1307 so the subaddress will be only 1 byte e.g. you want to read from 3F location then
run1: acall startc ;this example is for DS1307
mov a,#0d0h
acall send
mov r6,#3fh
acall startc
mov a,#0d1h
acall send
acall recv
;after the above instruction the data will be in ACC
;so can be stored anywhere you want
mov r4,a ;i am storing in r4
acall stop

but in case of EEPROM, your subaddress is 2 bytes so, while sending subaddress you will first send high of subaddress and then lower byte of subaddress. This way you can read it.
and for sequential read, keep on recieving the data until you want to stop.
and as you said. that data space in DS1307 is only 40bytes, so when you reach 3F while reading, it will roll back to 00H and starts again. so its continuous process until you stop.


3). If I have 10 data to be stored into the AT24C01A, for example : Data_1,............, Data_10, do I need to make a descriptions like this : Data_1 equ 00H, Data_2 equ 1H,..........Data_10 equ 9H (to specify each data address in AT24C01A RAM) ?.

SGH


you can also define e.g.
DB 03H,04H,05H,00H
so this will store bytes on your desired location in 8051 ROM and when you want to write this data, then simply make a routine like...
send start
send slave add with write bit
send subadd
send data
send data ; if multiple data, you can also use a loop
send stop ; when all data is sent

loop e.g.
send start
send slave add with write bit
send subadd
load counter ; load how many bytes to send
load data from location is controller's ROM
dec counter and check for zero
if not zero go back else stop
send stop

so this way you can do sequential write. But one thing is important in case of AT24C01 or any other I2C EEPROM, that you have to wait until u get acknowledgment from EEPROM. I hope you have seen in datasheet of memory for ack polling. this is only done during writing..
but the above is not applicable in case of DS1307 coz it has RAM not ROM.


Sorry for the long post.

Thanks,
SGH

SGH


don't worry about long posts, doubts can be big or small just ask.
Sat Apr 21 2007, 03:46 PM
#7
Rickey, you published I2C code in 8052 forum.

Which line in your send and receive routine for acknowledge ?.

I read in a routine published by Rentron Electronics for AT89C2051 + DS1307, for example in their send_byte routine, it used JNB SDA to check for acknowledge.

What is the function of rlc c in your routine ?.


Thanks,
SGH
Tags acknowledgeds1307at89c2051jnbrickey
Sat Apr 21 2007, 05:54 PM
#8
In my routines, i am not checking for ack! i am assuming that the data transfer is perfect and ack is received. thats the reason, it cannot be used for EEPROM.
but my C routines can be used for EEPROM and any I2C device.

RLC A instruction means "rotate left through carry"
whatever is there in A is rotated left and the MSB is copied back to the place of LSB and all bits are shifted by 1 toward left. and the MSB is also copied to the Carry flag.
e.g.
A is 0x10110100 and carry is 0
after RLC A
A is 0x01101001 and carry is 1
Tags msbeepromrlcackc routines
Wed Mar 12 2008, 02:34 AM
#9
After a while, I still unable to write a correct code to write and read from EEPROM (AT24C01A). I have read the datasheet many times and still could not figure out the way to write the proper code.

Would you please help me or let me know where I can download the routine (in assembly). I'm using AT24C01A with AT89S51.

Thanks,
SGH
Wed Mar 12 2008, 06:05 PM
#10
my old I2C code wont work with EEPROM. check I2C library section in download area.

Get Social

Information

Powered by e107 Forum System

Conversation

Sun Oct 13 2019, 02:02 AM
Aline Hutchinson
Hey there,
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

Downloads

Comments

ilylily07
Tue Oct 15 2019, 04:32 PM
hientran123
Tue Oct 15 2019, 02:27 AM
Sat Oct 05 2019, 02:38 PM
zexalo
Thu Oct 03 2019, 09:53 AM
thanhle12345
Thu Oct 03 2019, 07:37 AM
ramon_vsc
Fri Sep 20 2019, 04:53 PM
youssoufba
Thu Sep 19 2019, 11:57 AM
Taiphan000
Tue Sep 17 2019, 04:21 AM

Online

Guests: 38, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38097
Newest member: ilylily07
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:05 PM
sir, 3rd and 4th dot matrix display flickering, ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Oct 18 2019, 09:18 PM
Hopefully you understand some of the program.Which...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Thu Oct 17 2019, 09:38 PM