[General] I2C protocol 1 byte read

Status
Not open for further replies.

asimov_18

Member level 2
Joined
Sep 25, 2006
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
London---UK
Visit site
Activity points
1,816
Hello Users,
I have a very basic question about I2C.
I am interfacing a micro(any micro) to an I2c memory device.

If i wish to read only 1 byte from a particular memory address
I would send the following commands.
1) Start condition
2) device address+ write command bit active
3) Check if acknowledgement received
4) Write address of the memory location
5) Check if acknowledgement received
6) Generate a repeated start condition
7) Give device address+read command bit active
8) Check if acknowledgement received
9) generate the clock and read the first byte
10) Generate the acknowledgement or not?
11) Generate the stop condition

I just wish to know is the 10 step correct or not. Do I give an acknowledgment
or not after reading my 1st (and only byte to be read)?

Asimov
 

in step also you have to read the acknowledgement, you need not generate it.

If you use library functions it will be much more easier.
 
Hi,

For detailed protocol informtion please read the memory's datasheet.
There are different protocols used for different types of memory.

Also in the datasheet you will find when to send or wait for an acknowledge.

Klaus
 
Thanks for the response. I wasn't sure if one was allowed to send a NACK for the first byte one receives even if it is the only byte to be received.
Thanks for the inputs.

Asimov
 

İ also want to ask a question here. im able to send to and read from a character like 'd' (one byte, 8 bits ) data to the epprom. i have no problem.

but i want to make 8 bits integers (changing from 0-255 numerical values i mean) to write and read in one byte to the epprom.

how can i do?
 
Last edited:

Hi,


What's the difference between character and 8 bit integer?

Klaus
 

Hi,


What's the difference between character and 8 bit integer?

Klaus

for example for letter 'c' it is 01100011 this value to the eeprom. and also for number 99 it is storing the same value.

i have solve this like this. is it a good way or bad? how can i else do it?

for 99

wrdata(RxByte); a function that writing one byte to the lcd. this gives me letter c on the lcd.
sprintf(data,"%d",RxByte);
wrstr(data,1,0); a function that writes an array to the lcd. this gives me 99 on the lcd.
 
Last edited:

Hi,

before you wrote writing a charactor to the EEPROM.
in the same text you wrote about writng an 8 bit integer to an EEPROM.

which is the same thing for me.

******
now you speak of wirting an ASCII charactor to an LCD
and converting a integer number to a two byte string and sending the string to an LCD.

That is totally different.

******
i doubt you want to convert an integer number to a string and write it to an EEPROM.

******
byte, int8, uint8, character, 8bits .... is all the same when stored to a memory cell.
But it is different how to interprete those 8 bits.
it can be interpreted like a positive number, like a negative number, an ASCII character or anything else. But the interpretation is more human syte, the EEPROM won´t think about it. ;-)


Klaus
 

yep , when i asked this question i was thinking something wrong with the epprom sequence. after i have understood that it is just releted to how i interpreted to it.

im using hi tech c compiler. so here my goal was saving the data like A99 to the epprom in 2 bytes. if try to save them like 'A', '9' and '9' they are all charechters and it was 3 bytes. i was just trying to save them in 2 bytes and then read them from epprom and sent them to lcd screen with 2 bytes.

"it can be interpreted like a positive number, like a negative number, an ASCII character or anything else. But the interpretation is more human syte, the EEPROM won´t think about it. ""

could you give me a few example (short code) showing a one byte data is giving me different things. like a letter, a number, a positive number ...bla bla. it will help me.
 

Hi,

could you give me a few example (short code) showing a one byte data is giving me different things. like a letter, a number, a positive number ...bla bla. it will help me.

You answered this already in this question and in your post #8.


0b 1111 1111 can be: -1 for a signed integer, or 255 as an unsigned integer.

0b 0110 0011 can be an ACII letter "c", it can be it can be 99 as decimal number, it can be 0x63 as hexadecimal number.
you can even interpret it as 1.93V when you see it as an 8 bit ADC value (unipolar 5V range)
or as "purple" when seen as 8 bit RGB color.

Usually it is the job of the programmer that stores data in a memory to know how to interprete the information.

Klaus
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…