]>
cvs.zerfleddert.de Git - rsbs2/blob - bmc/i2c.c
7104758551a25b280296ea999091638557a56f00
   2 #include <avr/interrupt.h> 
   7 #define TWCR_ACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC);   
   8 #define TWCR_NACK TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(0<<TWEA)|(0<<TWSTA)|(0<<TWSTO)|(0<<TWWC); 
   9 #define TWCR_RESET TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWEA)|(0<<TWSTA)|(1<<TWSTO)|(0<<TWWC);   
  11 static volatile unsigned char databuf
[12]; 
  12 static volatile uint8_t pos 
= 0x00; 
  16         TWAR 
= BMC_ADDR 
& 0xfe; 
  18         TWCR 
&= ~((1<<TWSTA
) | (1<<TWSTO
)); 
  19         TWCR 
|= ((1<<TWEA
) | (1<<TWEN
) | (1<<TWIE
));  
  20         printf("Status: 0x%02x\n", TW_STATUS
); 
  24 ISR (TWI_vect
, ISR_BLOCK
) 
  29                         printf("I2C: Slave 0x%02x adressed\n", TWDR
); 
  37                         printf("I2C: Data received: 0x%02x\n", TWDR
); 
  46                         printf("I2C: STOP received\n"); 
  48                         decode_bmc_cmd((unsigned char*)databuf
, pos
); 
  55                         printf("I2C: Data requested\n"); 
  61                         printf("I2C: Unimplemented status 0x%02x\n", TW_STATUS
);