Frank Girald
/
i2cslaveToRasbPi
Configura kl25z en modo esclavo i2c, para recibir comandos de la Raspsberry Pi en modo Maestro
Diff: main.cpp
- Revision:
- 0:b16fccf97adb
diff -r 000000000000 -r b16fccf97adb main.cpp --- /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