Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Committer:
dbartolovic
Date:
Wed Mar 07 14:39:27 2018 +0000
Revision:
1:198b9945994e
Parent:
0:fc77522f4d28
Child:
2:41a1cdac47a7
Child:
3:38eadab20283
Made some adjustments.

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"
jurica238814 0:fc77522f4d28 9
jurica238814 0:fc77522f4d28 10 static advertising_packet advertisementPacket;
jurica238814 0:fc77522f4d28 11 static GapAdvertisingData adv_data = GapAdvertisingData();
jurica238814 0:fc77522f4d28 12
jurica238814 0:fc77522f4d28 13 void disableI2C(){
jurica238814 0:fc77522f4d28 14 NRF_TWI0->ENABLE = 0;
jurica238814 0:fc77522f4d28 15 NRF_TWI0->PSELSCL = 0xFFFFFFFF;
jurica238814 0:fc77522f4d28 16 NRF_TWI1->ENABLE = 0;
jurica238814 0:fc77522f4d28 17 NRF_TWI1->PSELSCL = 0xFFFFFFFF;
jurica238814 0:fc77522f4d28 18 NRF_TWIM0->ENABLE = 0;
jurica238814 0:fc77522f4d28 19 NRF_TWIM0->PSEL.SCL = 0x80000000;
jurica238814 0:fc77522f4d28 20 NRF_TWIM0->PSEL.SDA = 0x80000000;
jurica238814 0:fc77522f4d28 21 NRF_TWIM1->ENABLE = 0;
jurica238814 0:fc77522f4d28 22 NRF_TWIM0->PSEL.SCL = 0x80000000;
jurica238814 0:fc77522f4d28 23 NRF_TWIM0->PSEL.SDA = 0x80000000;
jurica238814 0:fc77522f4d28 24 DigitalOut foo(I2C_DATA);
jurica238814 0:fc77522f4d28 25 DigitalOut bar(I2C_CLK);
jurica238814 0:fc77522f4d28 26 foo = 1;
jurica238814 0:fc77522f4d28 27 bar = 1;
jurica238814 0:fc77522f4d28 28 }
jurica238814 0:fc77522f4d28 29
jurica238814 0:fc77522f4d28 30 void bleF(BLE *ble)
jurica238814 0:fc77522f4d28 31 {
jurica238814 0:fc77522f4d28 32 while(true)
jurica238814 0:fc77522f4d28 33 {
jurica238814 0:fc77522f4d28 34
jurica238814 0:fc77522f4d28 35 advertisementPacket.header = APPLICATION_ID;
jurica238814 0:fc77522f4d28 36 advertisementPacket.type = 0x00;
jurica238814 0:fc77522f4d28 37 advertisementPacket.gyroscope[0] = (int16_t)0;
jurica238814 0:fc77522f4d28 38 advertisementPacket.gyroscope[1] = (int16_t)0;
jurica238814 0:fc77522f4d28 39 advertisementPacket.gyroscope[2] = (int16_t)0;
jurica238814 0:fc77522f4d28 40 advertisementPacket.magnetometer[0] = (int16_t)0;
jurica238814 0:fc77522f4d28 41 advertisementPacket.magnetometer[1] = (int16_t)0;
jurica238814 0:fc77522f4d28 42 advertisementPacket.magnetometer[2] = (int16_t)0;
jurica238814 0:fc77522f4d28 43
dbartolovic 1:198b9945994e 44
dbartolovic 1:198b9945994e 45 advertisementPacket.accelerometer[0] = (int16_t)mems.readXAxis()*LSB_VALUE/375;
dbartolovic 1:198b9945994e 46 advertisementPacket.accelerometer[1] = (int16_t)mems.readYAxis()*LSB_VALUE/375;
dbartolovic 1:198b9945994e 47 advertisementPacket.accelerometer[2] = (int16_t)mems.readZAxis()*LSB_VALUE/375;
dbartolovic 1:198b9945994e 48
dbartolovic 1:198b9945994e 49
dbartolovic 1:198b9945994e 50 printf("%d\t", advertisementPacket.accelerometer[0]);
dbartolovic 1:198b9945994e 51 printf("%d\t", advertisementPacket.accelerometer[1]);
dbartolovic 1:198b9945994e 52 printf("%d\r\n", advertisementPacket.accelerometer[2]);
dbartolovic 1:198b9945994e 53
jurica238814 0:fc77522f4d28 54 //updatePayload(ble, &advertisementPacket);
jurica238814 0:fc77522f4d28 55
jurica238814 0:fc77522f4d28 56 /* setup advertising */
jurica238814 0:fc77522f4d28 57
jurica238814 0:fc77522f4d28 58
jurica238814 0:fc77522f4d28 59 /*
jurica238814 0:fc77522f4d28 60 GapAdvertisingData advetisementData = GapAdvertisingData();
jurica238814 0:fc77522f4d28 61 advetisementData = ble->getAdvertisingData();
jurica238814 0:fc77522f4d28 62 advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
jurica238814 0:fc77522f4d28 63 ble->setAdvertisingData(advetisementData);
jurica238814 0:fc77522f4d28 64 */
jurica238814 0:fc77522f4d28 65 adv_data = ble->getAdvertisingData();
jurica238814 0:fc77522f4d28 66 adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
jurica238814 0:fc77522f4d28 67 ble->setAdvertisingData(adv_data);
jurica238814 0:fc77522f4d28 68
jurica238814 0:fc77522f4d28 69
jurica238814 0:fc77522f4d28 70 //printf("Ble advertisement is ON.\r\n");
jurica238814 0:fc77522f4d28 71
jurica238814 0:fc77522f4d28 72 #if DEBUG_LED
jurica238814 0:fc77522f4d28 73 redLed = 0;
jurica238814 0:fc77522f4d28 74 #endif
jurica238814 0:fc77522f4d28 75 ble->gap().startAdvertising();
jurica238814 0:fc77522f4d28 76 wait_ms(1000);
jurica238814 0:fc77522f4d28 77
jurica238814 0:fc77522f4d28 78 //wait_ms(MEASURE_INTERVAL_MS);
jurica238814 0:fc77522f4d28 79 //wait_ms(1000);
jurica238814 0:fc77522f4d28 80
jurica238814 0:fc77522f4d28 81 //printf("Ble advertisement is OFF.\r\n\r\n");
jurica238814 0:fc77522f4d28 82 #if DEBUG_LED
jurica238814 0:fc77522f4d28 83 redLed = 1;
jurica238814 0:fc77522f4d28 84 #endif
dbartolovic 1:198b9945994e 85 //ble->gap().stopAdvertising();
jurica238814 0:fc77522f4d28 86 /*
jurica238814 0:fc77522f4d28 87 GapAdvertisingData advetisementData = GapAdvertisingData();
jurica238814 0:fc77522f4d28 88 advetisementData = ble->getAdvertisingData();
jurica238814 0:fc77522f4d28 89 advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
jurica238814 0:fc77522f4d28 90 ble->setAdvertisingData(advetisementData);
jurica238814 0:fc77522f4d28 91 */
jurica238814 0:fc77522f4d28 92 wait_ms(1000);
jurica238814 0:fc77522f4d28 93 }
jurica238814 0:fc77522f4d28 94 }
jurica238814 0:fc77522f4d28 95
jurica238814 0:fc77522f4d28 96
jurica238814 0:fc77522f4d28 97 int main(){
jurica238814 0:fc77522f4d28 98
jurica238814 0:fc77522f4d28 99 printf("Main program started.\r\n");
jurica238814 0:fc77522f4d28 100
jurica238814 0:fc77522f4d28 101 NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR
jurica238814 0:fc77522f4d28 102 NRF_NVMC->ERASEUICR = 0x00000001; // Erase all
jurica238814 0:fc77522f4d28 103 NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR
jurica238814 0:fc77522f4d28 104 NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function
jurica238814 0:fc77522f4d28 105
jurica238814 0:fc77522f4d28 106 redLed = 1;
jurica238814 0:fc77522f4d28 107 AccVcc = 1;
jurica238814 0:fc77522f4d28 108 wait_ms(POWER_UP_DELAY_MS);
jurica238814 0:fc77522f4d28 109
jurica238814 0:fc77522f4d28 110 /*
jurica238814 0:fc77522f4d28 111 INT1.rise(int1Handler);
jurica238814 0:fc77522f4d28 112 NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps
jurica238814 0:fc77522f4d28 113 */
jurica238814 0:fc77522f4d28 114
jurica238814 0:fc77522f4d28 115 BLE &ble = BLE::Instance();
jurica238814 0:fc77522f4d28 116 ble.init(bleInitComplete);
jurica238814 0:fc77522f4d28 117
jurica238814 0:fc77522f4d28 118 mems.setMode(LOW_POWER);
jurica238814 0:fc77522f4d28 119 mems.enableAxes(X_axis);
jurica238814 0:fc77522f4d28 120 mems.enableAxes(Y_axis);
jurica238814 0:fc77522f4d28 121 mems.enableAxes(Z_axis);
jurica238814 0:fc77522f4d28 122 mems.setODR(ODR_50Hz);
jurica238814 0:fc77522f4d28 123 mems.setScale(_16g);
jurica238814 0:fc77522f4d28 124 mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad
jurica238814 0:fc77522f4d28 125 mems.int1Latch(0x01); // Enable int1 latch
jurica238814 0:fc77522f4d28 126 mems.int1Threshold(INT1_THRESHOLD);
jurica238814 0:fc77522f4d28 127 mems.int1Duration(INT1_DUR);
jurica238814 0:fc77522f4d28 128 mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh
jurica238814 0:fc77522f4d28 129
jurica238814 0:fc77522f4d28 130 bleT.start(callback(bleF, &ble)); // Start bleT
jurica238814 0:fc77522f4d28 131
jurica238814 0:fc77522f4d28 132
jurica238814 0:fc77522f4d28 133 while(1){
jurica238814 0:fc77522f4d28 134 //disableI2C();
jurica238814 0:fc77522f4d28 135 Thread::wait(0xFFFFFFFF);
jurica238814 0:fc77522f4d28 136 }
jurica238814 0:fc77522f4d28 137 }