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

i2c_transfer for LTC2635
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
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jan 17, 2019 2:33 am     Reply with quote

Yes. The key to this is to read the data sheet (old story...), and then look
at how this peripheral actually works.
The I2C_transfer instruction, directly relates to the hardware on this chip.

The value given as the 'count', is the value fed into the I2CcCNT register.
This register gives the total number of bytes for the whole transaction,
including the I2C address that is loaded into the 12CxADB1 register
(which is the 'address' byte from the CCS transfer).

This is made plain in the datasheet entry about this:
Quote:

The I2CxCNT register is used to specify the number of
bytes in a complete I2C packet. The value in this
register will decrement every time a data byte is
received or transmitted from the I2C module. The
I2CxCNT register will not decrement past zero.
//Then in the entry for master transmission:
Master software loads the number of bytes to be
transmitted in one sequence in I2CxCNT, slave
address in I2CxADB1 with R/W = 0 and the first byte
of data in I2CxTXB.


So to transfer a three byte buffer, you actually have a four byte transfer
(buffer + address byte).

If CCS documented this a bit more, it'd help massively.
Something like this in the I2C_transfer documentation:
Quote:

wCount - Number of bytes to transfer to device. This includes the address
byte.
Therefore for a 1 byte buffer, a count of 2 should be used. etc..
temtronic



Joined: 01 Jul 2010
Posts: 9098
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 17, 2019 6:26 am     Reply with quote

We should all thank Mr. T for taking the time to read and explain this 'new I2C module ! While I don't have this PIC and my compiler's old(OK, ancient like me...) I'm always curious.,but not enough to read the 800 page datasheet.
My 'gut' feeling was that you'd need 4 as the count to send 3 data bytes as the I2C address is SENT on the bus,so it is part of the 'data packet'.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jan 17, 2019 11:36 am     Reply with quote

Agreed. However I think it really should be documented. It's not
really logical that you pass the function perhaps an array containing
five bytes to send, but then have to tell it to send six bytes...
Once you understand I2C, it makes sense as this is the whole
'packet'.
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