PCA9634 (LED driver) driven by DPA

pca964bbheaderSome months ago, I wrote article about PCA9634 LED driver. I made a Breakout Board for this IC and made IQRF application for this board. Now it is time to try make it better – with DPA.

Last week I published post about Custom DPA Handler. We are going to do work in the same way. All you need to do is copy parts of code from P2P application and paste this parts of code to the Custom DPA Handler template . I spent only 5 minutes with this job + 5 minutes with Peripheral commands handler.

This part of source code shows peripheral handler. There are two commands:

  • “0” for Write Register
  • “1” for Read Register
// Handle peripheral command
if ( _PNUM == PNUM_USER + 0 ) // ?
{
    // Check command
    if ( _PCMD == 0 )
    {
        // Check data length
        if ( _DpaDataLength != 2 )
            DpaApiReturnPeripheralError( ERROR_DATA_LEN );
        PCA9634_WriteReg(_DpaMessage.Response.PData[0],_DpaMessage.Response.PData[1]);
        goto DpaHandleReturnTRUE;
    }
            
    if ( _PCMD == 1 )
    {
        // Check data length
        if ( _DpaDataLength != 1 )
            DpaApiReturnPeripheralError( ERROR_DATA_LEN );
        _DpaMessage.Response.PData[0] = PCA9634_ReadReg(_DpaMessage.Response.PData[0]);
        _DpaDataLength = 1;
        goto DpaHandleReturnTRUE;
    }        
            
    DpaApiReturnPeripheralError( ERROR_PCMD );         
}

 

DPA packet for testing

You can test the device with this Write Register DPA packet:

  • NADR: 0x0001
  • PNUM: 0x20
  • PCMD: 0x00 (Write Register)
  • HWPID: 0x000F or 0xFFFF
  • DATA: REGISTER_ADDRESS
  • DATA: REGISTER_DATA

And Read Register DPA packet:

  • NADR: 0x0001
  • PNUM: 0x20
  • PCMD: 0x01 (Read Register)
  • HWPID: 0x000F or 0xFFFF
  • DATA: REGISTER_ADDRESS

This will send the register value in DPA Response.

 

Examples:

request

pca9634dpa1

result

pca9634scope


request

pca9634dpa2

result

pca9634dpa3

Full source code is attached

Download Attachments

Leave a Reply

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