#include "bsp.h" #include "tty.h" int i2c_bytep; int i2c_count; char i2c_bytes[] = { 0x00, 0xff, 0x55, 0xaa, 0x80, 0x01 }; /* tx = NACK */ void __attribute__((interrupt)) s0tx_handler (void) { p2.b = 'N'; if (i2c_bytep == i2c_count) { u0smr4.b = 0x04; u0smr4.b = 0x0c; } else { u0tbw = i2c_bytes[i2c_bytep++] | 0x0100; } } /* rx = ACK */ void __attribute__((interrupt)) s0rx_handler (void) { p2.b = 'A'; } void __attribute__((interrupt)) s0ss_handler (void) { p2.b = 'S'; if (i2c_bytep) /* End of transmission */ i2c_bytep = -1; else { /* Start of transmission */ p2.b = 0; u0c1.b = 0x15; /* enable tx, rx */ p2.b = 1; u0smr4.b = 0x00; p2.b = 2; u0tbw = i2c_bytes[0] | 0x0100; p2.b = 3; i2c_bytep = 1; } } main() { int i; pd2.b = 0xff; p2.b = 0x55; pd6.b = 0x0c; pur2.b = 0x01; wait_ms (3); for (i=0; i<50; i++) { p6.b = 0xff; p6.b = 0x00; } p2.b = 0xC1; pd6.b = 0x00; wait_ms (1); p2.b = 0x0f; // Set up UART0 for serial output for testing. u0brg = 99; /* 20 mhz / 200 khz / 8*/ u0mr.b = 0x02; /* UART, 8N1 */ u0c0.b = 0xb0; /* LSB first, CMOS, buffered, f1, CRD, NCH? UFORM? !CKPOL */ u0c1.b = 0x10; /* disable tx, rx */ u0smr.b = 0x01; u0smr2.b = 0x00; u0smr3.b = 0xe2; u0smr4.b = 0x70; /* commands */ ps0.b = 0x0c; psl0.b = 0x02; /* Interrupts */ ifsr = 0xc0; s0tic = 0x05; s0ric = 0x05; bcn0ic = 0x05; asm("fset I"); p2.b = 0xAA; wait_ms (1); while (1) { wait_ms (1); i2c_bytep = 0; i2c_count = 6; p2.b = 0x81; /* Generate start condition */ u0smr4.b = 0x71; u0smr4.b = 0x09; /* wait for interrupts to cycle through the whole data stream. */ while (i2c_bytep != -1) p2.b = u0smr4.b; p2.b = 0x84; } }