/* test_twi_master.c */ #include "twi_master.h" #include #include #include #include void proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) { uint8_t data[1] = {0x00}; int8_t c; sei (); switch (cmd) { case 's': if (size == 2) { proto_send ('s', 0, 0); twi_master_send (args[0], &args[1], 1); while (!twi_master_is_finished ()) ; proto_send ('f', 0, 0); } else proto_send ('e', 0, 0); break; case 'r': if (size == 2) { rs232_putc ('r'); c = twi_master_read (args[0], data, 1); if (c != 0) proto_send ('e', 1 , 0); else { while (!twi_master_is_finished ()) ; proto_send ('f', 1, data); } } else proto_send ('e', 1, 0); break; default: proto_send ('e', 1, 0); } } int main (void) { uint8_t c; rs232_init (); twi_master_init (); rs232_putc ('m'); rs232_putc ('s'); rs232_putc ('s'); rs232_putc ('\n'); //DDRC = 1; //PORTC = 1; while (42) { c = rs232_getc (); proto_accept (c); } return 0; }