]> git.zerfleddert.de Git - rsbs2/commitdiff
working i2c connection to RSBS2-card
authorMichael Gernoth <michael@gernoth.net>
Sun, 22 Aug 2010 16:31:35 +0000 (18:31 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sun, 22 Aug 2010 16:31:35 +0000 (18:31 +0200)
bmc/Makefile
bmc/bmc.c
bmc/i2c.c

index 8adc53d1798a225998a649843f8b6553425e53d0..6f8b4ddde473b69e4c5df6007560a559b39dcb10 100644 (file)
@@ -1,9 +1,13 @@
-CC=avr-gcc
-CFLAGS=-mmcu=atmega16 -DF_CPU=8000000UL -Wall -g
-OBJCOPY=avr-objcopy
 PROG=dragon_jtag
 PORT=usb
 PMCU=m16
+GCCMCU=atmega16
+
+CPUFLAG=-mmcu=$(GCCMCU)
+CC=avr-gcc
+CFLAGS=$(CPUFLAG) -DF_CPU=8000000UL -Wall -g
+LDFLAGS=$(CPUFLAG)
+OBJCOPY=avr-objcopy
 
 all: bmc.bin
 
index c786032e092d235dec4240be704dae4eda4c34b6..d7c5cdc95ec4d1c4028112f188b6547e7320b081 100644 (file)
--- a/bmc/bmc.c
+++ b/bmc/bmc.c
@@ -1,4 +1,5 @@
 #include <avr/io.h>
+#include <avr/sleep.h>
 #include <avr/interrupt.h>
 #include <stdio.h>
 #include "usart.h"
@@ -6,27 +7,24 @@
 
 int main(void)
 {
-       uint8_t pb = 0x00;
-       int8_t dir = 1;
-       volatile uint16_t i;
-
        DDRB = 0xff;
+       PORTB = 0xff;
 
        usart_init();
+       printf("\n");
+
        i2c_init();
 
+       printf("Waiting for I2C...\n");
+
        sei();
 
-       printf("Hallo!\n");
+       PORTB = 0xff;
 
        while(1) {
-               pb += dir;
-               PORTB = pb;
-
-               for (i = 0; i < (pb<<5); i++) {}
-
-               if ((pb == 0) || (pb == 0xff))
-                       dir = -dir;
+#if 1
+               sleep_mode();
+#endif
        }
 
        return 0;
index 992d6ce4c840f2cb6324c2067396352f631e1578..214d410158ee3dea10e1fbb4059c24fceb736278 100644 (file)
--- a/bmc/i2c.c
+++ b/bmc/i2c.c
@@ -9,18 +9,21 @@
 
 void i2c_init()
 {
-       TWAR = BMC_ADDR;
-       TWCR &= ~(1<<TWSTA)|(1<<TWSTO);
-       TWCR|= (1<<TWEA) | (1<<TWEN)|(1<<TWIE); 
+       TWAR = BMC_ADDR & 0xfe;
+       TWDR = 0x00;
+       TWCR &= ~((1<<TWSTA) | (1<<TWSTO));
+       TWCR |= ((1<<TWEA) | (1<<TWEN) | (1<<TWIE)); 
+       printf("Status: 0x%02x\n", TW_STATUS);
+       PORTC = 0x03;
 }
 
-ISR (TWI_vect)
+ISR (TWI_vect, ISR_BLOCK)
 {
-       printf("Interrupt, Status: %02x!\n", TW_STATUS);
+       printf("Interrupt, Status: 0x%02x, Data: 0x%02x!\n", TW_STATUS, TWDR);
 
        switch (TW_STATUS) {
                default:
-                       TWCR_RESET;
+                       TWCR_ACK;
                        break;
        }
 }
Impressum, Datenschutz