Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

Committer:
jurica238814
Date:
Thu Mar 08 10:29:22 2018 +0000
Revision:
2:41a1cdac47a7
Parent:
1:198b9945994e
Child:
4:49b1aeca55e4
Multiplication factor added.

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
jurica238814 2:41a1cdac47a7 44 advertisementPacket.accelerometer[0] = (int16_t)mems.readXAxis();
jurica238814 2:41a1cdac47a7 45 advertisementPacket.accelerometer[1] = (int16_t)mems.readYAxis();
jurica238814 2:41a1cdac47a7 46 advertisementPacket.accelerometer[2] = (int16_t)mems.readZAxis();
jurica238814 2:41a1cdac47a7 47 advertisementPacket.acc_lsb_value = 0xC000;
jurica238814 2:41a1cdac47a7 48 /*
dbartolovic 1:198b9945994e 49 printf("%d\t", advertisementPacket.accelerometer[0]);
dbartolovic 1:198b9945994e 50 printf("%d\t", advertisementPacket.accelerometer[1]);
dbartolovic 1:198b9945994e 51 printf("%d\r\n", advertisementPacket.accelerometer[2]);
jurica238814 2:41a1cdac47a7 52 */
jurica238814 0:fc77522f4d28 53 //updatePayload(ble, &advertisementPacket);
jurica238814 0:fc77522f4d28 54
jurica238814 0:fc77522f4d28 55 /* setup advertising */
jurica238814 0:fc77522f4d28 56
jurica238814 0:fc77522f4d28 57
jurica238814 0:fc77522f4d28 58 /*
jurica238814 0:fc77522f4d28 59 GapAdvertisingData advetisementData = GapAdvertisingData();
jurica238814 0:fc77522f4d28 60 advetisementData = ble->getAdvertisingData();
jurica238814 0:fc77522f4d28 61 advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
jurica238814 0:fc77522f4d28 62 ble->setAdvertisingData(advetisementData);
jurica238814 0:fc77522f4d28 63 */
jurica238814 0:fc77522f4d28 64 adv_data = ble->getAdvertisingData();
jurica238814 0:fc77522f4d28 65 adv_data.updateData(adv_data.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertisementPacket));
jurica238814 0:fc77522f4d28 66 ble->setAdvertisingData(adv_data);
jurica238814 0:fc77522f4d28 67
jurica238814 0:fc77522f4d28 68
jurica238814 0:fc77522f4d28 69 //printf("Ble advertisement is ON.\r\n");
jurica238814 0:fc77522f4d28 70
jurica238814 0:fc77522f4d28 71 #if DEBUG_LED
jurica238814 0:fc77522f4d28 72 redLed = 0;
jurica238814 0:fc77522f4d28 73 #endif
jurica238814 0:fc77522f4d28 74 ble->gap().startAdvertising();
jurica238814 0:fc77522f4d28 75 wait_ms(1000);
jurica238814 0:fc77522f4d28 76
jurica238814 0:fc77522f4d28 77 //wait_ms(MEASURE_INTERVAL_MS);
jurica238814 0:fc77522f4d28 78 //wait_ms(1000);
jurica238814 0:fc77522f4d28 79
jurica238814 0:fc77522f4d28 80 //printf("Ble advertisement is OFF.\r\n\r\n");
jurica238814 0:fc77522f4d28 81 #if DEBUG_LED
jurica238814 0:fc77522f4d28 82 redLed = 1;
jurica238814 0:fc77522f4d28 83 #endif
dbartolovic 1:198b9945994e 84 //ble->gap().stopAdvertising();
jurica238814 0:fc77522f4d28 85 /*
jurica238814 0:fc77522f4d28 86 GapAdvertisingData advetisementData = GapAdvertisingData();
jurica238814 0:fc77522f4d28 87 advetisementData = ble->getAdvertisingData();
jurica238814 0:fc77522f4d28 88 advetisementData.updateData(advetisementData.MANUFACTURER_SPECIFIC_DATA, (uint8_t *)&advertisementPacket, sizeof(advertising_packet));
jurica238814 0:fc77522f4d28 89 ble->setAdvertisingData(advetisementData);
jurica238814 0:fc77522f4d28 90 */
jurica238814 0:fc77522f4d28 91 wait_ms(1000);
jurica238814 0:fc77522f4d28 92 }
jurica238814 0:fc77522f4d28 93 }
jurica238814 0:fc77522f4d28 94
jurica238814 0:fc77522f4d28 95
jurica238814 0:fc77522f4d28 96 int main(){
jurica238814 0:fc77522f4d28 97
jurica238814 0:fc77522f4d28 98 printf("Main program started.\r\n");
jurica238814 0:fc77522f4d28 99
jurica238814 0:fc77522f4d28 100 NRF_NVMC->CONFIG = 0x00000002; // Erase enable UICR
jurica238814 0:fc77522f4d28 101 NRF_NVMC->ERASEUICR = 0x00000001; // Erase all
jurica238814 0:fc77522f4d28 102 NRF_NVMC->CONFIG = 0x00000001; // Write enable UICR
jurica238814 0:fc77522f4d28 103 NRF_UICR->NFCPINS = 0xFFFFFFFE; // Change NFC to GPIO function
jurica238814 0:fc77522f4d28 104
jurica238814 0:fc77522f4d28 105 redLed = 1;
jurica238814 0:fc77522f4d28 106 AccVcc = 1;
jurica238814 0:fc77522f4d28 107 wait_ms(POWER_UP_DELAY_MS);
jurica238814 0:fc77522f4d28 108
jurica238814 0:fc77522f4d28 109 /*
jurica238814 0:fc77522f4d28 110 INT1.rise(int1Handler);
jurica238814 0:fc77522f4d28 111 NRF_GPIO->PIN_CNF[INT_PIN1] &= 0xFFFFFFF3; // NO PullUps
jurica238814 0:fc77522f4d28 112 */
jurica238814 0:fc77522f4d28 113
jurica238814 0:fc77522f4d28 114 BLE &ble = BLE::Instance();
jurica238814 0:fc77522f4d28 115 ble.init(bleInitComplete);
jurica238814 0:fc77522f4d28 116
jurica238814 0:fc77522f4d28 117 mems.setMode(LOW_POWER);
jurica238814 0:fc77522f4d28 118 mems.enableAxes(X_axis);
jurica238814 0:fc77522f4d28 119 mems.enableAxes(Y_axis);
jurica238814 0:fc77522f4d28 120 mems.enableAxes(Z_axis);
jurica238814 0:fc77522f4d28 121 mems.setODR(ODR_50Hz);
jurica238814 0:fc77522f4d28 122 mems.setScale(_16g);
jurica238814 0:fc77522f4d28 123 mems.int1Setup(0x40); // IntActivity 1 driven to INT1 pad
jurica238814 0:fc77522f4d28 124 mems.int1Latch(0x01); // Enable int1 latch
jurica238814 0:fc77522f4d28 125 mems.int1Threshold(INT1_THRESHOLD);
jurica238814 0:fc77522f4d28 126 mems.int1Duration(INT1_DUR);
jurica238814 0:fc77522f4d28 127 mems.int1Config(0x2A); // Enable XHigh, YHigh and ZHigh
jurica238814 0:fc77522f4d28 128
jurica238814 0:fc77522f4d28 129 bleT.start(callback(bleF, &ble)); // Start bleT
jurica238814 0:fc77522f4d28 130
jurica238814 0:fc77522f4d28 131
jurica238814 0:fc77522f4d28 132 while(1){
jurica238814 0:fc77522f4d28 133 //disableI2C();
jurica238814 0:fc77522f4d28 134 Thread::wait(0xFFFFFFFF);
jurica238814 0:fc77522f4d28 135 }
jurica238814 0:fc77522f4d28 136 }