Sensor I2C Coragem

Files at this revision

API Documentation at this revision

Comitter:
brunnobbco
Date:
Mon Jun 29 20:36:27 2020 +0000
Commit message:
Sensor I2C Coragem

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
mbed_coragem.lib 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	Mon Jun 29 20:36:27 2020 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+ 
+//#define ADDR    (0x6D<<1)
+ 
+Serial pc(p25, p8); // tx, rx
+DigitalOut ADR(P0_12);
+ 
+I2C i2c(p13, p15);
+
+
+char buffer[2];
+uint16_t aux;
+ 
+int main()
+{
+    ADR=1;
+    char sco_bit;
+    i2c.frequency(100000);
+    
+    const int addr = 0x6d << 1;
+    char readdata[3];
+    
+    while(1)
+    {
+        int ret, value, value1, value2;
+        sco_bit = 1;
+        pc.printf("Lendo valor em registrador 0xA5…\r\n");
+        
+        buffer[0] = 0xA5;
+        
+        //ret = i2c.write((addr << 1) & 0xFE);
+        ret = i2c.write(addr, buffer, 1);
+        
+        if (!ret) // 0:ACK 1:NACK
+        {
+            ret = i2c.read(addr, readdata, 3);
+
+            if (ret)
+                pc.printf("Erro B %d.\r\n", ret);
+        }
+        else
+            pc.printf("Erro A %d.\r\n", ret);
+
+        if (!ret)
+        {
+            buffer[0] = 0xA5;
+            buffer[1] = readdata[0] & 0x07;
+            buffer[2] = readdata[1] & 0x0f;
+            buffer[3] = readdata[2] & 0x0d;
+            ret = i2c.write(addr, buffer, 4);
+
+            if (ret == 0) // 0:ACK 1:NACK
+            {
+                buffer[0] = 0x30;
+                buffer[1] = 0x0A;
+                i2c.write(addr, buffer, 2);
+                i2c.read(addr, sco_bit, 1);
+                
+                if (!sco_bit)
+                {
+                    buffer[0] = 0x06;
+                    i2c.write(addr, buffer, 1);
+                    i2c.read(addr, readdata[0], 3);
+                    buffer[0] = 0x07;
+                    i2c.write(addr, buffer, 1);
+                    i2c.read(addr, readdata[1], 3);                 
+                    buffer[0] = 0x08;
+                    i2c.write(addr, buffer, 1);
+                    i2c.read(addr, readdata[2], 3);
+                    
+                    pc.printf("Valor lido: %d\n", readdata);
+                }
+            }
+            else
+                pc.printf("Erro C %d.\r\n", ret);
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Mon Jun 29 20:36:27 2020 +0000
@@ -0,0 +1,35 @@
+{  
+    
+    "target_overrides": {
+        "K64F": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"]
+        },
+        "NUCLEO_F401RE": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"]
+        },
+        "DISCO_L475VG_IOT01A": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_BLUENRG"]
+        },
+        "NRF52840_DK": {
+            "platform.stdio-baud-rate": 115200,
+            "platform.default-serial-baud-rate": 115200,
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_LL", "SOFTDEVICE_N ONE", "NORDIC_CORDIO"],
+            "target.extra_labels_remove": ["SOFTDEVICE_COMMON", "SOFTDEVICE_S140_FULL", "NORDIC_SOFTDEVICE"],           
+            "target.lf_clock_src": "NRF_LF_SRC_RC",
+            "target.lf_clock_rc_calib_timer_interval": 16,
+            "target.lf_clock_rc_calib_mode_config": 2
+
+
+            
+        },
+        "NRF52_DK": {
+            "target.features_add": ["BLE"],
+            "target.extra_labels_add": ["CORDIO", "CORDIO_LL", "SOFTDEVICE_NONE", "NORDIC_CORDIO"],
+            "target.extra_labels_remove": ["SOFTDEVICE_COMMON", "SOFTDEVICE_S132_FULL", "NORDIC_SOFTDEVICE"]
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_coragem.lib	Mon Jun 29 20:36:27 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/leiachewbacca/mbed_coragem.git/#b8dad0652c9cd2321126a590280a18a964e1eed0