Writes and reads test values, displaying results on MBED LEDS

Dependencies:   mbed

Fork of I2C_HelloWorld_Mbed by mbed official

Committer:
oliverb
Date:
Fri Sep 16 09:08:25 2016 +0000
Revision:
1:494c4f7f60db
Parent:
0:f76c26307f9a
Tested with a PIC18F4520 acting as peripheral (slave), test displays 4 bits on LEDs, writes to PIC, waits 0.5s, reads value and displays then waits 0.5s.; Success=non flashing, fail=leds flash sent value-red value

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:f76c26307f9a 1 #include "mbed.h"
mbed_official 0:f76c26307f9a 2
mbed_official 0:f76c26307f9a 3
mbed_official 0:f76c26307f9a 4 I2C i2c(p28, p27);
oliverb 1:494c4f7f60db 5 BusOut myleds(LED1, LED2, LED3, LED4);
mbed_official 0:f76c26307f9a 6
oliverb 1:494c4f7f60db 7
oliverb 1:494c4f7f60db 8 const int addr = 0xAA;
mbed_official 0:f76c26307f9a 9
mbed_official 0:f76c26307f9a 10 int main() {
oliverb 1:494c4f7f60db 11 i2c.frequency(100000);
oliverb 1:494c4f7f60db 12 while (1) {
oliverb 1:494c4f7f60db 13 for(int aa=0;aa<16;aa++)
oliverb 1:494c4f7f60db 14 {
oliverb 1:494c4f7f60db 15 myleds=aa;
oliverb 1:494c4f7f60db 16 char cmd[2];
oliverb 1:494c4f7f60db 17 cmd[0] = 0x00;
oliverb 1:494c4f7f60db 18 cmd[1] = aa;
mbed_official 0:f76c26307f9a 19 i2c.write(addr, cmd, 2);
mbed_official 0:f76c26307f9a 20
mbed_official 0:f76c26307f9a 21 wait(0.5);
mbed_official 0:f76c26307f9a 22
mbed_official 0:f76c26307f9a 23 cmd[0] = 0x00;
oliverb 1:494c4f7f60db 24 i2c.write(addr, cmd, 1,true);
oliverb 1:494c4f7f60db 25 i2c.read(addr, cmd, 1);
oliverb 1:494c4f7f60db 26 myleds=cmd[0];
oliverb 1:494c4f7f60db 27 wait(0.5);
mbed_official 0:f76c26307f9a 28 }
oliverb 1:494c4f7f60db 29 }
mbed_official 0:f76c26307f9a 30 }