![](/media/cache/profiles/b5c4ec91390a6fbccf8d918d443563ed.jpg.50x50_q85.jpg)
Edit
Dependencies: Lis2dh12 aconno_I2C aconno_nrf52_uart adc52832_common aconno_SEGGER_RTT
source/main.cpp@13:7ae1c5bcccb5, 2018-03-02 (annotated)
- Committer:
- jurica238814
- Date:
- Fri Mar 02 10:29:59 2018 +0000
- Branch:
- NanoModule
- Revision:
- 13:7ae1c5bcccb5
- Parent:
- 12:d5d47f848af5
This version works ok for DICE project. ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 3:f2078081a779 | 1 | /* |
jurica238814 | 3:f2078081a779 | 2 | * aconno.de |
jurica238814 | 3:f2078081a779 | 3 | * Made by Jurica Resetar |
jurica238814 | 3:f2078081a779 | 4 | * All right reserved |
jurica238814 | 3:f2078081a779 | 5 | * |
jurica238814 | 3:f2078081a779 | 6 | */ |
jurica238814 | 3:f2078081a779 | 7 | |
jurica238814 | 3:f2078081a779 | 8 | #include "main.h" |
jurica238814 | 3:f2078081a779 | 9 | |
jurica238814 | 3:f2078081a779 | 10 | void disableI2C(){ |
jurica238814 | 3:f2078081a779 | 11 | NRF_TWI0->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 12 | NRF_TWI0->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 3:f2078081a779 | 13 | NRF_TWI1->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 14 | NRF_TWI1->PSELSCL = 0xFFFFFFFF; |
jurica238814 | 3:f2078081a779 | 15 | NRF_TWIM0->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 16 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 3:f2078081a779 | 17 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 3:f2078081a779 | 18 | NRF_TWIM1->ENABLE = 0; |
jurica238814 | 3:f2078081a779 | 19 | NRF_TWIM0->PSEL.SCL = 0x80000000; |
jurica238814 | 3:f2078081a779 | 20 | NRF_TWIM0->PSEL.SDA = 0x80000000; |
jurica238814 | 3:f2078081a779 | 21 | DigitalOut foo(I2C_DATA); |
jurica238814 | 3:f2078081a779 | 22 | DigitalOut bar(I2C_CLK); |
jurica238814 | 3:f2078081a779 | 23 | foo = 1; |
jurica238814 | 3:f2078081a779 | 24 | bar = 1; |
jurica238814 | 3:f2078081a779 | 25 | } |
jurica238814 | 3:f2078081a779 | 26 | |
jurica238814 | 3:f2078081a779 | 27 | void disableBle(){ |
jurica238814 | 3:f2078081a779 | 28 | bleTicker.detach(); |
jurica238814 | 3:f2078081a779 | 29 | bleT.signal_set(DISABLE_BLE_SIG); |
jurica238814 | 3:f2078081a779 | 30 | } |
jurica238814 | 3:f2078081a779 | 31 | |
jurica238814 | 3:f2078081a779 | 32 | void int1Handler(){ |
jurica238814 | 3:f2078081a779 | 33 | __disable_irq(); |
jurica238814 | 13:7ae1c5bcccb5 | 34 | I2C i2c(I2C_DATA,I2C_CLK); |
jurica238814 | 3:f2078081a779 | 35 | mems.clearIntFlag(); |
jurica238814 | 3:f2078081a779 | 36 | bleT.signal_set(ACC_INT_SIG); |
jurica238814 | 3:f2078081a779 | 37 | bleTicker.attach(disableBle, BLE_ACTIVE_TIME_S); |
jurica238814 | 13:7ae1c5bcccb5 | 38 | disableI2C(); |
jurica238814 | 3:f2078081a779 | 39 | __enable_irq(); |
jurica238814 | 10:83dab6cc625d | 40 | |
jurica238814 | 3:f2078081a779 | 41 | } |
jurica238814 | 3:f2078081a779 | 42 | |
jurica238814 | 3:f2078081a779 | 43 | |
jurica238814 | 3:f2078081a779 | 44 | void bleF(BLE *ble){ |
jurica238814 | 3:f2078081a779 | 45 | // Thread function for managing BLE radio |
jurica238814 | 3:f2078081a779 | 46 | // First wait for acc interrupt signal |
jurica238814 | 3:f2078081a779 | 47 | while(true){ |
jurica238814 | 3:f2078081a779 | 48 | Thread::signal_wait(ACC_INT_SIG); |
jurica238814 | 3:f2078081a779 | 49 | Thread::signal_clr(ACC_INT_SIG); |
jurica238814 | 10:83dab6cc625d | 50 | //I2C i2c(I2C_DATA,I2C_CLK); |
jurica238814 | 13:7ae1c5bcccb5 | 51 | |
jurica238814 | 12:d5d47f848af5 | 52 | printf("\r\n\r\n**********************\r\n"); |
jurica238814 | 10:83dab6cc625d | 53 | printf("Interrupt on accelerometer.\r\n"); |
jurica238814 | 10:83dab6cc625d | 54 | printf("X acceleration data: %d [mg]\r\n", mems.readXAxis()*LSB_VALUE); |
jurica238814 | 10:83dab6cc625d | 55 | printf("Y acceleration data: %d [mg]\r\n", mems.readYAxis()*LSB_VALUE); |
jurica238814 | 10:83dab6cc625d | 56 | printf("Z acceleration data: %d [mg]\r\n", mems.readZAxis()*LSB_VALUE); |
jurica238814 | 12:d5d47f848af5 | 57 | printf("******************************\r\n"); |
jurica238814 | 13:7ae1c5bcccb5 | 58 | |
jurica238814 | 10:83dab6cc625d | 59 | //disableI2C(); |
jurica238814 | 10:83dab6cc625d | 60 | //__enable_irq(); |
jurica238814 | 10:83dab6cc625d | 61 | |
jurica238814 | 3:f2078081a779 | 62 | ble->gap().startAdvertising(); |
jurica238814 | 10:83dab6cc625d | 63 | printf("Ble advertisement is ON.\r\n"); |
jurica238814 | 3:f2078081a779 | 64 | #if DEBUG_LED |
jurica238814 | 3:f2078081a779 | 65 | redLed = 0; |
jurica238814 | 3:f2078081a779 | 66 | #endif |
jurica238814 | 3:f2078081a779 | 67 | Thread::signal_wait(DISABLE_BLE_SIG); |
jurica238814 | 3:f2078081a779 | 68 | Thread::signal_clr(DISABLE_BLE_SIG); |
jurica238814 | 3:f2078081a779 | 69 | ble->gap().stopAdvertising(); |
jurica238814 | 10:83dab6cc625d | 70 | printf("Ble advertisement is OFF.\r\n\r\n"); |
jurica238814 | 3:f2078081a779 | 71 | #if DEBUG_LED |
jurica238814 | 3:f2078081a779 | 72 | redLed = 1; |
jurica238814 | 3:f2078081a779 | 73 | #endif |
jurica238814 | 3:f2078081a779 | 74 | } |
jurica238814 | 3:f2078081a779 | 75 | } |
jurica238814 | 3:f2078081a779 | 76 | |
jurica238814 | 10:83dab6cc625d | 77 | void measureF( void ) |
jurica238814 | 10:83dab6cc625d | 78 | { |
jurica238814 | 10:83dab6cc625d | 79 | while(1){ |
jurica238814 | 10:83dab6cc625d | 80 | printf("X acceleration data: %d [mg]\r\n", mems.readXAxis()*LSB_VALUE); |
jurica238814 | 10:83dab6cc625d | 81 | printf("Y acceleration data: %d [mg]\r\n", mems.readYAxis()*LSB_VALUE); |
jurica238814 | 10:83dab6cc625d | 82 | printf("Z acceleration data: %d [mg]\r\n\r\n", mems.readZAxis()*LSB_VALUE); |
jurica238814 | 12:d5d47f848af5 | 83 | wait_ms(100); |
jurica238814 | 10:83dab6cc625d | 84 | } |
jurica238814 | 10:83dab6cc625d | 85 | } |
jurica238814 | 10:83dab6cc625d | 86 | |
jurica238814 | 3:f2078081a779 | 87 | int main(){ |
jurica238814 | 8:4b1ac4733b3d | 88 | |
jurica238814 | 10:83dab6cc625d | 89 | printf("Main program started.\r\n"); |
jurica238814 | 10:83dab6cc625d | 90 | |
jurica238814 | 8:4b1ac4733b3d | 91 | NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR |
jurica238814 | 8:4b1ac4733b3d | 92 | NRF_NVMC->ERASEUICR = 0x00000001; // Erase all |
jurica238814 | 8:4b1ac4733b3d | 93 | NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR |
jurica238814 | 8:4b1ac4733b3d | 94 | NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function |
jurica238814 | 8:4b1ac4733b3d | 95 | |
jurica238814 | 3:f2078081a779 | 96 | redLed = 1; |
jurica238814 | 3:f2078081a779 | 97 | AccVcc = 1; |
jurica238814 | 3:f2078081a779 | 98 | wait_ms(POWER_UP_DELAY_MS); |
jurica238814 | 3:f2078081a779 | 99 | |
jurica238814 | 3:f2078081a779 | 100 | INT1.rise(int1Handler); |
jurica238814 | 3:f2078081a779 | 101 | NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps |
jurica238814 | 3:f2078081a779 | 102 | |
jurica238814 | 3:f2078081a779 | 103 | BLE &ble = BLE::Instance(); |
jurica238814 | 3:f2078081a779 | 104 | ble.init(bleInitComplete); |
jurica238814 | 3:f2078081a779 | 105 | |
jurica238814 | 3:f2078081a779 | 106 | mems.setMode(LOW_POWER); |
jurica238814 | 3:f2078081a779 | 107 | |
jurica238814 | 10:83dab6cc625d | 108 | mems.enableAxes(X_axis); |
jurica238814 | 10:83dab6cc625d | 109 | mems.enableAxes(Y_axis); |
jurica238814 | 3:f2078081a779 | 110 | mems.enableAxes(Z_axis); |
jurica238814 | 10:83dab6cc625d | 111 | mems.setODR(ODR_50Hz); |
jurica238814 | 13:7ae1c5bcccb5 | 112 | mems.setScale(_16g); |
jurica238814 | 3:f2078081a779 | 113 | mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad |
jurica238814 | 3:f2078081a779 | 114 | mems.int1Latch(0x01); // Enable int1 latch |
jurica238814 | 9:a9c5db477f35 | 115 | mems.int1Threshold(INT1_THRESHOLD); |
jurica238814 | 10:83dab6cc625d | 116 | mems.int1Duration(INT1_DUR); |
jurica238814 | 10:83dab6cc625d | 117 | mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh |
jurica238814 | 3:f2078081a779 | 118 | |
jurica238814 | 3:f2078081a779 | 119 | bleT.start(callback(bleF, &ble)); // Start bleT |
jurica238814 | 13:7ae1c5bcccb5 | 120 | //measureT.start(callback(measureF)); |
jurica238814 | 3:f2078081a779 | 121 | |
jurica238814 | 3:f2078081a779 | 122 | while(1){ |
jurica238814 | 13:7ae1c5bcccb5 | 123 | disableI2C(); |
jurica238814 | 3:f2078081a779 | 124 | Thread::wait(0xFFFFFFFF); |
jurica238814 | 3:f2078081a779 | 125 | } |
jurica238814 | 3:f2078081a779 | 126 | } |