base program for tilt measurement
Dependencies: COG4050_ADT7420 ADXL362
Fork of COG4050_adxl355_adxl357-ver2 by
Revision 0:74a0756399ff, committed 2018-06-05
- Comitter:
- APS_Lab
- Date:
- Tue Jun 05 13:03:07 2018 +0000
- Child:
- 1:d3aeaa02781d
- Commit message:
- I2C&??????ADT7420
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Tue Jun 05 13:03:07 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Tue Jun 05 13:03:07 2018 +0000 @@ -0,0 +1,57 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Troubleshooting + +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Jun 05 13:03:07 2018 +0000
@@ -0,0 +1,97 @@
+#include "mbed.h"
+
+#define ADT7420 0x48
+
+#define RESET_REG 0x2F
+#define TEMP_REG 0x00
+#define ID_REG 0x0B
+
+
+DigitalOut led1(LED1);
+DigitalOut sensor(D8);
+
+I2C Myi2c(I2C_SDA, I2C_SCL);
+
+Serial pc(USBTX, USBRX);
+
+void ADT7420_reset(void);
+int ADT7420_GetID(void);
+int ADT7420_GetTemp(void);
+
+// main() runs in its own thread in the OS
+int main() {
+ float status;
+ int res;
+ sensor=1;
+ //configure for UART
+ pc.baud(115200);
+ pc.printf("I2C ADT7420 Demo\n");
+
+ //configure for I2C @400KHz
+ Myi2c.frequency(100000);
+
+ //configure for ADT7420
+
+ pc.printf("[RESET ] ADT7420\n");
+ ADT7420_reset();
+ wait(0.5);
+
+ pc.printf("[CHECK ID] ADT7420\n");
+ ADT7420_GetID();
+
+
+ while (true) {
+ led1 = 0;
+
+ pc.printf("[Get Temp] ADT7420\n");
+ res = ADT7420_GetTemp();
+
+ if(res & 0x1000)
+ {
+ status = (float)((res - 8192) / 16);
+ }
+ else
+ {
+ status = (float)(res / 16);
+ }
+
+ pc.printf("Current Temp %.0f \n", status);
+
+ wait(0.5);
+ led1 = 1;
+ wait(0.5);
+ }
+
+}
+
+void ADT7420_reset(void)
+{
+ char cmd_reset[1];
+ cmd_reset[0] = RESET_REG;
+ Myi2c.write(ADT7420, cmd_reset, 1);
+}
+
+int ADT7420_GetID(void)
+{
+ char cmd_id[1], read_val;
+ cmd_id[0]=ID_REG;
+ Myi2c.write(ADT7420, cmd_id, 1, 1);
+ Myi2c.read(ADT7420, &read_val, 1);
+ pc.printf("ID %02x\n", read_val);
+ return read_val;
+}
+
+int ADT7420_GetTemp(void)
+{
+ char cmd_temp[1], read_val[2];
+ int temp=0;
+ cmd_temp[0]=TEMP_REG;
+ Myi2c.write(ADT7420, cmd_temp, 1, 1);
+ Myi2c.read(ADT7420, read_val, 2);
+ pc.printf("Temp Upper %02x\n", read_val[0]);
+ pc.printf("Temp Lower %02x\n", read_val[1]);
+
+ temp = (int)((read_val[0] << 8) | read_val[1]);
+ temp >>= 3;
+ return temp;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Tue Jun 05 13:03:07 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#c26126ee5951b70703989c844c4d0bc8f498049b
