SHARE
TWEET

Untitled

a guest Jul 18th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void led_on()
  2. {
  3.     //turn on led
  4. }
  5.  
  6. void twi_start()
  7. {
  8.     TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTA);
  9.  
  10.     while (!(TWCR & (1 << TWINT)));
  11. }
  12.  
  13. void twi_stop()
  14. {
  15.     TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
  16.  
  17.     while (!(TWCR & (1 << TWSTO)));
  18. }
  19.  
  20. void twi_write(uint8_t byte)
  21. {
  22.     TWDR = byte;
  23.  
  24.     TWCR = (1 << TWINT) | (1 << TWEN);
  25.  
  26.     while (!(TWCR & (1 << TWINT)));
  27. }
  28.  
  29. void twi_write_byte(uint8_t byte)
  30. {
  31.     twi_start();
  32.     twi_write(0x4E);
  33.  
  34.     //if (TWSR & 0x18) {
  35.     //  led_on();
  36.     //} // it works as expected
  37.  
  38.     twi_write(byte);
  39.  
  40.     led_on(); // this is never reached
  41.  
  42.     twi_stop();
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top