Example for using the MAX1472 RF Transmitter for low power data transmission.

Dependencies:   mbed-dev2 max32630fthr USBDevice

Committer:
MI
Date:
Wed Jan 24 01:15:14 2018 +0000
Revision:
1:8834bc22c2e7
Parent:
0:41ed595f83f5
Child:
2:33b3b46a9c0d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MI 0:41ed595f83f5 1 #include "mbed.h"
MI 0:41ed595f83f5 2 #include "max32630fthr.h"
MI 0:41ed595f83f5 3 #include "mxc_config.h"
MI 0:41ed595f83f5 4 #include "lp.h"
MI 0:41ed595f83f5 5 #include "gpio.h"
MI 1:8834bc22c2e7 6 #include "rtc.h"
MI 1:8834bc22c2e7 7 #include "MAX14690.h"
MI 0:41ed595f83f5 8
MI 0:41ed595f83f5 9 DigitalOut rLED(LED1);
MI 0:41ed595f83f5 10 DigitalOut gLED(LED2);
MI 0:41ed595f83f5 11 DigitalOut bLED(LED3);
MI 0:41ed595f83f5 12
MI 0:41ed595f83f5 13 DigitalIn sw1(SW1);
MI 0:41ed595f83f5 14
MI 0:41ed595f83f5 15 // *****************************************************************************
MI 1:8834bc22c2e7 16 void RTC_Setup()
MI 0:41ed595f83f5 17 {
MI 1:8834bc22c2e7 18 rtc_cfg_t RTCconfig;
MI 0:41ed595f83f5 19
MI 1:8834bc22c2e7 20 RTCconfig.compareCount[0] = 1;//1 second timer
MI 1:8834bc22c2e7 21 RTCconfig.compareCount[1] = 10;//10 second timer
MI 1:8834bc22c2e7 22 RTCconfig.prescaler = RTC_PRESCALE_DIV_2_12; //1Hz clock
MI 1:8834bc22c2e7 23 RTCconfig.prescalerMask = RTC_PRESCALE_DIV_2_12;//used for prescaler compare
MI 1:8834bc22c2e7 24 RTCconfig.snoozeCount = 0;
MI 1:8834bc22c2e7 25 RTCconfig.snoozeMode = RTC_SNOOZE_DISABLE;
MI 0:41ed595f83f5 26
MI 1:8834bc22c2e7 27 RTC_Init(&RTCconfig);
MI 0:41ed595f83f5 28
MI 1:8834bc22c2e7 29 RTC_Start();
MI 0:41ed595f83f5 30 }
MI 0:41ed595f83f5 31
MI 0:41ed595f83f5 32 /******************************************************************************/
MI 0:41ed595f83f5 33 int main(void)
MI 0:41ed595f83f5 34 {
MI 1:8834bc22c2e7 35 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
MI 1:8834bc22c2e7 36
MI 0:41ed595f83f5 37 //check if starting at main because of LP0 wake-up
MI 1:8834bc22c2e7 38 if(LP_IsLP0WakeUp()) {
MI 1:8834bc22c2e7 39
MI 1:8834bc22c2e7 40 }
MI 0:41ed595f83f5 41 else {
MI 0:41ed595f83f5 42 //We did not wake up from sleep and this is first power-on
MI 1:8834bc22c2e7 43 //Only configure RTC the first time around
MI 1:8834bc22c2e7 44 RTC_Setup();
MI 0:41ed595f83f5 45 }
MI 0:41ed595f83f5 46
MI 0:41ed595f83f5 47 gLED = LED_ON;
MI 1:8834bc22c2e7 48 rLED = LED_ON;
MI 1:8834bc22c2e7 49 bLED = LED_ON;
MI 0:41ed595f83f5 50
MI 0:41ed595f83f5 51 while(1) {
MI 1:8834bc22c2e7 52
MI 1:8834bc22c2e7 53 //hold down switch 1 to prevent the microcontroller from going into LP0
MI 1:8834bc22c2e7 54 while(sw1 == 0);
MI 1:8834bc22c2e7 55
MI 1:8834bc22c2e7 56 //keep LED on long enough to see it!
MI 1:8834bc22c2e7 57 wait_ms(100);
MI 1:8834bc22c2e7 58
MI 1:8834bc22c2e7 59 gLED = LED_OFF;
MI 1:8834bc22c2e7 60 rLED = LED_OFF;
MI 1:8834bc22c2e7 61 bLED = LED_OFF;
MI 0:41ed595f83f5 62
MI 1:8834bc22c2e7 63 //disable unused PMIC rails to minimize power consumption
MI 1:8834bc22c2e7 64 pegasus.max14690.ldo2SetMode(MAX14690::LDO_DISABLED);
MI 1:8834bc22c2e7 65 pegasus.max14690.ldo3SetMode(MAX14690::LDO_DISABLED);
MI 1:8834bc22c2e7 66
MI 1:8834bc22c2e7 67 //Clear existing wake-up config
MI 1:8834bc22c2e7 68 LP_ClearWakeUpConfig();
MI 0:41ed595f83f5 69
MI 1:8834bc22c2e7 70 //Clear any event flags
MI 1:8834bc22c2e7 71 LP_ClearWakeUpFlags();
MI 0:41ed595f83f5 72
MI 1:8834bc22c2e7 73 //configure wake-up on RTC compare 0
MI 1:8834bc22c2e7 74 //LP_ConfigRTCWakeUp(enable compare 0, enable compare 1, set prescale, set rollover)
MI 1:8834bc22c2e7 75 LP_ConfigRTCWakeUp(1, 0, 0, 0);
MI 1:8834bc22c2e7 76
MI 1:8834bc22c2e7 77 //read the current RTC timer and add 5 seconds to it
MI 1:8834bc22c2e7 78 uint32_t cmp = RTC_GetCount() + 5;
MI 1:8834bc22c2e7 79
MI 1:8834bc22c2e7 80 //set RTC to generate an interrupt 5 seconds from current value
MI 1:8834bc22c2e7 81 RTC_SetCompare(0,cmp);
MI 1:8834bc22c2e7 82
MI 1:8834bc22c2e7 83 //clear comparison flag in the RTC registers
MI 1:8834bc22c2e7 84 RTC_ClearFlags(MXC_F_RTC_FLAGS_COMP0);
MI 0:41ed595f83f5 85
MI 1:8834bc22c2e7 86 LP_EnterLP0();
MI 1:8834bc22c2e7 87
MI 1:8834bc22c2e7 88 //firmware will reset with no prior knowledge on wake-up
MI 0:41ed595f83f5 89 }
MI 0:41ed595f83f5 90 }