indx = 0;
printf(“SR,32000000\r\n”);
//set as Peripheral and enable MLDP
__delay_ms(500);
if(EUSART_DataReady)
{
do{
rxBuf[indx++] = EUSART_Read();
}while(EUSART_DataReady);
}
}
The RN4020 will respond with AOK if the peripheral/
MLDP command was successfully issued. Upon receipt of
the AOK message, we will perform an RN4020 reboot:
if(rxBuf[0] == ‘A’ && \
rxBuf[1] == ‘O’ && \
rxBuf[2] == ‘K’)
{
indx = 0;
printf(“R,1\r\n”); //reboot command
__delay_ms(1000);
if(EUSART_DataReady)
{
do{
rxBuf[indx++] = EUSART_Read();
}while(EUSART_DataReady);
}
}
if(rxBuf[0] == ‘R’ && \
rxBuf[1] == ‘e’ && \
rxBuf[2] == ‘b’ && \
rxBuf[3] == ‘o’ && \
rxBuf[4] == ‘o’ && \
rxBuf[5] == ‘t’)
{
indx = 0;
__delay_ms(1000);
if(EUSART_DataReady)
{
do{
rxBuf[indx++] = EUSART_Read();
}while(EUSART_DataReady);
December 2015 59
■ Photo 6. The Sniffer is based on the Nordic
Semiconductor nRF51822.
■ Screenshot 5. This is a Wireshark capture of our
Curiosity development board’s RN4020 advertisement.
Advertising Address field. The actual data is highlighted in
the hex dump at the bottom of Screenshot 5.
Generating a Central
}
if(rxBuf[0] == ‘C’ && \
rxBuf[1] == ‘M’ && \
rxBuf[2] == ‘D’)
{
// RN4020 is ONLINE at this point
}
The comment “// RN4020 is ONLINE at this point”
says it all.
But, Does It Work?
Now that we have a Peripheral (Slave), we can use
most of the peripheral code to generate a Central
(Master). The first order of business is to create a new
project. I called it rn4020Central. I used the Code
Configurator to generate the code for our new Central
project. The newly generated code is identical to our
original rn4020DesignCycle peripheral project with the
exception of the GPIO setup. The new project GPIO
setup is shown in Screenshot 6.
I happen to have a Bluetooth Smart Sniffer on the
EDTP bench. The Bluetooth Smart Sniffer hardware is
under the lights in Photo 6. The Sniffer passes packets to
We will need to configure the RN4020 click module
as a Central. To do this, we simply change the role value
in our original peripheral code:
Wireshark. If our RN4020 driver worked, the RN4020
should be “advertising” and Wireshark should be picking
that up. It works. Take a look at Screenshot 5. The proof
of concept is revealed in the Wireshark capture’s
if(rxBuf[0] == ‘C’ && \
rxBuf[1] == ‘M’ && \
rxBuf[2] == ‘D’)
{
indx = 0;
printf(“SR,92000000\r\n”);
//set as Central and enable MLDP