CYALKIT-E02 Solar-Powered BLE Sensor Beacon Reference Design Kit Guide, Doc. No. 002-11317 Rev. *C
61
5.2.3.4 I
2
C Start, Read Sensor Data and BLE Advertisement
Along with BLE start, the WDT counter is configured for periodic interrupts to run the I
2
C state machine. This state machine
initiates I
2
C as well as reads the data from the sensor to send it as part of the advertisement (ADV) packet. Also,
CyBle_ProcessEvents() is called to process BLE events.
After I
2
C is started, the next state sends the temperature or humidity data request, and then the system goes back to deep
sleep. After sensor data is requested, temperature or humidity data is read, and the system goes back to deep sleep again.
Upon WDT interrupt, the system wakes up and the ADV packet is updated with the new data. Also, the GAP advertisement is
started so that the new ADV packet can be transmitted by BLE.
void
BLE_AppEventHandler(
uint32
event,
void
* eventParam)
{
(
void
)eventParam;
switch
(event)
{
case
CYBLE_EVT_STACK_ON:
/* This event is received when component is Started. */
/* Read user configuration and apply.
* ReadAndApplyConfig() must be invoked in the case of
* CYBLE_EVT_STACK_ON. */
ReadAndApplyConfig(&interval, &Sensor_Flag);
restartadvertisement =
true
;
CySysWdtUnlock();
/*Unlock the WDT registers for modification*/
CySysWdtWriteMode
(
SOURCE_COUNTER
,
CY_SYS_WDT_MODE_INT
);
CySysWdtWriteClearOnMatch
(
SOURCE_COUNTER
,
COUNTER_ENABLE
);
CySysWdtWriteMatch
(
SOURCE_COUNTER
,
COUNT_PERIOD_1S
);
CySysWdtEnable(
CY_SYS_WDT_COUNTER0_MASK
);
CySysWdtLock();
break
;
default
:
break
;
}
}