anchor.diff:       0 variable i2c.cnt
        0 variable i2c.addr
        0 variable i2c.needstop
  + $ffff variable i2c.timeout
   
   \ Checks I2C1 busy bit
   : i2c-busy?   ( -- b) I2C1-SR2 h@ 1 bit and 0<> ;
  
positive.code: 7  bit constant i2c-SR1-TxE
  10 bit constant i2c-SR1-AF
  
  \ Medium level actions, no or limited status checking
  
  : i2c-start ( -- ) \ set start bit and wait for start condition
    i2c-start! i2c-SR1-SB i2c-SR1-wait ;
  
  : i2c-stop  ( -- )  i2c-stop! begin i2c-MSL? 0= until ; \ stop and wait
  
  : i2c-probe ( c -- nak ) \ Sets address and waits for ACK or NAK
    i2c-start
  
negative.code: : i2c-AF-0 ( -- )  10 bit I2C1-SR1 hbic! ;      \ Clears AF flag
  : i2c-START-0 ( -- )   8 bit I2C1-CR1 hbic! ;   \ Clears START condition
  : i2c-SR1-flag? ( u -- ) I2C1-SR1 hbit@ ;
  : i2c-SR2-flag? ( u -- ) I2C1-SR2 hbit@ ;
  : i2c-ACK-1 ( -- ) 10 bit I2C1-CR1 hbis! ;
  : i2c-ACK-0 ( -- ) 10 bit I2C1-CR1 hbic! ;
  : i2c-POS-1 ( -- ) 11 bit I2C1-CR1 hbis! ;
  