]> git.zerfleddert.de Git - rsbs2/blame - bmc/i2c.c
working i2c connection to RSBS2-card
[rsbs2] / bmc / i2c.c
CommitLineData
99e4226b
MG
1#include <util/twi.h>
2#include <avr/interrupt.h>
3#include <stdio.h>
4#include "i2c.h"
5
6#define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);
7#define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);
8#define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|(0<<TWWC);
9
10void i2c_init()
11{
7f52e040
MG
12 TWAR = BMC_ADDR & 0xfe;
13 TWDR = 0x00;
14 TWCR &= ~((1<<TWSTA) | (1<<TWSTO));
15 TWCR |= ((1<<TWEA) | (1<<TWEN) | (1<<TWIE));
16 printf("Status: 0x%02x\n", TW_STATUS);
17 PORTC = 0x03;
99e4226b
MG
18}
19
7f52e040 20ISR (TWI_vect, ISR_BLOCK)
99e4226b 21{
7f52e040 22 printf("Interrupt, Status: 0x%02x, Data: 0x%02x!\n", TW_STATUS, TWDR);
99e4226b
MG
23
24 switch (TW_STATUS) {
25 default:
7f52e040 26 TWCR_ACK;
99e4226b
MG
27 break;
28 }
29}
Impressum, Datenschutz