Computing stuff tied to the physical world

Next MPS challenge: the radio

Now that the radio has been added and power-up logic implemented, we will need some new code to try it out. It can be found on GitHub as mps/2-radio.

Here is the essential part of the logic in this code:

// GPREG0 is saved across deep power-downs, starts as 0 on power-up reset    
switch (LPC_PMU->GPREG0++) {                                                 

    case 0: // do nothing, just let the energy levels build up               
        LPC_WKT->COUNT = 30000;         // sleep 3 sec                       
        break;                                                               

    case 1: // turn on power to the radio                                    
        LPC_GPIO_PORT->DIR0 |= 1<<1;    // PIO0_1 is an output
        LPC_GPIO_PORT->B0[1] = 0;       // low turns on radio power

        LPC_WKT->COUNT = 100;           // sleep 10 ms
        break;                                                               

    case 2: // initialise the radio and put it to sleep
        // disable SWCLK/SWDIO and RESET
        LPC_SWM->PINENABLE0 |= (3<<2) | (1<<6);
        // lpc810: sck=3p3, ssel=4p2, miso=2p4, mosi=5p1
        LPC_SWM->PINASSIGN3 = 0x03FFFFFF;   // sck  -    -    -
        LPC_SWM->PINASSIGN4 = 0xFF040205;   // -    nss  miso mosi

        rf.init(61, 42, 8683);          // node 61, group 42, 868.3 MHz
        rf.sleep();

        LPC_WKT->COUNT = 10000;         // sleep 1 sec                       
        break;                                                               

    default: // send out one packet and go back to sleep                     
        rf.send(0, "xyz", 3);                                                
        rf.sleep();

        LPC_WKT->COUNT = 100000;        // sleep 10 sec                      
        break;                                                               
}                                                                            

This relies on the fact that some registers in the LPC8xx will retain their value across deep power-down resets. In this case, GPREG0 is used as a sequence number to step through the different phases of the code each time the µC wakes up and starts running from scratch.

The frequency choice of 868.3 MHz is within the allocated 868 MHz band, which runs from 868.0 to 868.6 MHz. Note that picking different frequencies is a simple way to avoid collisions, but the choices are limited, since each choice will occupy a range (depending on the transmitter frequency shift settings and the receiver filter bandwidth, e.g. ≈ 100 KHz).

At the end of the day, all nodes on the same frequency will compete for their frequency use on the air. Even if a transmission is not intended for us or has a different modulation that we couldn’t possibly decode, it still occupies the band (radio is a broadcast mechanism!). The 868 MHz ISM band has as rule that each node transmit at most 1% of the the time, so that the chance of a collision (more than one node transmitting at the same time) is low.

[Back to article index]