Edit
Dependencies: Lis2dh12 aconno_I2C aconno_nrf52_uart adc52832_common aconno_SEGGER_RTT
Diff: source/main.cpp
- Branch:
- NanoModule
- Revision:
- 10:83dab6cc625d
- Parent:
- 9:a9c5db477f35
- Child:
- 12:d5d47f848af5
diff -r a9c5db477f35 -r 83dab6cc625d source/main.cpp --- a/source/main.cpp Wed Feb 28 07:25:59 2018 +0000 +++ b/source/main.cpp Wed Feb 28 19:59:55 2018 +0000 @@ -7,13 +7,6 @@ #include "main.h" -void printOnUart(){ - while(1){ - SEND("Uart works...\r\n"); - wait_ms(500); - } -} - void disableI2C(){ NRF_TWI0->ENABLE = 0; NRF_TWI0->PSELSCL = 0xFFFFFFFF; @@ -38,12 +31,13 @@ void int1Handler(){ __disable_irq(); - I2C i2c(I2C_DATA,I2C_CLK); + //I2C i2c(I2C_DATA,I2C_CLK); mems.clearIntFlag(); bleT.signal_set(ACC_INT_SIG); bleTicker.attach(disableBle, BLE_ACTIVE_TIME_S); - disableI2C(); + //disableI2C(); __enable_irq(); + } @@ -53,30 +47,49 @@ while(true){ Thread::signal_wait(ACC_INT_SIG); Thread::signal_clr(ACC_INT_SIG); + //I2C i2c(I2C_DATA,I2C_CLK); + printf("Interrupt on accelerometer.\r\n"); + printf("X acceleration data: %d [mg]\r\n", mems.readXAxis()*LSB_VALUE); + printf("Y acceleration data: %d [mg]\r\n", mems.readYAxis()*LSB_VALUE); + printf("Z acceleration data: %d [mg]\r\n", mems.readZAxis()*LSB_VALUE); + //disableI2C(); + //__enable_irq(); + ble->gap().startAdvertising(); + printf("Ble advertisement is ON.\r\n"); #if DEBUG_LED redLed = 0; #endif Thread::signal_wait(DISABLE_BLE_SIG); Thread::signal_clr(DISABLE_BLE_SIG); ble->gap().stopAdvertising(); + printf("Ble advertisement is OFF.\r\n\r\n"); #if DEBUG_LED redLed = 1; #endif } } +void measureF( void ) +{ + while(1){ + printf("X acceleration data: %d [mg]\r\n", mems.readXAxis()*LSB_VALUE); + printf("Y acceleration data: %d [mg]\r\n", mems.readYAxis()*LSB_VALUE); + printf("Z acceleration data: %d [mg]\r\n\r\n", mems.readZAxis()*LSB_VALUE); + wait_ms(1000); + } +} + int main(){ + printf("Main program started.\r\n"); + NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR NRF_NVMC->ERASEUICR = 0x00000001; // Erase all NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function redLed = 1; - //rgbLEDR = 1; - //rgbLEDG = 1; - //rgbLEDB = 1; AccVcc = 1; wait_ms(POWER_UP_DELAY_MS); @@ -88,21 +101,21 @@ mems.setMode(LOW_POWER); - mems.disableAxes(X_axis); - mems.disableAxes(Y_axis); + mems.enableAxes(X_axis); + mems.enableAxes(Y_axis); mems.enableAxes(Z_axis); - mems.setODR(ODR_10Hz); + mems.setODR(ODR_50Hz); mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad - mems.int1Latch(0x01); // Enable int1 latch mems.int1Threshold(INT1_THRESHOLD); - mems.int1Duration(INT1_DURATION); - mems.int1Config(0x20); // Enable XHigh and YHigh + mems.int1Duration(INT1_DUR); + mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh bleT.start(callback(bleF, &ble)); // Start bleT + //measureT.start(callback(measureF)); while(1){ - disableI2C(); + //disableI2C(); Thread::wait(0xFFFFFFFF); } }