|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19215
|
|
Posted: Thu Jan 17, 2019 2:33 am |
|
|
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
|
|
Posted: Thu Jan 17, 2019 6:26 am |
|
|
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
|
|
Posted: Thu Jan 17, 2019 11:36 am |
|
|
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'. |
|
|
|
|
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
|