]> git.zerfleddert.de Git - rsbs2/blobdiff - bmc/i2c.c
beginning i2c
[rsbs2] / bmc / i2c.c
diff --git a/bmc/i2c.c b/bmc/i2c.c
new file mode 100644 (file)
index 0000000..992d6ce
--- /dev/null
+++ b/bmc/i2c.c
@@ -0,0 +1,26 @@
+#include <util/twi.h>
+#include <avr/interrupt.h>
+#include <stdio.h>
+#include "i2c.h"
+
+#define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);  
+#define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);
+#define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|(0<<TWWC);  
+
+void i2c_init()
+{
+       TWAR = BMC_ADDR;
+       TWCR &= ~(1<<TWSTA)|(1<<TWSTO);
+       TWCR|= (1<<TWEA) | (1<<TWEN)|(1<<TWIE); 
+}
+
+ISR (TWI_vect)
+{
+       printf("Interrupt, Status: %02x!\n", TW_STATUS);
+
+       switch (TW_STATUS) {
+               default:
+                       TWCR_RESET;
+                       break;
+       }
+}
Impressum, Datenschutz