I2C boot loader

Dependencies:   mbed

Fork of I2C_HelloWorld_Mbed by mbed official

Committer:
mbedAustin
Date:
Fri Mar 27 20:14:09 2015 +0000
Revision:
4:df6232c70efd
Parent:
3:ab0e4b55d7da
Added license to main.c file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 4:df6232c70efd 1 /* mbed Example Program
mbedAustin 4:df6232c70efd 2 * Copyright (c) 2006-2014 ARM Limited
mbedAustin 4:df6232c70efd 3 *
mbedAustin 4:df6232c70efd 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbedAustin 4:df6232c70efd 5 * you may not use this file except in compliance with the License.
mbedAustin 4:df6232c70efd 6 * You may obtain a copy of the License at
mbedAustin 4:df6232c70efd 7 *
mbedAustin 4:df6232c70efd 8 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 4:df6232c70efd 9 *
mbedAustin 4:df6232c70efd 10 * Unless required by applicable law or agreed to in writing, software
mbedAustin 4:df6232c70efd 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbedAustin 4:df6232c70efd 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 4:df6232c70efd 13 * See the License for the specific language governing permissions and
mbedAustin 4:df6232c70efd 14 * limitations under the License.
mbedAustin 4:df6232c70efd 15 */
mbed_official 0:f76c26307f9a 16 #include "mbed.h"
mbed_official 0:f76c26307f9a 17
mbed_official 0:f76c26307f9a 18 // Read temperature from LM75BD
mbed_official 0:f76c26307f9a 19
mbedAustin 3:ab0e4b55d7da 20 I2C i2c(I2C_SDA , I2C_SCL );
mbed_official 0:f76c26307f9a 21
mbedAustin 3:ab0e4b55d7da 22 const int addr7bit = 0x48; // 7 bit I2C address
mbedAustin 3:ab0e4b55d7da 23 const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90
mbed_official 0:f76c26307f9a 24
mbed_official 0:f76c26307f9a 25 int main() {
mbed_official 0:f76c26307f9a 26 char cmd[2];
mbed_official 0:f76c26307f9a 27 while (1) {
mbed_official 0:f76c26307f9a 28 cmd[0] = 0x01;
mbed_official 0:f76c26307f9a 29 cmd[1] = 0x00;
mbedAustin 3:ab0e4b55d7da 30 i2c.write(addr8bit, cmd, 2);
mbed_official 0:f76c26307f9a 31
mbed_official 0:f76c26307f9a 32 wait(0.5);
mbed_official 0:f76c26307f9a 33
mbed_official 0:f76c26307f9a 34 cmd[0] = 0x00;
mbedAustin 3:ab0e4b55d7da 35 i2c.write(addr8bit, cmd, 1);
mbedAustin 3:ab0e4b55d7da 36 i2c.read( addr8bit, cmd, 2);
mbed_official 0:f76c26307f9a 37
mbed_official 0:f76c26307f9a 38 float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
mbed_official 0:f76c26307f9a 39 printf("Temp = %.2f\n", tmp);
mbed_official 0:f76c26307f9a 40 }
mbed_official 0:f76c26307f9a 41 }