A few months ago, I published post about DPA .NET Class. This article describes simple, but effective library used for DPA handling by MCU (UART interface). Published library is independent on the MCU family, but it was written for 32-bit ARM processors with Cortex-M3 core and GNU C compiler.
Library consists of two files:
- header file: iqrf_dpa.h
- code file: iqrf_dpa.c
Header file includes many useful definitions. Also there are defined two new data types:
// DPA message structure typedef struct { uint16_t NADR; // Node address uint8_t PNUM; // Peripheral number uint8_t PCMD; // Peripheral command uint16_t HWPID; // Hardware profile ID uint8_t *pData; // Data pointer uint8_t Dlen; // Data length } DPAparams_t; |
This structure describes DPA parameters. You can use this structure for simple DPA packet initialisation and changes.
typedef struct { uint8_t *pData; // Data pointer uint8_t DataLen; // Index of data array uint8_t DataMax; // Max buffer boundary uint8_t EcapeFlag; } DPAbufer_t; |
This structure is used for definition of input and output buffers.
- *pData is pointer to byte data array, where incoming or outgoing data are stored.
- DataLen set or get length of data.
- DataMax specifies max data length.
- EscapeFlag is for library internal use only.
Also there are defined some functions:
- DPA_crc which calculates CRC used by DPA
- Build_DPA_buffer which is used for outgoing data buffer creation (from DPA parameters)
- Process_DPA_buffer which is used for incoming DPA characters processing.
Example of use:
/* This section is done only once */ // DPA Tx buffer DPAbufer_t TX_DPABuffer; uint8_t TX_DPAData [DPA_OUT_BUFFER_LEN]; // DPA params for TX DPAparams_t TX_DPAParams; uint8_t TX_DPAParams_data[64]; // buffers initialisation TX_DPAParams.pData = TX_DPAParams_data; TX_DPABuffer.pData = TX_DPAData; TX_DPABuffer.DataLen = 0; TX_DPABuffer.DataMax = DPA_OUT_BUFFER_LEN; /* This is example how to set hop to 0 */ TX_DPAParams.NADR = 0x00; TX_DPAParams.PNUM = 0x00; TX_DPAParams.PCMD = 0x09; TX_DPAParams.HWPID = 0xFFFF; TX_DPAParams.pData[0] = 0x01; TX_DPAParams.pData[1] = 0x01; TX_DPAParams.Dlen = 0x02; // Create DPA buffer from DPA Params TX_DPABuffer.DataLen = Build_DPA_buffer(TX_DPABuffer.pData, TX_DPAParams); // Send DPA buffer to Coordinator for(i=0;i<TX_DPABuffer.DataLen;i++) USART2Send(TX_DPABuffer.pData[i]); /* DONE */ |
I am going to prepare some advanced examples of use next week.
Both library files are attached.
Enjoy.
.
Dear Sir, regarding the I2C, I used the template and insert all the data for MCP23008. The routines that arein the templates those are by default and must not be modified?
Please, could you write better description of your problem? I am not able understand, what you mean. Thank you.
Pingback: DPA library for MCU – Ráj Bastlířů