#include <stdio.h>
#include "usart.h"
#include "i2c.h"
+#include "bmc.h"
+
+void decode_bmc_cmd(unsigned char *buf, int len)
+{
+ int i;
+
+ for(i = 0; i < len; i++) {
+ printf("0x%02x ", buf[i]);
+ }
+
+ printf("\n");
+}
int main(void)
{
sei();
- PORTB = 0xff;
-
while(1) {
#if 1
sleep_mode();
#include <avr/interrupt.h>
#include <stdio.h>
#include "i2c.h"
+#include "bmc.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);
+static volatile unsigned char databuf[12];
+static volatile uint8_t pos = 0x00;
+
void i2c_init()
{
TWAR = BMC_ADDR & 0xfe;
ISR (TWI_vect, ISR_BLOCK)
{
- printf("Interrupt, Status: 0x%02x, Data: 0x%02x!\n", TW_STATUS, TWDR);
-
switch (TW_STATUS) {
- default:
+ case TW_SR_SLA_ACK:
+#ifdef DEBUG
+ printf("I2C: Slave 0x%02x adressed\n", TWDR);
+#endif
+ pos = 0x00;
+ TWCR_ACK;
+ break;
+
+ case TW_SR_DATA_ACK:
+#ifdef DEBUG
+ printf("I2C: Data received: 0x%02x\n", TWDR);
+#endif
+ databuf[pos] = TWDR;
+ pos++;
+ TWCR_ACK;
+ break;
+
+ case TW_SR_STOP:
+#ifdef DEBUG
+ printf("I2C: STOP received\n");
+#endif
+ decode_bmc_cmd((unsigned char*)databuf, pos);
+ pos = 0x00;
+ TWCR_RESET;
+ break;
+
+ case TW_ST_SLA_ACK:
+ case TW_ST_DATA_ACK:
+ printf("I2C: Data requested\n");
+ TWDR = 0x00;
TWCR_ACK;
break;
+
+ default:
+ printf("I2C: Unimplemented status 0x%02x\n", TW_STATUS);
+ TWCR_RESET;
+ break;
}
}
--- /dev/null
+Power OFF:
+ 0x00 0xdc 0x28 0x04 0x02 0x00 0xd2
+ 0x00 0xdc 0x28 0x08 0x02 0x00 0xce
+
+Hard Reset:
+ 0x00 0xdc 0x28 0x04 0x02 0x03 0xcf
+
+Power ON:
+ 0x00 0xdc 0x28 0x04 0x02 0x01 0xd1
+ 0x00 0xdc 0x28 0x08 0x02 0x01 0xcd
+
+Unknown (periodic messages):
+ 0x18 0xc4 0x28 0x04 0x25 0xaf
+ 0x18 0xc4 0x28 0x04 0x01 0xd3
+ 0x18 0xc4 0x28 0x08 0x25 0xab
+ 0x18 0xc4 0x28 0x08 0x01 0xcf