example of i2c slave device supporting block transfers

Dependencies:   lib_i2c_slave_block

Tested on nucleo board as slave. Use with i2c_master_block_example on raspberry pi as master.

Master I2C write will print on serial terminal 115200. User button will raise an irq; the RPi test program will service the interrupt.

See lib_i2c_slave_block for explanation of code.

Revision:
3:0288d257446a
Parent:
2:d7e05c75f240
--- a/main.cpp	Mon Jan 21 18:09:05 2019 -0800
+++ b/main.cpp	Sun Feb 03 16:56:15 2019 -0800
@@ -1,7 +1,6 @@
 
 #include <mbed.h>
 #include "smbus.h"
-#include "cmds.h"
 
 #define IRQ_OUT_PIN     D6
 
@@ -70,6 +69,16 @@
         case CMD_BUFFER:
             memcpy(test_buf, req, sizeof(test_buf));
             break;
+        /* failures: */
+        case CMD_BUSERR:
+            pc.printf("BUSERR%u\r\n", req[0]);
+            break;
+        case CMD_ARLO:
+            pc.printf("ARLO%u\r\n", req[0]); // req[0] tx_cndtr
+            break;
+        case CMD_TIMEOUT:
+            pc.printf("TIMEOUT%u\r\n", req[0]);    // req[0] tx_cndtr
+            break;
         default:
             pc.printf("??%02x??\r\n", cmd);
             break;
@@ -85,7 +94,7 @@
     pc.baud(115200);
     pc.printf("\r\nreset\r\n");
 
-    res = smbus_init(SLAVE_ADDRESS);
+    res = smbus_init(I2C_SDA, I2C_SCL, SLAVE_ADDRESS);
     pc.printf("%d = smbus_init()\r\n", res);
 
     but = button.read();