AnsweredAssumed Answered

Transmission of an int with NDEF (NHS3152)

Question asked by Achraf Kabbabi on Nov 18, 2018
Latest reply on Nov 23, 2018 by Dries Moors

Hi everybody,

 

I am using a NHS3152 and I want to readout the analog values of an external resistor connected between the pins ANA0_0 and VSS (in "real-time", let's say 100Hz) and transmit it through a NDEF message.

 

I am trying first to test the NFC transmission before implementing the readout of the sensor.

I'm sending a simple integer for testing : int adcInput=123456789;

 

Here is my code in LPCXpresso :

 

#include "board.h"
#include "ndeft2t/ndeft2t.h" // For NFC communication : NDEF messages
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


int main(void)
{
Board_Init();

// 1. ADC Single-shot

// int adcInput;
// Chip_ADCDAC_Init(NSS_ADCDAC0);
// Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_0, IOCON_FUNC_1);
// Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO_ANA0_0);
// Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0, ADCDAC_INPUTRANGE_WIDE);
// Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_SINGLE_SHOT);

// // Readout ADC
// Chip_ADCDAC_StartADC(NSS_ADCDAC0);
// while (!(Chip_ADCDAC_ReadStatus(NSS_ADCDAC0) & ADCDAC_STATUS_ADC_DONE)) {
// ; /* Wait until measurement completes. For single-shot mode only! */
// }
// adcInput = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);

 

int adcInput=123456789;

 

// 2. Conversion int to hexadecimal string
char str_adcInput[16];
itoa(adcInput, str_adcInput, 10);

 

// 3. Sending the NDEF message to the common memory
uint8_t instanceBuffer[NDEFT2T_INSTANCE_SIZE] __attribute__((aligned (4)));
uint8_t messageBuffer[NFC_SHARED_MEM_BYTE_SIZE ] __attribute__((aligned (4)));
NDEFT2T_CREATE_RECORD_INFO_T createRecordInfo;
uint8_t locale[] = "en";
uint8_t payloadText[16];
strcpy((char *)payloadText,(const char *)str_adcInput);
/* Ensure initialization of the NFC HW block is done first. This needs to be done only once.
* Any previously written NDEF message will be lost as the NFC shared memory will be re-initialized.
*/
Chip_NFC_Init(NSS_NFC);
NDEFT2T_Init(); /* Required once, not for every message creation or parsing. */
NDEFT2T_CreateMessage((void*)instanceBuffer, messageBuffer, NFC_SHARED_MEM_BYTE_SIZE, true);
createRecordInfo.shortRecord = 1; /* Enable Short record */
createRecordInfo.pString = locale;
if (NDEFT2T_CreateTextRecord((void*)instanceBuffer, &createRecordInfo)) {
/* The payload length to pass excludes the NUL terminator. */
if (NDEFT2T_WriteRecordPayload((void*)instanceBuffer, payloadText, sizeof(payloadText) - 1)) {
NDEFT2T_CommitRecord((void*)instanceBuffer);
}
}
NDEFT2T_CommitMessage((void*)instanceBuffer);

return 0;
}

 

I get the following readout on MATLAB using an Adafruit PN532 (programmed with an arduino using the script ntag2xx_read):

 

Hello!

Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
Found an ISO14443A card
UID Length: 7 bytes
UID Value: 0x04 0x23 0xC0 0x00 0x62 0x0B 0x04

Seems to be an NTAG2xx tag (7 byte UID)
PAGE 00: 04 23 C0 6F .#⸮o
PAGE 01: 00 62 0B 04 .b..
PAGE 02: 6D 48 07 00 mH..
PAGE 03: E1 11 42 00 ⸮.B.
PAGE 04: 01 03 E8 0E ..⸮.
PAGE 05: 46 FD 01 00 F⸮..
PAGE 06: 03 16 D1 01 ..⸮.
PAGE 07: 12 54 02 65 .T.e
PAGE 08: 6E 31 32 33 n123
PAGE 09: 34 35 36 37 4567
PAGE 10: 38 39 00 34 89.4
PAGE 11: A9 D7 EB 98 ⸮⸮⸮
PAGE 12: FE 54 07 7D ⸮T.}
PAGE 13: 44 ED 2D F4 D⸮-⸮
PAGE 14: 17 CC 1C 05 .⸮..
PAGE 15: 9A BE E1 43 ⸮⸮⸮C
PAGE 16: 69 FF DB 73 i⸮⸮s
PAGE 17: 4D FD F5 7C M⸮⸮|
PAGE 18: 75 3F 9B 53 u?⸮S
PAGE 19: 96 95 5A 4A ⸮⸮ZJ
PAGE 20: 81 7F 0F 6E ⸮.n
PAGE 21: 8E 9B BE 42 ⸮⸮⸮B
PAGE 22: 6C FE ED F0 l⸮⸮⸮
PAGE 23: C5 B0 02 2B Ű.+
PAGE 24: E7 A7 6D D0 ⸮m⸮
PAGE 25: 6B CC 82 97 k̂⸮
PAGE 26: 16 AF 48 11 .⸮H.
PAGE 27: 57 EA 0C 6F W⸮.o
PAGE 28: E9 32 20 DF ⸮2 ⸮
PAGE 29: E3 79 8C E5 ⸮y⸮⸮
PAGE 30: 53 12 DE EA S.⸮⸮
PAGE 31: B7 BB C6 50 ⸮⸮⸮P
PAGE 32: E7 BC A2 B1 缢⸮
PAGE 33: B2 B6 22 B5 ⸮⸮"⸮
PAGE 34: 78 3E A4 76 x>⸮v
PAGE 35: 3F 58 C8 0B ?X⸮.
PAGE 36: 2F 71 AA C5 /q⸮⸮
PAGE 37: 26 2D A8 5D &-⸮]
PAGE 38: 2A D2 09 6D *⸮.m
PAGE 39: 81 D8 DD 89 ⸮⸮݉
PAGE 40: A7 B9 FF BB ⸮⸮⸮⸮
PAGE 41: 72 D2 AE DB rҮ⸮

 

So I can successfully transmit the integer I want 123456789, and I'm happy with that, but I'm not sure that this is how it would be done practically for my goal : Readout of external resistor value at about 100Hz.

I bought the NHS3152 chip because it is able in principle to transmit data at a datarate of 106 kb/s so I'd like to optimize my way of doing the readout.

 

So here are my questions, if someone can help :

1. Is wanting a 100 Hz readout possible using NDEF messages ? Because as I see from PAGE 00 to PAGE 41 there is a lot of "junk" information I don't need for my project. By the way I don't know how much time it takes for the 41 pages to be read, that would be a nice information to have.

 

2. Is there a smarter way to do that ? An int is supposed to be 4 bytes

 

3. (This is more a C/C++ question) I arbitrarily put 16 as the size of the char array : char str_adcInput[16]; and uint8_t payloadText[16]; This implies "junk" information after the "123456789" (it is quite random, for instance I read "1234567894???" on my phone using an Android NFC reader, the "4???" shouldn't be there).

What size should I put instead of 16 ? sizeof(int) or 4*sizeof(int) (or something else) ? (I know an int is 4 bytes but I don't know if we specify in bits of bytes)

 

Thank you for reading this post, any help is welcome !

 

Best,

Achraf

Outcomes