![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
freefall-sleep
main.cpp@1:1b10921f4922, 2017-11-13 (annotated)
- Committer:
- zdenka
- Date:
- Mon Nov 13 15:40:25 2017 +0000
- Revision:
- 1:1b10921f4922
- Parent:
- 0:97ddc2168412
freefall-sleep
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zdenka | 0:97ddc2168412 | 1 | #include "mbed.h" |
zdenka | 0:97ddc2168412 | 2 | #include "MMA8451Q.h" |
zdenka | 1:1b10921f4922 | 3 | #include "cmsis.h" |
zdenka | 1:1b10921f4922 | 4 | #include "PeripheralPins.h" |
zdenka | 0:97ddc2168412 | 5 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
zdenka | 0:97ddc2168412 | 6 | PinName const SDA = PTE25; |
zdenka | 0:97ddc2168412 | 7 | PinName const SCL = PTE24; |
zdenka | 0:97ddc2168412 | 8 | #elif defined (TARGET_KL05Z) |
zdenka | 0:97ddc2168412 | 9 | PinName const SDA = PTB4; |
zdenka | 0:97ddc2168412 | 10 | PinName const SCL = PTB3; |
zdenka | 0:97ddc2168412 | 11 | #elif defined (TARGET_K20D50M) |
zdenka | 0:97ddc2168412 | 12 | PinName const SDA = PTB1; |
zdenka | 0:97ddc2168412 | 13 | PinName const SCL = PTB0; |
zdenka | 0:97ddc2168412 | 14 | #else |
zdenka | 0:97ddc2168412 | 15 | #error TARGET NOT DEFINED |
zdenka | 0:97ddc2168412 | 16 | #endif |
zdenka | 0:97ddc2168412 | 17 | |
zdenka | 0:97ddc2168412 | 18 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
zdenka | 0:97ddc2168412 | 19 | Serial pc(USBTX, USBRX); |
zdenka | 0:97ddc2168412 | 20 | |
zdenka | 0:97ddc2168412 | 21 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
zdenka | 0:97ddc2168412 | 22 | InterruptIn in(PTA15); |
zdenka | 1:1b10921f4922 | 23 | |
zdenka | 1:1b10921f4922 | 24 | |
zdenka | 1:1b10921f4922 | 25 | |
zdenka | 1:1b10921f4922 | 26 | void slleep() |
zdenka | 1:1b10921f4922 | 27 | { |
zdenka | 1:1b10921f4922 | 28 | SMC->PMPROT = SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLP_MASK; |
zdenka | 1:1b10921f4922 | 29 | |
zdenka | 1:1b10921f4922 | 30 | //Normal sleep mode for ARM core: |
zdenka | 1:1b10921f4922 | 31 | SCB->SCR = 0; |
zdenka | 1:1b10921f4922 | 32 | __WFI(); |
zdenka | 1:1b10921f4922 | 33 | } |
zdenka | 0:97ddc2168412 | 34 | void svojafunkcia(){ |
zdenka | 0:97ddc2168412 | 35 | uint8_t data[1]; |
zdenka | 0:97ddc2168412 | 36 | acc.readRegs(0x0C,data,1); |
zdenka | 0:97ddc2168412 | 37 | if((data[0]&0x04)==0x04){ |
zdenka | 0:97ddc2168412 | 38 | uint8_t cokolvek[1]; |
zdenka | 0:97ddc2168412 | 39 | acc.readRegs(0x16,cokolvek,1); |
zdenka | 0:97ddc2168412 | 40 | pc.printf("prerusenie\r \n"); // print the value of variable i |
zdenka | 1:1b10921f4922 | 41 | slleep(); |
zdenka | 0:97ddc2168412 | 42 | |
zdenka | 0:97ddc2168412 | 43 | } |
zdenka | 0:97ddc2168412 | 44 | } |
zdenka | 0:97ddc2168412 | 45 | |
zdenka | 0:97ddc2168412 | 46 | int main(void) |
zdenka | 0:97ddc2168412 | 47 | { |
zdenka | 0:97ddc2168412 | 48 | in.fall(&svojafunkcia); |
zdenka | 0:97ddc2168412 | 49 | |
zdenka | 0:97ddc2168412 | 50 | //krok1 |
zdenka | 0:97ddc2168412 | 51 | uint8_t data1[2] = {0x2A, 0x20}; |
zdenka | 0:97ddc2168412 | 52 | acc.writeRegs(data1, 2); |
zdenka | 0:97ddc2168412 | 53 | |
zdenka | 0:97ddc2168412 | 54 | //krok2 |
zdenka | 0:97ddc2168412 | 55 | uint8_t data2[2] = {0x15, 0xB8}; |
zdenka | 0:97ddc2168412 | 56 | acc.writeRegs(data2, 2); |
zdenka | 0:97ddc2168412 | 57 | |
zdenka | 0:97ddc2168412 | 58 | //krok3 |
zdenka | 0:97ddc2168412 | 59 | uint8_t data3[2] = {0x17, 0x03}; |
zdenka | 0:97ddc2168412 | 60 | acc.writeRegs(data3, 2); |
zdenka | 0:97ddc2168412 | 61 | |
zdenka | 0:97ddc2168412 | 62 | //krok4 |
zdenka | 0:97ddc2168412 | 63 | uint8_t data4[2] = {0x18, 0x06}; |
zdenka | 0:97ddc2168412 | 64 | acc.writeRegs(data4, 2); |
zdenka | 0:97ddc2168412 | 65 | |
zdenka | 0:97ddc2168412 | 66 | //krok5 |
zdenka | 0:97ddc2168412 | 67 | uint8_t data5[2] = {0x2D, 0x04}; |
zdenka | 0:97ddc2168412 | 68 | acc.writeRegs(data5, 2); |
zdenka | 0:97ddc2168412 | 69 | |
zdenka | 0:97ddc2168412 | 70 | //krok6 |
zdenka | 0:97ddc2168412 | 71 | uint8_t data6[2] = {0x2E, 0x00}; |
zdenka | 0:97ddc2168412 | 72 | acc.writeRegs(data6, 2); |
zdenka | 0:97ddc2168412 | 73 | |
zdenka | 0:97ddc2168412 | 74 | //krok7 |
zdenka | 0:97ddc2168412 | 75 | uint8_t data[1]; |
zdenka | 0:97ddc2168412 | 76 | acc.readRegs(0x2A,data,1); |
zdenka | 0:97ddc2168412 | 77 | data[0]=data[0]| 0x01; |
zdenka | 0:97ddc2168412 | 78 | uint8_t data7[2]={0x2A,data[0]}; |
zdenka | 0:97ddc2168412 | 79 | data7[1]=data[0]; |
zdenka | 0:97ddc2168412 | 80 | acc.writeRegs(data7,2); |
zdenka | 1:1b10921f4922 | 81 | |
zdenka | 0:97ddc2168412 | 82 | |
zdenka | 1:1b10921f4922 | 83 | slleep(); |
zdenka | 0:97ddc2168412 | 84 | while (true) { |
zdenka | 1:1b10921f4922 | 85 | } |
zdenka | 0:97ddc2168412 | 86 | } |