Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

STRING AND 24C256 EEPROM

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
EKREMhbx

Bascom Member



Joined: 06 Jun 2005
Posts: 27

PostPosted: Thu Oct 20, 2005 2:02 pm    Post subject: STRING AND 24C256 EEPROM Reply with quote

HELLO

Dim data1 as string *7
data1 = "ekremhb"

How I can write this data1 string to 24c256 eeprom and
how I can read this string from 24c256 eeprom

regards
Back to top
View user's profile
DJD XTREEM

Bascom Member



Joined: 24 Jun 2004
Posts: 190
Location: 127.0.0.1

netherlands.gif
PostPosted: Thu Oct 20, 2005 9:38 pm    Post subject: Reply with quote

Well i geuss that the eeprom is an IC type?

I'm intressted too in this one.. Need some extra memory in short terms..

_________________
Bascom AVR 1.11.8.8 full version
STK500 Programmer
ISP Programmer
Back to top
View user's profile Visit poster's website MSN Messenger
Funci

Bascom Member



Joined: 03 Aug 2005
Posts: 58
Location: CRO

croatia.gif
PostPosted: Thu Oct 20, 2005 10:14 pm    Post subject: Reply with quote

Hi

I have experience with Bascom 8051 and EEPROM's, but I am thinking that principles aer the same and with Bascom AVR.
When you are saving string in EEPROM you must brake it:

"ekremhb" --> "e" + "k" + "r" + "e" + "m" + "b" + "h"

and save this single string on diferent places in EEPROM!
For example:
"e" --> on adress "100"
"k" --> on adress "101"

.
.
.

"h" --> on adress "106"


So, it's very important to know where you are puting this strings for taking them back from EEPROM!

I am hoping that this will helps you Smile
Back to top
View user's profile Visit poster's website
DToolan

Bascom Member



Joined: 14 Aug 2004
Posts: 1384
Location: Dallas / Fort Worth, Texas (USA)

blank.gif
PostPosted: Thu Oct 20, 2005 11:15 pm    Post subject: Reply with quote

Look at I2CSend in the html help file. Since I2CSend doesn't deal with strings, you can work around that like so...

Code:
Dim Data1 As String * 7
Data1 = "ekremhb"

Dim DataArray(7) As Byte at Data1 Overlay

Dim X As Byte
Dim Y As Byte

Const Slave = &HA0
Y = Len(Data1)

For X = 1 To Y

    I2CSend Slave, DataArray(X)

Next X

There is a lot more to it than this though. As Funci points out, you have to know what address within the chip you want to write to and later, what address within the chip you want to retrieve from.

The procedure for accessing (writing or reading) the 24C256 is as follows...

1. I2C start
2. Send the device write address
3. Send the high byte of the address within the device you wish to write or read
4. Send the low byte of the address within the device you wish to write or read
5. If reading, I2C re-start and then the device read address... else, send data.
6. When done, I2C stop
Back to top
View user's profile Yahoo Messenger
EKREMhbx

Bascom Member



Joined: 06 Jun 2005
Posts: 27

PostPosted: Sat Oct 22, 2005 5:19 pm    Post subject: string and 24c256 Reply with quote

thank you for all
inetereting

Iam using ds1307 and 24c256 same port pin

so can write string and then read back whit I2Csend command

regards
Back to top
View user's profile
EKREMhbx

Bascom Member



Joined: 06 Jun 2005
Posts: 27

PostPosted: Sun Oct 23, 2005 8:54 am    Post subject: data write and read + 24c256 Reply with quote

I thing I2csend and receive command is not support 24c256 eeprom

so,

I want write 1.st data address 1000 and 2.nd data write address 1001 ,
3.data write address 1002 ,,,,1003,1004 ,1005 and go

How I can write program procedure for I2cread and I2c write command
for big address write to 24c256.

because I2c write command is need two line address address hi and
address lo

regards
Back to top
View user's profile
Funci

Bascom Member



Joined: 03 Aug 2005
Posts: 58
Location: CRO

croatia.gif
PostPosted: Sun Oct 23, 2005 10:12 pm    Post subject: Reply with quote

Hi Ekrem

This is good question! I don't have experience with EEPROM's larger than 24C16, but I am thinking that D'Toolan will give some answer!
D'Toolan? Smile
Back to top
View user's profile Visit poster's website
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon Oct 24, 2005 8:29 pm    Post subject: I2c commands and 24LC256 Reply with quote

Where I found it I don't know, but I use these routines to write to a 24LC256 EEPROM.

'24LC256
Dim E_ah As Byte
Dim E_al As Byte
Dim E_addr As Word
Dim E_dat As Byte
Dim Dat As Byte

'24lc256
Declare Sub E_write(byval E_addr As Word , Dat As Byte)
Declare Sub E_read(byval E_addr As Word , E_dat As Byte)
Declare Sub 24lc256_test

call 24lc256_test
end


' Routine to test the 24LC256
'
Sub 24lc256_test
'Test read and writes
Print "Testing I2C Eeprom"
Dat = 0
For E_addr = &H1000 To &H1010
Call E_write(e_addr , Dat)
Call E_read(e_addr , E_dat)
Print E_dat ; " ";
Incr Dat
Incr Dat
Incr Dat ' +1 +1 +1
Next E_addr

Print
Print "Here a counter should appear from 0, 3, 6, 9, 12, 15, 18, 21, 24, 27 etc."
Print "End of Test"
End Sub


' Routine to write the 24LC256
'
Sub E_write(byval E_addr As Word , Dat As Byte)
E_ah = High(e_addr)
E_al = Low(e_addr)
I2cstart
I2cwbyte E_ctlw
I2cwbyte E_ah
I2cwbyte E_al
I2cwbyte Dat
I2cstop
Waitms 10
End Sub


' Routine to read the 24LC256
'
Sub E_read(byval E_addr As Word , E_dat As Byte)
E_ah = High(e_addr)
E_al = Low(e_addr)
I2cstart
I2cwbyte E_ctlw
I2cwbyte E_ah
I2cwbyte E_al
I2cstart
I2cwbyte E_ctlr
I2crbyte E_dat , Nack
I2cstop '
End Sub

--

Have fun
Ben Zijlstra
http://members.home.nl/bzijlstra
Back to top
View user's profile Visit poster's website
DToolan

Bascom Member



Joined: 14 Aug 2004
Posts: 1384
Location: Dallas / Fort Worth, Texas (USA)

blank.gif
PostPosted: Tue Oct 25, 2005 10:27 pm    Post subject: Reply with quote

There are some "gotcha's" when working with serial eeproms that you should be aware of. Most have some sort of default "page size". The "page size" for a 24C256 is 64 bytes.

If you write to your eeprom one byte at a time (byte mode), you will notice no problems, although, you must wait 10ms between each write operation and/or a write (wait 10ms) then a read operation. Basically, the write cycle time for a byte is 10ms. The eeprom will not respond to an I2C attempt until any write cycle is complete. An example of byte mode writing might be...

1. I2C start
2. Send the device write address
3. Send the high byte of the address within the device you wish to write
4. Send the low byte of the address within the device you wish to write
5. send a byte of data
6. I2C stop
7. Wait 10ms before repeating or before reading

Page mode writing is where you send the device an address (where within the chip you'd like to write) once, and then send multiple bytes of data. An example of page mode writing might be...

1. I2C start
2. Send the device write address
3. Send the high byte of the address within the device you wish to write
4. Send the low byte of the address within the device you wish to write
5. Send multiple bytes of data
6. When done, I2C stop
7. Wait 10ms before repeating or before reading

Problems can arise when you try writing in "Page Mode" (multiple bytes in one session) but you cross a page boundry. For simplicity sake, I am going to use a 24LC16 as an example. The 24LC16 page size is 16 bytes.

1. I2C start
2. Send the device write address
3. Send the address within the device you wish to write (&H00)

For X = 0 TO 17
5. Send data byte (X)
Next X

6. When done, I2C stop
7. Wait 10ms before repeating or before reading

The example above sent 18 bytes of data (values 0 through 17) to be written into locations 0 through 17 of the eeprom. The result of this attempt would be the following...

Code:
Address      Data
00            16
01            17
02            02
03            03
04            04

'continues in order...

14            14
15            15
16            FF
17            FF
18            FF
etc...

As you can see... the eeprom's internal address counter wrapped around when it hit a page boundry. The data you wanted in locations 16 and 17 ended up in locations 0 and 1. If you plan to write data in "Page Mode" (multiple bytes at once), you must be wary of where the page boundries are and not cross them without pre-planning.
Back to top
View user's profile Yahoo Messenger
Funci

Bascom Member



Joined: 03 Aug 2005
Posts: 58
Location: CRO

croatia.gif
PostPosted: Tue Oct 25, 2005 11:40 pm    Post subject: Reply with quote

Yes, I am forget "page size"!
That is important to know when you are sending data to EEPROM with DO-LOOP and FOR-NEXT routines!
So, you must very precisiusly plan how you will send large amout of date into EEPROM.
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum