Searching \ for 'I2C code explanation Provided sample' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/i2cs.htm?key=i2c
Search entire site for: 'I2C code explanation Provided sample'.

Truncated match.
PICList Thread
'I2C code explanation Provided sample'
1998\05\08@002221 by PHXSYS

picon face
Hello

The following is a code snip for I2C between a BS2 and another device. I am
new at this and trying to understand the code. It is not commented. I was
hoping someone could explain how this works. It seems to me it would be more
effective to use the shiftin/shiftout command? I am really having trouble with
the :

IF (bit_count & in_byte) then si2c_wbyte_do1

The "in_byte" is the value we want to write, but it is the "bit_count" that
is shifted to the right. Does this previous command mask the two variables and
"bit_count" is now the sum of those two variables after the mask?

Can someone make this code more efficient?

Help

si2c_wbyte:             ' returns 1 if successful, 0 = NACK
                       ' in_byte is byte to be written
   bit_count=%10000000
   si2c_wbyte_lp:
       low si2c_clk
       input si2c_data
       IF (bit_count & in_byte) then si2c_wbyte_do1
           low si2c_data
       si2c_wbyte_do1:
       bit_count=bit_count>>1
       input si2c_clk
       IF bit_count then si2c_wbyte_lp

   ' now test the acknowlege bit
   low si2c_clk
   input si2c_data
   input si2c_clk
   exit_ack=0
   IF in1 then si2c_wbyte_ex
       exit_ack=1
   si2c_wbyte_ex:
   return

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...