this is program how build nRF51822 to get ADXL345 data
Dependencies: BLE_API mbed nRF51822
Fork of ADXL345_I2C by
Revision 4:a57b495be9fa, committed 2017-12-04
- Comitter:
- asyrofi
- Date:
- Mon Dec 04 14:00:40 2017 +0000
- Parent:
- 3:1749778af065
- Child:
- 5:8242f251bcac
- Commit message:
- mantapp
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Dec 03 10:58:11 2017 +0000
+++ b/main.cpp Mon Dec 04 14:00:40 2017 +0000
@@ -13,13 +13,12 @@
#define DEBUG(...) /* nothing */
#endif /* #if NEED_CONSOLE_OUTPUT */
- ADXL345_I2C accelerometer(p7, p30);
- Serial pc(USBTX, USBRX);
+ ADXL345_I2C accelerometer(p30, p7);
BLEDevice ble;
DigitalOut led1(LED1);
Serial uart1(USBTX,USBRX);
UARTService *uartServicePtr;
- uint8_t sFlag = 0;
+ //uint8_t sFlag = 0;
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
{
@@ -51,30 +50,14 @@
led1 = !led1;
}
-uint8_t c;
-void uartRx(void)
-{
-
- c = uart1.getc();
-
- if(sFlag < 39)
- b[sFlag++] = c;
-
- if(c == '\r' || c == '\n' || sFlag == 15)
- {
- ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (const uint8_t*)b/*params->data*/, sFlag/*bytesRead*/);
- sFlag = 0;
- }
-}
int main() {
- pc.baud(9600);
+ uart1.baud(9600);
int readings[3] = {0, 0, 0};
-
- pc.printf("Starting ADXL345 test...\n");
+ uart1.printf("Starting ADXL345 test...\n");
wait(.001);
- pc.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID());
+ uart1.printf("Device ID is: 0x%02x\n", accelerometer.getDeviceID());
wait(.001);
//Go into standby mode to configure the device.
@@ -93,8 +76,8 @@
uart1.baud(9600);
Ticker ticker;
ticker.attach(periodicCallback, 1);
- uart1.attach(uartRx,Serial::RxIrq);
-
+
+
DEBUG("Initialising the nRF51822\n\r");
ble.init();
ble.onDisconnection(disconnectionCallback);
@@ -115,11 +98,15 @@
UARTService uartService(ble);
uartServicePtr = &uartService;
- while (1) {
+ while (1)
+ {
ble.waitForEvent();
wait(0.1);
accelerometer.getOutput(readings);
- pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);
+ uart1.printf("%i, %i, %i\n", (uint8_t)readings[0], (uint8_t)readings[1], (uint8_t)readings[2]);
+ ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)readings[0]/*params->data*/, 4/*bytesRead*/);
+ ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)readings[1]/*params->data*/, 4/*bytesRead*/);
+ ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), (uint8_t*)readings[2]/*params->data*/, 4/*bytesRead*/);
}
}
