CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

EX_EXTEE.C question (3)
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 17, 2017 10:36 am     Reply with quote

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

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Thu Aug 17, 2017 10:39 am     Reply with quote

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

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Thu Aug 17, 2017 10:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 17, 2017 10:51 am     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Thu Aug 17, 2017 11:32 am     Reply with quote

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

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Thu Aug 17, 2017 11:45 am     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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


Powered by phpBB © 2001, 2005 phpBB Group