Firmware for the mbed in the BlueSync Sensor platform. Intended to communicate with a BlueGiga BLE112 Bluetooth LE module over UART.

Dependencies:   TimerCapture mbed

Revision:
5:fd4773c12f93
Parent:
4:778626dfcc92
Child:
6:51884d3fd44d
--- a/main.cpp	Sat May 30 05:27:26 2015 +0000
+++ b/main.cpp	Thu Jun 11 20:06:51 2015 +0000
@@ -7,11 +7,13 @@
 
 Serial ble112(p9, p10); ///< Serial connection for communicating with the BLE112.
 TimerCapture * capPin; ///< Capture pin, wired to GPIO pin on BLE112.
+TimerCapture * evtPin; 
 DigitalOut bleSlaveLed(LED1);
 DigitalOut bleScanningLed(LED2);
 DigitalOut bleAdvRecv(LED3);
 DigitalOut bleTimeStampRecv(LED4);
 Ticker ticker;
+InterruptIn evtWatchPin(p28);
 
 void blankOutLeds() {
     bleSlaveLed = 0;
@@ -83,6 +85,16 @@
     LPC_TIM2->TC += bitArray.signed_integer;
 }
 
+void on_interrupt_recv() {
+    uint8_t event = (uint8_t) EventCode::SET_SENSOR_TIME;
+    intByteArray bitArray;
+    bitArray.integer = evtPin->getTime();
+    printf("Sending sensor time %d (%08x)\r\n", bitArray.integer, bitArray.integer);
+    ble112.putc(event);
+    for (int i = 0; i < 4; i++) {
+        ble112.putc(bitArray.byte[i]);
+    }
+}
 
 void on_serial_rcv() {
     uint8_t command = ble112.getc();
@@ -111,14 +123,19 @@
 
 void on_tick() {
     uint32_t timestamp = capPin->getTime();
-    printf("+++Capture register: %d (%08x)\r\n", timestamp, timestamp);
+    printf("+++Capture register: %d (%08x) timer: %d (%08x)\r\n", timestamp, timestamp,
+        LPC_TIM2->TC, LPC_TIM2->TC
+    );
 }  
 
 int main() {
     printf("Booted!\r\n");
+    printf("SystemCoreClock is %d, %d ticks per ms\r\n", SystemCoreClock, SystemCoreClock/1000);
     ticker.attach(&on_tick, 5.0);
     TimerCapture::startTimer();
     capPin = new TimerCapture(p30);
+    evtPin = new TimerCapture(p29);
+    evtWatchPin.rise(&on_interrupt_recv);
     ble112.baud(9600);
     ble112.set_flow_control(SerialBase::RTSCTS, p7, p8);
     ble112.attach(&on_serial_rcv);