Extension of original I2CSlave library to support multiple slave addresses and interrupts.

Files at this revision

API Documentation at this revision

Comitter:
jaerts
Date:
Sat Jul 12 15:26:34 2014 +0000
Parent:
0:f94c714b3b4d
Commit message:
Update example code

Changed in this revision

I2CSlaveX.h Show annotated file Show diff for this revision Revisions of this file
diff -r f94c714b3b4d -r b7e586fffbf2 I2CSlaveX.h
--- a/I2CSlaveX.h	Sat Jul 12 15:09:06 2014 +0000
+++ b/I2CSlaveX.h	Sat Jul 12 15:26:34 2014 +0000
@@ -7,9 +7,46 @@
     
 /** An I2C Slave, used for communicating with an I2C Master device with support for Interrupts and multiple slave addresses
  *
+ * Warning: Currently only somewhat tested with LPC1347. This should be concidered a proof of concept. Ideally this would
+ * be merged into the original I2CSlave library.
+ *
  * Example:
  * @code
- * TBD EXAMPLE
+ * // Simple Simulated I2C Read-Only EEPROM
+ * #include <mbed.h>
+ * #include "I2CSlaveX.h"
+ * 
+ * I2CSlaveX slave(p9, p10);
+ * 
+ * uint8_t eeprom_data[16] = {0);
+ * uint8_t eeprom_addr = 0;
+ * 
+ * void receive_handler() {
+ *     char addr;
+ *     int i = slave.receive(&addr);
+ *     switch (i) {
+ *         case I2CSlave::ReadAddressed:
+ *             slave.write(&eeprom_data[eeprom_addr], 1);
+ *             printf("Write @ %02X [%02X] : %02X\n", addr, eeprom_addr, eeprom_data[eeprom_addr]);
+ *             break;
+ *         case I2CSlave::WriteAddressed:
+ *             slave.read(&eeprom_addr, 1);
+ *             printf("Read  @ %02X [%02X]\n", addr, eeprom_addr);
+ *             break;
+ *     }
+ * }
+ * 
+ * int main() {
+ *     slave.address(0xA0, 0);
+ *     slave.address(0x30, 1);
+ *     slave.attach(&receive_handler);
+ *     
+ *     while(1) {
+ *         printf("Nothing to do really...");
+ *         eeprom_data[0]++;
+ *         wait(1);
+ *     }
+ * }
  * @endcode
  */ 
 class I2CSlaveX : public I2CSlave