adress_I2C

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
henriquer
Date:
Wed Nov 16 14:17:26 2022 +0000
Commit message:
teste i2c

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	Wed Nov 16 14:17:26 2022 +0000
@@ -0,0 +1,24 @@
+#include "mbed.h"
+
+I2C i2c(I2C_SDA, I2C_SCL); 
+
+int main(){
+    printf("\nI2C Scanner running...\n");
+    //i2c.frequency(400000);
+    int error, address, nDevices;
+    nDevices = 0;
+    for(address = 0; address < 128; address++ ){
+        thread_sleep_for(10);
+        error = i2c.write(address  << 1, "1", 1);
+
+        if (error == 0){
+            printf("I2C device found at address 8bit: 0x%X 7bit: 0x%X\n", address, address << 1);
+            nDevices++;
+        }
+    }
+    if (nDevices == 0){
+        printf("No I2C devices found\n");
+    }else{
+        printf("\ndone\n");
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 16 14:17:26 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file