]> git.zerfleddert.de Git - rsbs2/commitdiff
beginning i2c
authorMichael Gernoth <michael@gernoth.net>
Sun, 22 Aug 2010 14:28:20 +0000 (16:28 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sun, 22 Aug 2010 14:28:20 +0000 (16:28 +0200)
bmc/Makefile
bmc/bmc.c
bmc/i2c.c [new file with mode: 0644]
bmc/i2c.h [new file with mode: 0644]

index 7915e96f99e531b36d9b55b2513dae1b78d6cc92..8adc53d1798a225998a649843f8b6553425e53d0 100644 (file)
@@ -7,7 +7,7 @@ PMCU=m16
 
 all: bmc.bin
 
 
 all: bmc.bin
 
-bmc: bmc.o usart.o
+bmc: bmc.o usart.o i2c.o
 
 bmc.bin: bmc
        $(OBJCOPY) -j .text -j .data -O binary $^ $@
 
 bmc.bin: bmc
        $(OBJCOPY) -j .text -j .data -O binary $^ $@
index a0387b339721c1b68f5fd6c907598afd617d5006..c786032e092d235dec4240be704dae4eda4c34b6 100644 (file)
--- a/bmc/bmc.c
+++ b/bmc/bmc.c
@@ -1,6 +1,8 @@
 #include <avr/io.h>
 #include <avr/io.h>
+#include <avr/interrupt.h>
 #include <stdio.h>
 #include "usart.h"
 #include <stdio.h>
 #include "usart.h"
+#include "i2c.h"
 
 int main(void)
 {
 
 int main(void)
 {
@@ -11,6 +13,9 @@ int main(void)
        DDRB = 0xff;
 
        usart_init();
        DDRB = 0xff;
 
        usart_init();
+       i2c_init();
+
+       sei();
 
        printf("Hallo!\n");
 
 
        printf("Hallo!\n");
 
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;
+       }
+}
diff --git a/bmc/i2c.h b/bmc/i2c.h
new file mode 100644 (file)
index 0000000..d666669
--- /dev/null
+++ b/bmc/i2c.h
@@ -0,0 +1,3 @@
+#define BMC_ADDR 0x24
+
+void i2c_init();
Impressum, Datenschutz