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
src/application.cpp@11:b3929de96933, 2016-02-19 (annotated)
- Committer:
- stormysun513
- Date:
- Fri Feb 19 10:27:54 2016 +0000
- Revision:
- 11:b3929de96933
I2C LEDs workable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stormysun513 | 11:b3929de96933 | 1 | #include "application.h" |
stormysun513 | 11:b3929de96933 | 2 | #include "mbed.h" |
stormysun513 | 11:b3929de96933 | 3 | |
stormysun513 | 11:b3929de96933 | 4 | extern Serial pc; |
stormysun513 | 11:b3929de96933 | 5 | |
stormysun513 | 11:b3929de96933 | 6 | float readTMP102Temperature(I2C& i2c, char* reg) { |
stormysun513 | 11:b3929de96933 | 7 | const char regAddr = TMP102_TEMP_REG_ADDR; |
stormysun513 | 11:b3929de96933 | 8 | i2c.write(TMP102_ADDR, ®Addr, 1); |
stormysun513 | 11:b3929de96933 | 9 | int result = i2c.read(TMP102_ADDR, reg, 2); |
stormysun513 | 11:b3929de96933 | 10 | if (result != 0) |
stormysun513 | 11:b3929de96933 | 11 | return -1; |
stormysun513 | 11:b3929de96933 | 12 | |
stormysun513 | 11:b3929de96933 | 13 | int TemperatureSum = (reg[0] << 8 | reg[1]) >> 4; |
stormysun513 | 11:b3929de96933 | 14 | return (float)TemperatureSum*0.0625; |
stormysun513 | 11:b3929de96933 | 15 | } |
stormysun513 | 11:b3929de96933 | 16 | |
stormysun513 | 11:b3929de96933 | 17 | /* AT24C64D */ |
stormysun513 | 11:b3929de96933 | 18 | bool writeAT24EEPROMBuffer(I2C& i2c, uint8_t dataAddr, char* buf, uint16_t length){ |
stormysun513 | 11:b3929de96933 | 19 | uint8_t tmpBuf[10] = {0,}; |
stormysun513 | 11:b3929de96933 | 20 | tmpBuf[0] = dataAddr; |
stormysun513 | 11:b3929de96933 | 21 | if(length > 9) |
stormysun513 | 11:b3929de96933 | 22 | length = 9; |
stormysun513 | 11:b3929de96933 | 23 | |
stormysun513 | 11:b3929de96933 | 24 | for(int i = 1; i < (length+1); i++) |
stormysun513 | 11:b3929de96933 | 25 | tmpBuf[i] = buf[i-1]; |
stormysun513 | 11:b3929de96933 | 26 | |
stormysun513 | 11:b3929de96933 | 27 | int result = i2c.write(EEPROM_ADDR, (char*)tmpBuf, length+1); |
stormysun513 | 11:b3929de96933 | 28 | if (result != 0) |
stormysun513 | 11:b3929de96933 | 29 | return false; |
stormysun513 | 11:b3929de96933 | 30 | else |
stormysun513 | 11:b3929de96933 | 31 | return true; |
stormysun513 | 11:b3929de96933 | 32 | } |
stormysun513 | 11:b3929de96933 | 33 | |
stormysun513 | 11:b3929de96933 | 34 | bool readAT24EEPROMBuffer(I2C& i2c, uint8_t dataAddr, char* buf, uint16_t length){ |
stormysun513 | 11:b3929de96933 | 35 | int result = i2c.write(EEPROM_ADDR, (char*)&dataAddr, 1); |
stormysun513 | 11:b3929de96933 | 36 | if (result != 0) |
stormysun513 | 11:b3929de96933 | 37 | return false; |
stormysun513 | 11:b3929de96933 | 38 | |
stormysun513 | 11:b3929de96933 | 39 | result = i2c.read(EEPROM_ADDR, buf, length); |
stormysun513 | 11:b3929de96933 | 40 | if (result != 0) |
stormysun513 | 11:b3929de96933 | 41 | return false; |
stormysun513 | 11:b3929de96933 | 42 | |
stormysun513 | 11:b3929de96933 | 43 | return true; |
stormysun513 | 11:b3929de96933 | 44 | } |