Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Committer:
dbartolovic
Date:
Wed Aug 29 14:48:43 2018 +0000
Branch:
axis_normal
Revision:
15:c0c01188a29b
Parent:
14:65734075c8d3
Child:
16:482d8f81d6f3
Brought consumption to 500uA

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jurica238814 0:fc77522f4d28 1 /*
jurica238814 0:fc77522f4d28 2 * aconno.de
jurica238814 0:fc77522f4d28 3 * Made by Jurica Resetar
jurica238814 0:fc77522f4d28 4 * All right reserved
jurica238814 0:fc77522f4d28 5 *
jurica238814 0:fc77522f4d28 6 */
jurica238814 0:fc77522f4d28 7
jurica238814 0:fc77522f4d28 8 #include "main.h"
dbartolovic 8:7ba4f82de9b6 9 #include "bsp.h"
dbartolovic 8:7ba4f82de9b6 10 #include "tasks.h"
jurica238814 0:fc77522f4d28 11
dbartolovic 8:7ba4f82de9b6 12
dbartolovic 8:7ba4f82de9b6 13 char memsI2CAddress = I2C_ADDRESS;
dbartolovic 8:7ba4f82de9b6 14 Mutex uartM;
dbartolovic 8:7ba4f82de9b6 15 Thread uartT;
dbartolovic 8:7ba4f82de9b6 16 Thread bleT;
dbartolovic 8:7ba4f82de9b6 17 Thread measureT;
dbartolovic 8:7ba4f82de9b6 18 Thread updateServiceT;
dbartolovic 8:7ba4f82de9b6 19 Thread updateBuzzLedsT;
dbartolovic 8:7ba4f82de9b6 20
dbartolovic 15:c0c01188a29b 21 DigitalOut redica(PIN_LED_RED);
dbartolovic 8:7ba4f82de9b6 22 DigitalOut AccVcc(ACC_POWER_PIN);
dbartolovic 8:7ba4f82de9b6 23 InterruptIn INT1(INT_PIN1);
dbartolovic 8:7ba4f82de9b6 24 //InterruptIn INT2(INT_PIN2);
dbartolovic 8:7ba4f82de9b6 25 I2C i2c(I2C_DATA,I2C_CLK);
dbartolovic 8:7ba4f82de9b6 26 Ticker bleTicker;
dbartolovic 8:7ba4f82de9b6 27
jurica238814 0:fc77522f4d28 28
jurica238814 0:fc77522f4d28 29 void disableI2C(){
jurica238814 0:fc77522f4d28 30 NRF_TWI0->ENABLE = 0;
jurica238814 0:fc77522f4d28 31 NRF_TWI0->PSELSCL = 0xFFFFFFFF;
jurica238814 0:fc77522f4d28 32 NRF_TWI1->ENABLE = 0;
jurica238814 0:fc77522f4d28 33 NRF_TWI1->PSELSCL = 0xFFFFFFFF;
jurica238814 0:fc77522f4d28 34 NRF_TWIM0->ENABLE = 0;
jurica238814 0:fc77522f4d28 35 NRF_TWIM0->PSEL.SCL = 0x80000000;
jurica238814 0:fc77522f4d28 36 NRF_TWIM0->PSEL.SDA = 0x80000000;
jurica238814 0:fc77522f4d28 37 NRF_TWIM1->ENABLE = 0;
jurica238814 0:fc77522f4d28 38 NRF_TWIM0->PSEL.SCL = 0x80000000;
jurica238814 0:fc77522f4d28 39 NRF_TWIM0->PSEL.SDA = 0x80000000;
jurica238814 0:fc77522f4d28 40 DigitalOut foo(I2C_DATA);
jurica238814 0:fc77522f4d28 41 DigitalOut bar(I2C_CLK);
jurica238814 0:fc77522f4d28 42 foo = 1;
jurica238814 0:fc77522f4d28 43 bar = 1;
jurica238814 0:fc77522f4d28 44 }
jurica238814 0:fc77522f4d28 45
dbartolovic 15:c0c01188a29b 46 extern int untilSleep;
dbartolovic 15:c0c01188a29b 47 void int1Handler(void)
dbartolovic 15:c0c01188a29b 48 {
dbartolovic 15:c0c01188a29b 49 untilSleep = ACTIVE_PERIOD / MEASURE_INTERVAL_MS;
dbartolovic 15:c0c01188a29b 50
dbartolovic 15:c0c01188a29b 51 redica = !redica;
dbartolovic 15:c0c01188a29b 52
dbartolovic 15:c0c01188a29b 53 measureT.signal_set(START_MEAS);
dbartolovic 15:c0c01188a29b 54 }
dbartolovic 15:c0c01188a29b 55
dbartolovic 8:7ba4f82de9b6 56 int main(){
dbartolovic 8:7ba4f82de9b6 57 Lis2dh12 mems(&i2c, memsI2CAddress);
dbartolovic 6:55607d577a42 58
dbartolovic 15:c0c01188a29b 59 redica = 1;
dbartolovic 15:c0c01188a29b 60
dbartolovic 8:7ba4f82de9b6 61 tasks_init();
dbartolovic 6:55607d577a42 62
jurica238814 0:fc77522f4d28 63 printf("Main program started.\r\n");
jurica238814 0:fc77522f4d28 64
jurica238814 0:fc77522f4d28 65 NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR
jurica238814 0:fc77522f4d28 66 NRF_NVMC->ERASEUICR = 0x00000001; // Erase all
jurica238814 0:fc77522f4d28 67 NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR
jurica238814 0:fc77522f4d28 68 NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function
jurica238814 0:fc77522f4d28 69
jurica238814 0:fc77522f4d28 70 AccVcc = 1;
jurica238814 0:fc77522f4d28 71 wait_ms(POWER_UP_DELAY_MS);
jurica238814 0:fc77522f4d28 72
dbartolovic 15:c0c01188a29b 73
jurica238814 0:fc77522f4d28 74 INT1.rise(int1Handler);
jurica238814 0:fc77522f4d28 75 NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps
dbartolovic 15:c0c01188a29b 76
jurica238814 0:fc77522f4d28 77
jurica238814 0:fc77522f4d28 78 BLE &ble = BLE::Instance();
jurica238814 0:fc77522f4d28 79 ble.init(bleInitComplete);
jurica238814 0:fc77522f4d28 80
dbartolovic 14:65734075c8d3 81 mems.setMode(LOW_POWER);
dbartolovic 14:65734075c8d3 82 //mems.setMode(HIGH_RES);
jurica238814 0:fc77522f4d28 83 mems.enableAxes(X_axis);
jurica238814 0:fc77522f4d28 84 mems.enableAxes(Y_axis);
jurica238814 0:fc77522f4d28 85 mems.enableAxes(Z_axis);
jurica238814 0:fc77522f4d28 86 mems.setODR(ODR_50Hz);
dbartolovic 3:38eadab20283 87 //mems.setScale(_16g);
dbartolovic 3:38eadab20283 88 mems.setScale(_2g);
jurica238814 0:fc77522f4d28 89 mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad
jurica238814 0:fc77522f4d28 90 mems.int1Latch(0x01); // Enable int1 latch
jurica238814 0:fc77522f4d28 91 mems.int1Threshold(INT1_THRESHOLD);
jurica238814 0:fc77522f4d28 92 mems.int1Duration(INT1_DUR);
jurica238814 0:fc77522f4d28 93 mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh
jurica238814 0:fc77522f4d28 94
jurica238814 0:fc77522f4d28 95 bleT.start(callback(bleF, &ble)); // Start bleT
dbartolovic 8:7ba4f82de9b6 96 measureT.start(callback(measureF, &mems));
dbartolovic 8:7ba4f82de9b6 97 updateServiceT.start(updateServiceF);
dbartolovic 8:7ba4f82de9b6 98 updateBuzzLedsT.start(updateBuzzLedsF);
jurica238814 0:fc77522f4d28 99
jurica238814 0:fc77522f4d28 100
jurica238814 0:fc77522f4d28 101 while(1){
jurica238814 0:fc77522f4d28 102 //disableI2C();
dbartolovic 15:c0c01188a29b 103 //ble.waitForEvent();
dbartolovic 15:c0c01188a29b 104 getBLEEventQueue()->dispatch_forever();
dbartolovic 15:c0c01188a29b 105 Thread::wait(0xFFFFFFFF);
jurica238814 0:fc77522f4d28 106 }
jurica238814 0:fc77522f4d28 107 }