5803 Project 2 / Mbed 2 deprecated I2C

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
gabinader
Date:
Mon Mar 12 12:36:53 2018 +0000
Child:
1:e3aa5dc929c0
Commit message:
temp sensor

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib 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
pindef.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Mon Mar 12 12:36:53 2018 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Mon Mar 12 12:36:53 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	Mon Mar 12 12:36:53 2018 +0000
@@ -0,0 +1,59 @@
+/*----------------------------------------------------------------------------
+LAB EXERCISE 11.3 - I2C interface
+SERIAL COMMUNICATION
+ ----------------------------------------
+    Access the virtual temperature sensor via I2C interface, print the current temperature
+    to the PC via UART
+    
+    Input: temperature sensor
+    Output: PC
+    
+    GOOD LUCK!
+ *----------------------------------------------------------------------------*/
+#include "mbed.h"
+#include "pindef.h"
+
+//I2C interface
+I2C temp_sensor(I2C_SDA, I2C_SCL);
+Serial pc(UART_TX, UART_RX);
+
+//I2C address of temperature sensor DS1631
+const int temp_addr = 0x90;
+
+char cmd[] = {0x51, 0xAA};
+char read_temp[2];
+
+/*----------------------------------------------------------------------------
+ MAIN function
+ *----------------------------------------------------------------------------*/
+
+int main(){
+    while(1){
+        /*
+        Write the Start Convert T command to the sensor
+        Write the Read Temperature command to the sensor
+        Read the 16-bit temperature data
+        */
+        
+        //Write your code here
+        
+        int status = temp_sensor.write(temp_addr, cmd, 1, 0);
+        temp_sensor.read(temp_addr,read_temp,2,false);
+        
+       
+        printf(" array read 1  %x \r\n", read_temp[0]);
+        printf(" array read 2  %x \r\n", read_temp[1]);
+        
+        //Convert temperature to Celsius
+        float temp = (float((read_temp[0] << 8) | read_temp[1]) / 256);
+        
+        //Print temperature to the serial monitor
+        
+        //Write your code here
+        pc.printf(" Temperature reading is: %f Celsius \r\n", temp );
+        
+        
+    }
+}
+
+// *******************************ARM University Program Copyright (c) ARM Ltd 2014*************************************
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Mon Mar 12 12:36:53 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#91e6db1ea251ffcc973001ed90477f42fdca5751
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 12 12:36:53 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/aa5281ff4a02
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pindef.h	Mon Mar 12 12:36:53 2018 +0000
@@ -0,0 +1,57 @@
+/*----------------------------------------------------------------------------
+ Pin definitions
+ *----------------------------------------------------------------------------*/
+
+#ifndef PINDEF_H
+#define PINDEF_H
+ 
+//Define pins below
+
+//Digital input pins
+#define Din0 PA_10
+#define Din1 PB_3
+#define Din2 PB_5
+#define Din3 PB_4
+
+//Digital output pins
+#define Dout0 PB_10
+#define Dout1 PA_8
+#define Dout2 PA_9
+#define Dout3 PC_7
+
+//Analog input pins
+#define Ain0 PA_0
+#define Ain1 PA_1
+#define Ain2 PA_4
+#define Ain3 PB_0
+#define Ain4 PC_1
+#define Ain5 PC_0
+
+//Analog output pins
+#define Aout0
+#define Aout1
+#define Aout2
+#define Aout3
+#define Aout4
+#define Aout5
+
+//Communication pins
+#define I2C_SCL PB_8
+#define I2C_SDA PB_9
+
+#define SPI_MOSI PA_7
+#define SPI_MISO PA_6
+#define SPI_SCLK PA_5
+#define SPI_CS PB_6
+
+#define UART_TX PA_2
+#define UART_RX PA_3
+
+//If any on board RGB LEDs are present:
+#define LED_r PB_10
+#define LED_g PA_8
+#define LED_b PA_9
+
+#endif
+ 
+// *******************************ARM University Program Copyright © ARM Ltd 2014*************************************