Configura kl25z en modo esclavo i2c, para recibir comandos de la Raspsberry Pi en modo Maestro

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
franni
Date:
Fri Oct 12 01:46:57 2018 +0000
Commit message:
KL25Z i2c Slave to Raspberry Pi Master

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 12 01:46:57 2018 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+
+DigitalOut led(LED1);
+Serial pc(USBTX, USBRX); // tx, rx
+I2CSlave slave(PTC9,PTC8); // SDA, SCL
+
+const int SLAVE_ADDRESS = 0x0A;
+const int I2C_FREQUENCY = 100000;
+// const int I2C_BUFFER_SIZE = 6;
+
+
+int main() {
+    pc.baud(9600);
+    
+    // Configure I2C
+    slave.frequency(I2C_FREQUENCY);
+    pc.printf("Frecuencia I2C Slave @ %dHz\r\n", I2C_FREQUENCY);
+    slave.address(SLAVE_ADDRESS);
+    pc.printf("Direccion Slave @ SLAVE_ADDRESS = 0x%x\r\n", SLAVE_ADDRESS);
+
+    // I2C buffer
+    // char buffer[I2C_BUFFER_SIZE];
+       
+    while (1) {
+        int rec = slave.receive();
+        pc.printf("Dato recibido %d\r\n", rec); 
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 12 01:46:57 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file