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 10:27:54 2016 +0000
Revision:
11:b3929de96933
Parent:
main.cpp@10:9e24f9f4ac47
Child:
12:7060e287bdae
I2C LEDs workable

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan 0:7dec7e9ac085 1 #include "mbed.h"
stormysun513 11:b3929de96933 2 #include "application.h"
stormysun513 11:b3929de96933 3
stormysun513 11:b3929de96933 4 #define UART_BAUDRATE 14400
stormysun513 11:b3929de96933 5 #define MINIMUM_TICKER_PERIOD 2500
stormysun513 11:b3929de96933 6 #define BLE_BUF_LEN 20
dan 0:7dec7e9ac085 7
stormysun513 11:b3929de96933 8 void timerPeriodicalCB(void);
stormysun513 11:b3929de96933 9 void timerFlashLed(void);
stormysun513 11:b3929de96933 10 void timerRoutineTask(void);
stormysun513 11:b3929de96933 11
stormysun513 11:b3929de96933 12 Ticker ticker;
stormysun513 11:b3929de96933 13 I2C i2c(P0_8, P0_9); //P0_29, P0_15 // P0_8, P0_9
stormysun513 11:b3929de96933 14 DigitalOut powerLED(P0_11); //P0_19, LED1 // P0_10
stormysun513 11:b3929de96933 15 DigitalOut insertedLED(P0_10); //P0_28
stormysun513 11:b3929de96933 16 DigitalOut debug(P0_12);
stormysun513 11:b3929de96933 17
stormysun513 11:b3929de96933 18 //Serial pc(P0_18, P0_17); //P0_9, P0_11(USBTX, USBRX), modified to P0_7, P0_11 // P0_18, P0_17
stormysun513 11:b3929de96933 19
stormysun513 11:b3929de96933 20 static bool timerRoutine = false;
dan 0:7dec7e9ac085 21
RedBearLab 10:9e24f9f4ac47 22 int main()
RedBearLab 10:9e24f9f4ac47 23 {
stormysun513 11:b3929de96933 24 ticker.attach_us(timerPeriodicalCB, MINIMUM_TICKER_PERIOD);
stormysun513 11:b3929de96933 25
stormysun513 11:b3929de96933 26 while(true){
stormysun513 11:b3929de96933 27 if(timerRoutine){
stormysun513 11:b3929de96933 28 timerRoutine = false;
stormysun513 11:b3929de96933 29 timerRoutineTask();
stormysun513 11:b3929de96933 30 }
stormysun513 11:b3929de96933 31 deepsleep();
stevep 4:81cea7a352b0 32 }
dan 0:7dec7e9ac085 33 }
stormysun513 11:b3929de96933 34
stormysun513 11:b3929de96933 35 void timerPeriodicalCB(void){
stormysun513 11:b3929de96933 36 static uint32_t time = 0;
stormysun513 11:b3929de96933 37 time++;
stormysun513 11:b3929de96933 38
stormysun513 11:b3929de96933 39 if ( time % 100 == 2 ) { // 250ms
stormysun513 11:b3929de96933 40 // if(buttonState == BTN_CHECK_LONG_PRESS)
stormysun513 11:b3929de96933 41 // checkButtonCounter++;
stormysun513 11:b3929de96933 42 }
stormysun513 11:b3929de96933 43
stormysun513 11:b3929de96933 44
stormysun513 11:b3929de96933 45 if ( time % 200 == 3 ) { // 500ms
stormysun513 11:b3929de96933 46 timerFlashLed();
stormysun513 11:b3929de96933 47 }
stormysun513 11:b3929de96933 48
stormysun513 11:b3929de96933 49 if ( time % 400 == 4 ) { // 1s
stormysun513 11:b3929de96933 50 timerRoutine = true;
stormysun513 11:b3929de96933 51 }
stormysun513 11:b3929de96933 52 }
stormysun513 11:b3929de96933 53
stormysun513 11:b3929de96933 54 void timerFlashLed(void){
stormysun513 11:b3929de96933 55 powerLED = !powerLED;
stormysun513 11:b3929de96933 56 }
stormysun513 11:b3929de96933 57
stormysun513 11:b3929de96933 58 void timerRoutineTask(void){
stormysun513 11:b3929de96933 59 uint8_t buf[BLE_BUF_LEN] = {0,};
stormysun513 11:b3929de96933 60
stormysun513 11:b3929de96933 61 debug = 1;
stormysun513 11:b3929de96933 62 bool result = readAT24EEPROMBuffer(i2c, 0, (char*)buf+1, 2);
stormysun513 11:b3929de96933 63 debug = 0;
stormysun513 11:b3929de96933 64
stormysun513 11:b3929de96933 65 if(result == false){
stormysun513 11:b3929de96933 66 insertedLED = 1;
stormysun513 11:b3929de96933 67 buf[1] = 0xFF;
stormysun513 11:b3929de96933 68 buf[2] = 0xFF;
stormysun513 11:b3929de96933 69 }
stormysun513 11:b3929de96933 70 else{
stormysun513 11:b3929de96933 71 insertedLED = 0;
stormysun513 11:b3929de96933 72 }
stormysun513 11:b3929de96933 73 }