nRF51822 serves as the bridge between BLE central and MCU, which makes cental able to fetch photos from serial camera.

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_blinky by RedBearLab

Committer:
stormysun513
Date:
Fri Feb 19 09:23:56 2016 +0000
Revision:
9:d44d16ffd48c
commit for upgrade library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stormysun513 9:d44d16ffd48c 1 #include "application.h"
stormysun513 9:d44d16ffd48c 2 #include "mbed.h"
stormysun513 9:d44d16ffd48c 3
stormysun513 9:d44d16ffd48c 4 extern Serial pc;
stormysun513 9:d44d16ffd48c 5
stormysun513 9:d44d16ffd48c 6 float readTMP102Temperature(I2C& i2c, char* reg) {
stormysun513 9:d44d16ffd48c 7 const char regAddr = TMP102_TEMP_REG_ADDR;
stormysun513 9:d44d16ffd48c 8 int result = i2c.write(TMP102_ADDR, &regAddr, 1);
stormysun513 9:d44d16ffd48c 9 if (result != 0)
stormysun513 9:d44d16ffd48c 10 return -1;
stormysun513 9:d44d16ffd48c 11
stormysun513 9:d44d16ffd48c 12 result = i2c.read(TMP102_ADDR, reg, 2);
stormysun513 9:d44d16ffd48c 13 if (result != 0)
stormysun513 9:d44d16ffd48c 14 return -1;
stormysun513 9:d44d16ffd48c 15
stormysun513 9:d44d16ffd48c 16 int TemperatureSum = (reg[0] << 8 | reg[1]) >> 4;
stormysun513 9:d44d16ffd48c 17 return (float)TemperatureSum*0.0625;
stormysun513 9:d44d16ffd48c 18 }
stormysun513 9:d44d16ffd48c 19
stormysun513 9:d44d16ffd48c 20 /* AT24C64D */
stormysun513 9:d44d16ffd48c 21 bool writeAT24EEPROMBuffer(I2C& i2c, uint8_t dataAddr, char* buf, uint16_t length){
stormysun513 9:d44d16ffd48c 22 uint8_t tmpBuf[10] = {0,};
stormysun513 9:d44d16ffd48c 23 tmpBuf[0] = dataAddr;
stormysun513 9:d44d16ffd48c 24 if(length > 9)
stormysun513 9:d44d16ffd48c 25 length = 9;
stormysun513 9:d44d16ffd48c 26
stormysun513 9:d44d16ffd48c 27 for(int i = 1; i < (length+1); i++)
stormysun513 9:d44d16ffd48c 28 tmpBuf[i] = buf[i-1];
stormysun513 9:d44d16ffd48c 29
stormysun513 9:d44d16ffd48c 30 int result = i2c.write(EEPROM_ADDR, (char*)tmpBuf, length+1);
stormysun513 9:d44d16ffd48c 31 if (result != 0)
stormysun513 9:d44d16ffd48c 32 return false;
stormysun513 9:d44d16ffd48c 33 else
stormysun513 9:d44d16ffd48c 34 return true;
stormysun513 9:d44d16ffd48c 35 }
stormysun513 9:d44d16ffd48c 36
stormysun513 9:d44d16ffd48c 37 bool readAT24EEPROMBuffer(I2C& i2c, uint8_t dataAddr, char* buf, uint16_t length){
stormysun513 9:d44d16ffd48c 38 int result = i2c.write(EEPROM_ADDR, (char*)&dataAddr, 1);
stormysun513 9:d44d16ffd48c 39 if (result != 0)
stormysun513 9:d44d16ffd48c 40 return false;
stormysun513 9:d44d16ffd48c 41
stormysun513 9:d44d16ffd48c 42 result = i2c.read(EEPROM_ADDR, buf, length);
stormysun513 9:d44d16ffd48c 43 if (result != 0)
stormysun513 9:d44d16ffd48c 44 return false;
stormysun513 9:d44d16ffd48c 45
stormysun513 9:d44d16ffd48c 46 return true;
stormysun513 9:d44d16ffd48c 47 }