3D Low Frequency Wakeup Receiver
Diff: AS3933.h
- Revision:
- 4:10d482ca4eb1
- Parent:
- 3:2de552c4ffbc
--- a/AS3933.h Wed Mar 07 16:43:51 2018 +0000 +++ b/AS3933.h Tue Mar 13 15:08:21 2018 +0000 @@ -11,7 +11,7 @@ * @version 7/March/2018 The ORIGIN * @pre N/A. * @warning N/A - * @pre This code belongs to Nimbus Centre ( http://unbarquero.blogspot.com ). + * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ). */ #ifndef AS3933_H #define AS3933_H @@ -20,21 +20,24 @@ /** Example: - #include "mbed.h" +#include "mbed.h" #include "AS3933.h" -AS3933 myAS3933 ( PB_5, PB_4, PB_3, PB_8, 1000000 ); // MOSI: PB_5 | MISO: PB_4 | SCLK: PB_3 | CS: PB_8 | FREQ: 1MHz; +AS3933 myAS3933 ( PB_5, PB_4, PB_3, PB_8, 1000000 ); // MOSI: PB_5 | MISO: PB_4 | SCLK: PB_3 | CS: PB_8 | FREQ: 1MHz; Serial pc ( USBTX, USBRX ); -Ticker newReading; -DigitalOut myled(LED1); +DigitalOut myled ( LED1 ); +InterruptIn myWAKEpin ( PA_8 ); +DigitalIn myDATpin ( PC_7 ); +DigitalIn myCLDpin ( PB_9 ); + AS3933::AS3933_status_t aux; AS3933::AS3933_data_t myAS3933Data; uint32_t myState = 0; -void changeDATA ( void ) +void newData ( void ) { myState = 1; } @@ -42,6 +45,10 @@ int main() { + uint32_t myCounterData = 0; + uint32_t myCounterTimeout = 0; + + pc.baud ( 115200 ); myled = 1; @@ -49,20 +56,80 @@ myled = 0; + // AS3933 CONFIGURATION // Clears the wake state of the chip aux = myAS3933.AS3933_Send_DirectCommand ( AS3933::CLEAR_WAKE ); // Sets all register in the default mode aux = myAS3933.AS3933_Send_DirectCommand ( AS3933::PRESET_DEFAULT ); - // Update the wakeup pattern ( default value ) - myAS3933Data.patt1b = 0x23; // Default value: AS3933::TS1_WAKEUP_PATTERN_PATT1B; + myAS3933Data.patt1b = AS3933::TS1_WAKEUP_PATTERN_PATT1B; myAS3933Data.patt2b = AS3933::TS2_WAKEUP_PATTERN_PATT2B; aux = myAS3933.AS3933_SetWakeUpPattern ( myAS3933Data ); - newReading.attach( &changeDATA, 1 ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s ) + // Configure All channels in Listening mode + aux = myAS3933.AS3933_SetLowPowerMode ( AS3933::AS3933_CH1_ON_CH2_ON_CH3_ON, AS3933::AS3933_STANDARD_LISTENING_MODE, ( AS3933::AS3933_r4_t_off_value_t )0 ); + + // Configure Crystal oscillator enabled without output signal displayed on CL_DAT pin + aux = myAS3933.AS3933_SetClockGenerator ( AS3933::EN_XTAL_ENABLED, AS3933::CLOCK_GEN_DIS_DISABLED ); + + // Configure Antenna dumper disabled + aux = myAS3933.AS3933_SetAntennaDamper ( AS3933::ATT_ON_DISABLED, ( AS3933::AS3933_r4_d_res_value_t )0 ); + + // Configure Envelop detector time constant = 4096 symbol rate + aux = myAS3933.AS3933_SetEnvelopDetector ( AS3933::FS_ENV_SYMBOL_RATE_4096 ); + + // Configure Data slicer. Threshold disabled, 2.3ms preamble length + aux = myAS3933.AS3933_SetDataSlicer ( AS3933::ABS_HY_DISABLED, AS3933::FS_SCL_PREAMBLE_LENGTH_2_3 ); + + // Configure Comparator Hysteresis. Both edges, 40mV + aux = myAS3933.AS3933_SetComparatorHysteresis ( AS3933::HY_POS_HYSTERESIS_BOTH_EDGES, AS3933::HY_20M_COMPARATOR_HYSTERESIS_40MV ); + + // Configure Gain reduction, No gain reduction at all + aux = myAS3933.AS3933_SetGainReduction ( AS3933::GR_GAIN_REDUCTION_NO_GAIN_REDUCTION ); + + // Configure Operating frequency range: 95-150 kHz + aux = myAS3933.AS3933_SetOperatingFrequencyRange ( AS3933::BAND_SEL_RANGE_95_150_KHZ ); + + // Configure Frequency detection tolerance: Tight + aux = myAS3933.AS3933_SetFrequencyDetectionTolerance ( AS3933::AS3933_TOLERANCE_TIGHT ); + + // Configure Sensitivity boost: Disabled + aux = myAS3933.AS3933_SetGainBoost ( AS3933::G_BOOST_DISABLED ); + + // Configure AGC: AGC acting only on the first carrier burst is disabled and AGC operating in both direction ( up-down ) + aux = myAS3933.AS3933_SetAGC ( AS3933::AGC_TLIM_DISABLED, AS3933::AGC_UD_UP_DOWN_MODE ); + + // Configure Do mask data before wakeup + aux = myAS3933.AS3933_SetDataMask ( AS3933::DAT_MASK_ENABLED ); + + // Configure Clock Generator: Crystal oscillator enabled, do NOT clock signal on CL_DAT pin + aux = myAS3933.AS3933_SetClockGenerator ( AS3933::EN_XTAL_ENABLED, AS3933::CLOCK_GEN_DIS_DISABLED ); + + // Configure Correlator: Enabled, 16 bit pattern and Manchester decoder enabled + aux = myAS3933.AS3933_SetCorrelator ( AS3933::EN_WPAT_ENABLED, AS3933::PATT32_16_BITS, AS3933::T_HBIT_BIT_RATE_12, AS3933::EN_MANCH_ENABLED ); + + // Configure Automatic Timeout: 50ms + aux = myAS3933.AS3933_SetAutomaticTimeOut ( AS3933::T_OUT_50_MSEC ); + + // Configure Input capacitor bank: NO capacitance in any channels + aux = myAS3933.AS3933_SetParallelTuningCapacitance ( AS3933::AS3933_CHANNEL_LF1P, AS3933::AS3933_CAPACITANCE_ADDS_NONE ); + aux = myAS3933.AS3933_SetParallelTuningCapacitance ( AS3933::AS3933_CHANNEL_LF2P, AS3933::AS3933_CAPACITANCE_ADDS_NONE ); + aux = myAS3933.AS3933_SetParallelTuningCapacitance ( AS3933::AS3933_CHANNEL_LF3P, AS3933::AS3933_CAPACITANCE_ADDS_NONE ); + + // Configure Artificial wakeup: Disabled + aux = myAS3933.AS3933_SetArtificialWakeUp ( AS3933::T_AUTO_NO_ARTIFICIAL_WAKEUP ); + // END AS3933 CONFIGURATION + + + // Read the wakeup pattern + aux = myAS3933.AS3933_GetWakeUpPattern ( &myAS3933Data ); + pc.printf( "PATT1B: %x ( 0x96 ) | PATT2B: %x ( 0x69 )\r\n", myAS3933Data.patt1b, myAS3933Data.patt2b ); + + + myWAKEpin.rise( &newData ); // attach the address of the 'newData' function to the rising edge // Let the callbacks take care of everything while(1) { @@ -71,9 +138,37 @@ myled = 1; if ( myState == 1 ) { - // Read the wakeup pattern - aux = myAS3933.AS3933_GetWakeUpPattern ( &myAS3933Data ); - pc.printf( "PATT1B: %x ( 0x23 ) | PATT2B: %x ( 0x69 )\r\n", myAS3933Data.patt1b, myAS3933Data.patt2b ); + + // Get data ( 8-bits, Manchester ). + // NOTE: Make sure the transmitter is sending data otherwise a little delay will + // be introduced by myCounterTimeout. + // + myAS3933Data.data = 0; + + for ( myCounterData = 0; myCounterData < 8; myCounterData++ ) { + // Wait until rising edges on CLD pin or Timeout + myCounterTimeout = 2323; + while ( ( myCLDpin == 0 ) && ( myCounterTimeout > 0 ) ) { + myCounterTimeout--; + } + + // Process the data + myAS3933Data.data <<= 1; + + if ( myDATpin == 1 ) { + myAS3933Data.data |= 1; + } + + // Wait until CLD pin goes low again or Timeout + myCounterTimeout = 2323; + while ( ( myCLDpin == 1 ) && ( myCounterTimeout > 0 ) ) { + myCounterTimeout--; + } + } + + // Get RSSIs and send all data through the UART + aux = myAS3933.AS3933_GetRSSI ( &myAS3933Data ); + pc.printf( "Data: %x | RSS1: %x | RSSI2: %x | RSSI3: %x\r\n", myAS3933Data.data, myAS3933Data.rssi1, myAS3933Data.rssi2, myAS3933Data.rssi3 ); myState = 0; // Reset the variable }