View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 17, 2017 10:36 am |
|
|
Having the hard address of 0xA1 in that line is a mistake that was not spotted.
That line should actually be:
Code: | i2c_write(device_address | 1); |
|
|
 |
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
|
Posted: Thu Aug 17, 2017 10:39 am |
|
|
PCM programmer wrote: | Having the hard address of 0xA1 in that line is a mistake that was not spotted.
That line should actually be:
Code: | i2c_write(device_address | 1); |
|
I am finally beginning to become beneficial for the forum and CCSINFO :D.
I changed it to "device_address + 1", I think mine is better? _________________ Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems! |
|
 |
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
|
Posted: Thu Aug 17, 2017 10:42 am |
|
|
So why does this has to be with 1 more? _________________ Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems! |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 17, 2017 10:51 am |
|
|
Either method works. It sets the Read/Write bit to "Read" mode.
That's what is required in that function, at that line of code. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19809
|
|
Posted: Thu Aug 17, 2017 11:32 am |
|
|
The device address is actually the top 7 bits of the number sent:
0baaaaaaax
The 'x' is a flag for read/write.
Now there are two different ways of expressing I2C device addresses.
Texas use the '7 bit format'. So device numbers 0 to 127 (though 0 to 7 and 127, are reserved), which you then multiply by two, and add the extra bit for read/write.
Most other manufacturers use the 8bit address format, with devices only being allowed to use even addresses, so 0, 2, 4, 6 etc..
Now using 'or' '|' is the standard way in code to set a bit without changing any other bit in the number. It'll work even if (for instance) the number was a signed int8, while '+1', risks problems is there is a wrap. I'd avoid this in more serious code, since at some point you will find yourself setting something unexpected. I'd avoid unwanted by using the addition...
Probably if coding this for a real application, I'd actually use a 'chip number' (0 to 7), and then have the code multiply by 2, and add this to the base address (0xA0, stored as 'FIRST_CHIP'). Then I'd probably code a value of '1' as 'I2C_READ', and or with this for the read operation to make it much more self-documenting. |
|
 |
Arakel
Joined: 06 Aug 2016 Posts: 107 Location: Moscow
|
|
Posted: Thu Aug 17, 2017 11:45 am |
|
|
Yes, I see, first it initializes the internal counter of the EEPROM to go at address "0", then for random read, without a "stop condition" it gives another "start_condition" and gives a read bit.
I am sorry, sometimes its difficult to orient in the code, it becomes so much, that I just can't accept more information. My mind goes blank, like it or not, not accepting and not transmitting :D. _________________ Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems! |
|
 |
|