IQRF Relay Board II – upgrade to DPA


One of my first post on this site was IQRF Relay Board. I made a simple board with shift register and eight relays. All was controlled by IQRF P2P application. Now it is time to make some upgrade, upgrade to DPA and make real IQMESH device. How is it simple? You will see inside…

What you need

  • Coordinator DCTR module inserted into the CK-USB-04.
  • Node DCTR module inserted into Realay Board.
  • Custom DPA handler source code for node DCTR module.
  • CATS (another DCTR module inserted into the another CK-USB-04).

Why do I need a CATS and what is it?

As you know, when you are bonding node, you usually need some push button on the node device. But in our case, there is no push button on relay board. So, what we can do? We can use CATS (Configurator, Analyzer, Tester and Scanner). It is wonderful tool for servicing your IQMESH net, and DCTRs. It allows you remote setup, bonding, unbonding, and more. For detailed description, please follow this video tutorial:

Custom DPA Handler

DPA allows you to modify functionality of DCTRs. It means, you can write your own functions for internal or external peripherals, your own data processing functions and so on. You can have your own custom DPA handler in both, coordinator and node modules. In our case, this new function will be shift register driver for node module. If you have no experience with Custom DPA Handler, please follow this video tutorial:

As a base for our code, we can use CustomDpaHandler-Template.c file from Applications\DPA\Custom-handler-examples\ path of IQRF Startup Package. Please follow this steps:

1. Insert definitions under line with #include “DPAcustomHandler.h”. We will use this definitions later.

// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// port definition
#define	MR_SET		LATA.0 = 1
#define	MR_CLR		LATA.0 = 0

#define	OE_SET		LATC.4 = 1
#define	OE_CLR		LATC.4 = 0

#define	CLK_SET		LATC.6 = 1
#define	CLK_CLR		LATC.6 = 0

#define	DATA_SET	LATC.5 = 1
#define	DATA_CLR	LATC.5 = 0

#define	STROBE_SET	LATC.3 = 1
#define	STROBE_CLR	LATC.3 = 0

// relay mapping
#define RE1			2
#define RE2			1
#define RE3			4
#define RE4			8
#define RE5			64
#define RE6			128
#define RE7			32
#define RE8			16

void SR74HC595_SendByte(uns8 data);

2. Modify DpaEvent_Reset case. This part of code will be executed only once after TR reset:

    case DpaEvent_Reset:
      // Called after module is reset
        TRISA.0 = 0;        // Pin 1 = MR (output)
        TRISC.6 = 0;        // Pin 5 = CLK (output)
        TRISB.4 = 1;        // paralel pin (input)
        TRISA.5 = 1;        // paralel pin (input)
        TRISC.3 = 0;        // Pin 6 = STROBE (output)
        TRISC.4 = 0;        // Pin 7 = OE (output)
        TRISC.5 = 0;        // Pin 8 = DATA (output)
        TRISC.7 = 1;        // paralel pin (input)
        OE_SET;             // output at 3rd state
        CLK_CLR;            // data at zero
        DATA_CLR;           // clk at zero
        STROBE_CLR;         // strobe at zero
        MR_CLR;             // clear data register
        STROBE_SET;         // storbe it out
        OE_CLR;            // enable outputs
      //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding

Modify Peripheral Enumeration part:

// Peripheral enumeration
if ( IsDpaEnumPeripheralsRequest() )
	_DpaMessage.EnumPeripheralsAnswer.UserPerNr = 1; // ?
	_DpaMessage.EnumPeripheralsAnswer.HWPID = 0x000F; // ????
	_DpaMessage.EnumPeripheralsAnswer.HWPIDver = 0xabcd; // ????
	goto DpaHandleReturnTRUE;

Modify information about peripherals…

// Get information about peripheral
  else if ( IsDpaPeripheralInfoRequest() )
	if ( _PNUM == PNUM_USER + 0 ) // ?
	  _DpaMessage.PeripheralInfoAnswer.PerT = PERIPHERAL_TYPE_USER_AREA; // PERIPHERAL_TYPE_?
	  _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ?
	  _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ?
	  goto DpaHandleReturnTRUE;

…and insert command handler for selected peripheral:

        // Handle peripheral command
        if ( _PNUM == PNUM_USER + 0 ) // ?

            // Check command
            if ( _PCMD != 0 )
                DpaApiReturnPeripheralError( ERROR_PCMD );

            // Check data length
            if ( _DpaDataLength != 1 )
                DpaApiReturnPeripheralError( ERROR_DATA_LEN );
            goto DpaHandleReturnTRUE;

This part of code checks, if requested periphery is your user periphery, checks the command number and data length and then will send received byte to the shift register.

The last part of the code is SR74HC595_SendByte function, please insert your own functions at the end of source code of Custom DPA Handler.

// fill 74HC595 and strobe it out
void SR74HC595_SendByte(uns8 data) 
    uns8 i;
    uns8 mask = 1;
    for (i=0; i<8; i++)
        if (data & mask)    // set data against the mask
        waitDelay(1);        // shift it 
        mask = mask << 1;
    STROBE_SET;        // strobe it out

It is good idea to realize, that all this work is about 5 minutes or less. All you need to do is copy and paste part of source code from previously published source code to correct parts of Custom DPA Handler source code.

Full source code is attached at the end of article.

Coordiantor and Node modules.

I will assume, you have some experience with DPA from my previous posts. So in this case, it is not important to explain how make a Coordinator and Node DCTR modules.  Now I will assume, you are using DCTRs, not TRs, so please do not use Demo-HWP files. Use the General-HWP files. Do not forget to have Custom DPA Handler option checked for Node.



If you have coordinator and node module finished, you can test them. Insert coordinator module into the CK-EVAL-04 and node module into the Relay Board. Use another one CK-EVAL and another one TR module for CATS. We will use two IQRF IDE windows: Coordinator window and CATS window.

  1. Show CATS window and select correct CK-USB-04 in the Device Manager.
  2. Make a new project, this will allow you to use CATS Service Tools.
  3. Run the Tools→CATS Service Tools→CATS Control.
  4. Insert TR module into the CATS CK-USB-04.
  5. Click on the Create CATS button.
  6. Your CATS is created.

Bonding Relay Board node:

  1. Show CATS window →DPA Service tab and click on the Connect button.
  2. Power-up Relay Board.
  3. Your node DCTR module should be connected to the CATS.
  4. Now are able co control node device wirelessly.
  5. Show the Coordinator window and try to bond node device.
  6. Now show the CATS window and click on the Bond button.
  7. Your node should be bonded.
  8. Disconnect CATS from your node.
  9. You can close CATS window.

Now you are able to control Relay Board. Use this DPA packet:

  • NADR: 0x0001
  • PNUM: 0x20
  • PCMD: 0x00
  • HWPID: 0x000F or 0xFFFF


  • 0x02 – Relay 1
  • 0x01 – Relay 2
  • 0x04 – Relay 3
  • 0x08 – Relay 4
  • 0x40 – Relay 5
  • 0x80 – Relay 6
  • 0x20 – Relay 7
  • 0x10 – Relay 8
  • Combination


Download Attachments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.