datalogger

Simple I2C responder

  1. include <mbed.h>

I2CSlave slave(p9, p10);

int main() { char buf[10]; char msg[] = "Slave!";

slave.address(0xA0); while (1) { int i = slave.receive(); switch (i) { case I2CSlave::ReadAddressed: slave.write(msg, strlen(msg) + 1); Includes null char break; case I2CSlave::WriteGeneral: slave.read(buf, 10); printf("Read G: %s\n", buf); break; case I2CSlave::WriteAddressed: slave.read(buf, 10); printf("Read A: %s\n", buf); break; } for(int i = 0; i < 10; i++) buf[i] = 0; Clear buffer } }


Please log in to post comments.