this profile using UART with ADXL335 accelerometer, but this is can't reach accelerometer sensor.. please help me to fix it

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_LoopbackUART by Bluetooth Low Energy

Committer:
asyrofi
Date:
Wed Oct 11 08:09:08 2017 +0000
Revision:
14:4dfb61282efb
Parent:
13:15764cc1f12c
Child:
15:34c3e96ce282
need revision for UART_ADXL335

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:e910d9bb040f 1 /* mbed Microcontroller Library
yihui 0:e910d9bb040f 2 * Copyright (c) 2006-2013 ARM Limited
yihui 0:e910d9bb040f 3 *
yihui 0:e910d9bb040f 4 * Licensed under the Apache License, Version 2.0 (the "License");
yihui 0:e910d9bb040f 5 * you may not use this file except in compliance with the License.
yihui 0:e910d9bb040f 6 * You may obtain a copy of the License at
yihui 0:e910d9bb040f 7 *
yihui 0:e910d9bb040f 8 * http://www.apache.org/licenses/LICENSE-2.0
yihui 0:e910d9bb040f 9 *
yihui 0:e910d9bb040f 10 * Unless required by applicable law or agreed to in writing, software
yihui 0:e910d9bb040f 11 * distributed under the License is distributed on an "AS IS" BASIS,
yihui 0:e910d9bb040f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
yihui 0:e910d9bb040f 13 * See the License for the specific language governing permissions and
yihui 0:e910d9bb040f 14 * limitations under the License.
yihui 0:e910d9bb040f 15 */
yihui 0:e910d9bb040f 16
yihui 0:e910d9bb040f 17 #include "mbed.h"
rgrover1 12:33153cf38631 18 #include "ble/BLE.h"
yihui 0:e910d9bb040f 19
rgrover1 12:33153cf38631 20 #include "ble/services/UARTService.h"
yihui 0:e910d9bb040f 21
rgrover1 6:e0fc9072e853 22 #define NEED_CONSOLE_OUTPUT 0 /* Set this if you need debug messages on the console;
Rohit Grover 2:e060367b9024 23 * it will have an impact on code-size and power consumption. */
yihui 0:e910d9bb040f 24
Rohit Grover 2:e060367b9024 25 #if NEED_CONSOLE_OUTPUT
rgrover1 6:e0fc9072e853 26 #define DEBUG(...) { printf(__VA_ARGS__); }
yihui 0:e910d9bb040f 27 #else
Rohit Grover 2:e060367b9024 28 #define DEBUG(...) /* nothing */
Rohit Grover 2:e060367b9024 29 #endif /* #if NEED_CONSOLE_OUTPUT */
yihui 0:e910d9bb040f 30
Rohit Grover 2:e060367b9024 31 BLEDevice ble;
Rohit Grover 2:e060367b9024 32 DigitalOut led1(LED1);
yihui 0:e910d9bb040f 33
rgrover1 6:e0fc9072e853 34 UARTService *uartServicePtr;
yihui 0:e910d9bb040f 35
asyrofi 14:4dfb61282efb 36 Serial pc(USBTX, USBRX);
asyrofi 14:4dfb61282efb 37 AnalogIn analog_value1(A0);
asyrofi 14:4dfb61282efb 38 AnalogIn analog_value2(A1);
asyrofi 14:4dfb61282efb 39 AnalogIn analog_value3(A2);
asyrofi 14:4dfb61282efb 40
asyrofi 14:4dfb61282efb 41 DigitalOut led(LED1);
asyrofi 14:4dfb61282efb 42
rgrover1 13:15764cc1f12c 43 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
yihui 0:e910d9bb040f 44 {
Rohit Grover 2:e060367b9024 45 DEBUG("Disconnected!\n\r");
Rohit Grover 2:e060367b9024 46 DEBUG("Restarting the advertising process\n\r");
Rohit Grover 2:e060367b9024 47 ble.startAdvertising();
Rohit Grover 2:e060367b9024 48 }
yihui 0:e910d9bb040f 49
rgrover1 12:33153cf38631 50 void onDataWritten(const GattWriteCallbackParams *params)
yihui 0:e910d9bb040f 51 {
rgrover1 12:33153cf38631 52 if ((uartServicePtr != NULL) && (params->handle == uartServicePtr->getTXCharacteristicHandle())) {
rgrover1 5:4bc41267a03a 53 uint16_t bytesRead = params->len;
rgrover1 5:4bc41267a03a 54 DEBUG("received %u bytes\n\r", bytesRead);
rgrover1 6:e0fc9072e853 55 ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
yihui 0:e910d9bb040f 56 }
Rohit Grover 2:e060367b9024 57 }
yihui 0:e910d9bb040f 58
Rohit Grover 2:e060367b9024 59 void periodicCallback(void)
Rohit Grover 2:e060367b9024 60 {
rgrover1 6:e0fc9072e853 61 led1 = !led1;
Rohit Grover 2:e060367b9024 62 }
yihui 0:e910d9bb040f 63
yihui 0:e910d9bb040f 64 int main(void)
yihui 0:e910d9bb040f 65 {
asyrofi 14:4dfb61282efb 66 int x,y,z;
asyrofi 14:4dfb61282efb 67 printf("\nAnalogIn Example\n");
asyrofi 14:4dfb61282efb 68
Rohit Grover 2:e060367b9024 69 led1 = 1;
Rohit Grover 2:e060367b9024 70 Ticker ticker;
Rohit Grover 2:e060367b9024 71 ticker.attach(periodicCallback, 1);
yihui 0:e910d9bb040f 72
Rohit Grover 2:e060367b9024 73 DEBUG("Initialising the nRF51822\n\r");
Rohit Grover 2:e060367b9024 74 ble.init();
Rohit Grover 2:e060367b9024 75 ble.onDisconnection(disconnectionCallback);
Rohit Grover 2:e060367b9024 76 ble.onDataWritten(onDataWritten);
yihui 0:e910d9bb040f 77
Rohit Grover 2:e060367b9024 78 /* setup advertising */
Rohit Grover 2:e060367b9024 79 ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
Rohit Grover 2:e060367b9024 80 ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Rohit Grover 2:e060367b9024 81 ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
rgrover1 6:e0fc9072e853 82 (const uint8_t *)"BLE UART", sizeof("BLE UART") - 1);
Rohit Grover 2:e060367b9024 83 ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS,
rgrover1 6:e0fc9072e853 84 (const uint8_t *)UARTServiceUUID_reversed, sizeof(UARTServiceUUID_reversed));
yihui 0:e910d9bb040f 85
rgrover1 12:33153cf38631 86 ble.setAdvertisingInterval(1000); /* 1000ms; in multiples of 0.625ms. */
Rohit Grover 2:e060367b9024 87 ble.startAdvertising();
yihui 0:e910d9bb040f 88
rgrover1 6:e0fc9072e853 89 UARTService uartService(ble);
rgrover1 6:e0fc9072e853 90 uartServicePtr = &uartService;
yihui 0:e910d9bb040f 91
asyrofi 14:4dfb61282efb 92 while (true)
asyrofi 14:4dfb61282efb 93 {
Rohit Grover 2:e060367b9024 94 ble.waitForEvent();
asyrofi 14:4dfb61282efb 95 x = analog_value1.read_u16();
asyrofi 14:4dfb61282efb 96 y = analog_value2.read_u16();
asyrofi 14:4dfb61282efb 97 z = analog_value3.read_u16();
asyrofi 14:4dfb61282efb 98 printf("\r x = %d y = %d z = %d \n",x,y,z);
asyrofi 14:4dfb61282efb 99 wait(0.5);
yihui 0:e910d9bb040f 100 }
asyrofi 14:4dfb61282efb 101
asyrofi 14:4dfb61282efb 102
yihui 0:e910d9bb040f 103 }