
Simple Test Program to check ACK from i2c Devices connected to an MBED board and then to report their addresses
Revision 1:df2444f34fec, committed 2021-02-15
- Comitter:
- martinsimpson
- Date:
- Mon Feb 15 17:20:16 2021 +0000
- Parent:
- 0:2db41a0c2f17
- Commit message:
- Removed lcd and Serial class references
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 |
diff -r 2db41a0c2f17 -r df2444f34fec main.cpp --- a/main.cpp Tue Jan 13 15:48:33 2015 +0000 +++ b/main.cpp Mon Feb 15 17:20:16 2021 +0000 @@ -1,5 +1,4 @@ #include "mbed.h" -#include "TextLCD.h" #define Device_Name_ADDR (0xEE) // Device You Wish to Use Address - using i2c Address #define WRITE (0x00) // i2c Write bit @@ -16,26 +15,18 @@ I2C i2c(I2C_SDA, I2C_SCL); //I2C Class Pin Assignments see I2C.h -Serial pc(SERIAL_TX, SERIAL_RX); //Serial Class Pin Assignments see Serial.h - -TextLCD lcd(D2,D3,D4,D5,D6,D7); //Text LCD Class assignments RS, E, D4 to D7 see TextLCD.h - -char ucdata_write[2]; -short count=0; - int main() { - unsigned int uibaudrate=115200; - pc.baud(uibaudrate); + + char ucdata_write[2]; + short count=0; unsigned int uifrequency=400000; //400KHz for i2c Max i2c.frequency (uifrequency); - pc.printf("\n\rHello World "); - pc.printf("at %u BAUD and %uKHz i2c Frequency\n\r",uibaudrate,uifrequency/1000); - pc.printf("Using mbed.org Martin\n\r"); - - lcd.cls();lcd.locate(0,0); //Tidy up LCD Display + printf("\n\rHello World "); + printf("at %uKHz i2c Frequency\n\r",uifrequency/1000); + printf("Using mbed.org Martin\n\r"); ucdata_write[0]=0;ucdata_write[1]=0; @@ -43,9 +34,8 @@ { if (!i2c.write((Device_Adress|WRITE), ucdata_write, 1, 0))// Check for ACK from i2c Device NB I am 'ORing' the Write Bit { - pc.printf("ACK from the Device at Address %#4x\n\r",Device_Adress); - lcd.printf("ACK at:%#4x\n",Device_Adress); - count=count+1; + printf("ACK from the Device at Address %#4x\n\r",Device_Adress); + count++; wait(2); } else @@ -55,6 +45,5 @@ //lcd.printf("No ACK from\nDevice!"); } } - pc.printf("\n\r %d Devices have been detected!\n\r",count); - lcd.printf("%d Dev Found!",count); + printf("\n\r %d Devices have been detected!\n\r",count); }
diff -r 2db41a0c2f17 -r df2444f34fec mbed.bld --- a/mbed.bld Tue Jan 13 15:48:33 2015 +0000 +++ b/mbed.bld Mon Feb 15 17:20:16 2021 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file