anchor.diff:  : i2c-ADDR? ( -- b)  1  bit i2c-SR1-flag? ;     \ ADDR bit
   : i2c-MSL? ( -- b)   0  bit I2C1-SR2 hbit@ ;    \ MSL bit
   
  -: i2c-SR1-wait ( u -- ) begin dup i2c-SR1-flag? until drop ; \ Waits until SR1 meets bit mask
  -: i2c-SR1-!wait ( u -- ) begin dup i2c-SR1-flag? 0= until drop ;
  +: i2c-SR1-wait ( u -- ) i2c.timeout @ begin 1- 2dup 0= swap i2c-SR1-flag? or until 2drop ; \ Waits until SR1 meets bit mask or timeout
  +: i2c-SR1-!wait ( u -- ) i2c.timeout @ begin 1- 2dup 0= swap i2c-SR1-flag? 0= or until 2drop ; \ Waits until SR1 has zero on bit mask or timeout
  +: i2c-SR2-wait ( u -- ) i2c.timeout @ begin 1- 2dup 0= swap i2c-SR2-flag? or until 2drop ; \ Waits until SR2 meets bit mask or timeout
  +: i2c-SR2-!wait ( u -- ) i2c.timeout @ begin 1- 2dup 0= swap i2c-SR2-flag? 0= or until 2drop ; \ Waits until SR2 has zero on bit mask or timeout
   
   0  bit constant i2c-SR1-SB
   1  bit constant i2c-SR1-ADDR
  
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:      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<> ;
  