Hello,
I am trying to use NHS3152 DEMO BOARD to read a resistance.
The program works fine except an issue with the scale.
I am now want to flash the program onto the NHS3152 DEMO board's chip, so that it can run without being connected to the PC and LPC-LINK2.
I am doing the following:
1. Press flash icon and connect to emulator --> press OK
It opens Program Flash using LPC-LINK2 CMSIS-DAP V5.173
I chose:
Options:
- Display progress log
- Run flash command and copy to clipboard
Connect sctrip: ISPRestetConnect.scp
Flash driver: NSS_20k_8k_IAP.cfx
program flash memory
select file: ...\DAC_ADC_toghether.axf (see code at end of Quesiton)
Erase Option: Mass erase

And pressed OK.
I get the following message out:
Nc:verify offset 0x2400/0x45B0[0x400/0x400]
Ps: ( 57) at 00002400: 1024 bytes - 10240/17840
Nc:verify offset 0x2800/0x45B0[0x400/0x400]
Ps: ( 63) at 00002800: 1024 bytes - 11264/17840
Nc:verify offset 0x2C00/0x45B0[0x400/0x400]
Ps: ( 68) at 00002C00: 1024 bytes - 12288/17840
Nc:verify offset 0x3000/0x45B0[0x400/0x400]
Ps: ( 74) at 00003000: 1024 bytes - 13312/17840
Nc:verify offset 0x3400/0x45B0[0x400/0x400]
Ps: ( 80) at 00003400: 1024 bytes - 14336/17840
Nc:verify offset 0x3800/0x45B0[0x400/0x400]
Ps: ( 86) at 00003800: 1024 bytes - 15360/17840
Nc:verify offset 0x3C00/0x45B0[0x400/0x400]
Ps: ( 91) at 00003C00: 1024 bytes - 16384/17840
Nc:verify offset 0x4000/0x45B0[0x400/0x400]
Ps: ( 97) at 00004000: 1024 bytes - 17408/17840
Nc:verify offset 0x4400/0x45B0[0x1B0/0x400]
Ps: (100) at 00004400: 1024 bytes - 18432/17840
Nt: Erased/Wrote page 0-17 with 17840 bytes in 6667msec
Pb: (100) Finished writing Flash successfully.
Nt: Flash Write Done
Nt: Loaded 0x45B0 bytes in 7358ms (about 2kB/s)
At this point however if i bring the phone into the NFC range it reads:
"Tag is empty or phone is not aligned" instead of the expected "res value is.. "
The program works since if I run it via Debug session it runs. but even here if i disconnect the LPClink2 I get the same "tag is empty" message.
Here is the code i am running:
It essentially displays a message with the resistance when the field is present.
/*
FROM https://community.nxp.com/t5/NFC/Measure-resistance-NHS3152/m-p/831045
1. Set the configuration of the analog pins to IOCON_FUNC_1
2. Connect the DAC to ANA1, set a continuous conversion of 1.25V.
3. Connect the I2D to ANA4, configure correctly and start a conversion. Only when a conversion is started, current will start flowing over your resistor. The current will continue to flow when the conversion ends. -> a
4. Connect the ADC to ANA4, and measure the voltage. -> v4
5. Connect the ADC to ANA1, and measure the voltage. -> v1
*/
/* ------------------------------------------------------------------------- */
#include <string.h>
#include <stdlib.h>
#include <stdio.h> // contains sprintf function (needs to be included to avoid : https://stackoverflow.com/questions/8440816/warning-implicit-declaration-of-function
#include "board.h"
#include "ndeft2t/ndeft2t.h"
/* ------------------------------------------------------------------------- */
#define LOCALE "en" /**< Language used when creating TEXT records. */
#define MIME "nhs31xx/example.ndef" /**< Mime type used when creating MIME records. */
/** The URL will be used in a single-record NDEF message. */
#define MAX_URI_PAYLOAD (254 - NDEFT2T_MSG_OVERHEAD(true, NDEFT2T_URI_RECORD_OVERHEAD(true)))
static const uint8_t sUrl[MAX_URI_PAYLOAD + 1 /* NUL */] = "nxp.com/NTAGSMARTSENSOR";
/**
* The text and the MIME data are always presented together, in a dual-record NDEF message.
* Payload length is split evenly between TEXT and MIME.
*/
#define MAX_TEXT_PAYLOAD (254 - (NDEFT2T_MSG_OVERHEAD(true, \
NDEFT2T_TEXT_RECORD_OVERHEAD(true, sizeof(LOCALE) - 1) + \
NDEFT2T_MIME_RECORD_OVERHEAD(true, sizeof(MIME) - 1)) / 2))
static uint8_t sText[MAX_TEXT_PAYLOAD] = "10 V1-V4";
/** @copydoc MAX_TEXT_PAYLOAD */
#define MAX_MIME_PAYLOAD MAX_TEXT_PAYLOAD
static uint8_t sBytes[MAX_MIME_PAYLOAD] = {0, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE};
/* ------------------------------------------------------------------------- */
/**
* Used to determine which NDEF message must be generated.
* - @c true: generate a single-record NDEF message containing a URL.
* - @c false: generate a dual-record NDEF message containing a TEXT and a MIME record.
*/
static bool sState;
static volatile bool sButtonPressed = false; /** @c true when the WAKEUP button is pressed on the Demo PCB */
static volatile bool sMsgAvailable = false; /** @c true when a new NDEF message has been written by the tag reader. */
static volatile bool sFieldPresent = false; /** @c true when an NFC field is detected and the tag is selected. */
static void GenerateNdef_Url(void);
static void GenerateNdef_TextMime(void);
static void ParseNdef(void);
/* ------------------------------------------------------------------------- */
//Store adc_1, adc_4, current and resistance value
static volatile float adcInput_4 = 5.0; // 4. store V input 4
static volatile float adcInput_1 = 5.0; // 5. store V input 1
static volatile int current_native; // 3. store I2D ana 4
static volatile int current_picoampere; // 3. store I2D ana4
static volatile double resval = -1; // store resistance calculated: (dcInput_1-adcInput_4)/Current_picoampere*10e-6
static void adcdac_nss_example_1(void); //continuous DAC ana1
static void i2d_nss_example_1(void); //I2D ana4
static void adcdac_nss_example_3(void); //NEW single shot get ADC value ana4
static void adcdac_nss_example_3_2(void); //NEW single shot get ADC value ana1
/**
* Handler for PIO0_0 / WAKEUP pin.
* Overrides the WEAK function in the startup module.
*/
void PIO0_IRQHandler(void)
{
Chip_GPIO_ClearInts(NSS_GPIO, 0, 1);
sButtonPressed = true; /* Handled in main loop */
}
/**
* Called under interrupt.
* @see NDEFT2T_FIELD_STATUS_CB
* @see pNdeft2t_FieldStatus_Cb_t
*/
void App_FieldStatusCb(bool status)
{
if (status) {
LED_On(LED_RED);
}
else {
LED_Off(LED_RED);
}
sFieldPresent = status; /* Handled in main loop */
}
/**
* Called under interrupt.
* @see NDEFT2T_MSG_AVAILABLE_CB
* @see pNdeft2t_MsgAvailable_Cb_t
*/
void App_MsgAvailableCb(void)
{
sMsgAvailable = true; /* Handled in main loop */
}
/* ------------------------------------------------------------------------- */
/** Generates a single-record NDEF message containing a URL, and copies it to the NFC shared memory. */
static void GenerateNdef_Url(void)
{
uint8_t instance[NDEFT2T_INSTANCE_SIZE];
uint8_t buffer[NFC_SHARED_MEM_BYTE_SIZE];
NDEFT2T_CREATE_RECORD_INFO_T recordInfo = {.pString = NULL /* don't care */,
.shortRecord = true,
.uriCode = 0x01 /* "http://www." */};
NDEFT2T_CreateMessage(instance, buffer, NFC_SHARED_MEM_BYTE_SIZE, true);
if (NDEFT2T_CreateUriRecord(instance, &recordInfo)) {
if (NDEFT2T_WriteRecordPayload(instance, sUrl, (int)strlen((char *)sUrl))) {
NDEFT2T_CommitRecord(instance);
}
}
NDEFT2T_CommitMessage(instance); /* Copies the generated message to NFC shared memory. */
}
/** Generates a dual-record NDEF message containing a TEXT and a MIME record, and copies it to the NFC shared memory. */
static void GenerateNdef_TextMime(void)
{
uint8_t instance[NDEFT2T_INSTANCE_SIZE];
uint8_t buffer[NFC_SHARED_MEM_BYTE_SIZE];
NDEFT2T_CREATE_RECORD_INFO_T textRecordInfo = {.pString = (uint8_t *)"en" /* language code */,
.shortRecord = true,
.uriCode = 0 /* don't care */};
NDEFT2T_CREATE_RECORD_INFO_T mimeRecordInfo = {.pString = (uint8_t *)MIME /* mime type */,
.shortRecord = true,
.uriCode = 0 /* don't care */};
NDEFT2T_CreateMessage(instance, buffer, NFC_SHARED_MEM_BYTE_SIZE, true);
if (NDEFT2T_CreateTextRecord(instance, &textRecordInfo)) {
if (NDEFT2T_WriteRecordPayload(instance, sText, sizeof(sText) - 1 /* exclude NUL char */)) {
NDEFT2T_CommitRecord(instance);
}
}
if (NDEFT2T_CreateMimeRecord(instance, &mimeRecordInfo)) {
if (NDEFT2T_WriteRecordPayload(instance, sBytes, sizeof(sBytes))) {
NDEFT2T_CommitRecord(instance);
}
}
NDEFT2T_CommitMessage(instance); /* Copies the generated message to NFC shared memory. */
}
/** Parses the NDEF message in the NFC shared memory, and copies the TEXT and MIME payloads. */
static void ParseNdef(void)
{
uint8_t instance[NDEFT2T_INSTANCE_SIZE];
uint8_t buffer[NFC_SHARED_MEM_BYTE_SIZE];
NDEFT2T_PARSE_RECORD_INFO_T recordInfo;
int len = 0;
uint8_t *pData = NULL;
if (NDEFT2T_GetMessage(instance, buffer, NFC_SHARED_MEM_BYTE_SIZE)) {
while (NDEFT2T_GetNextRecord(instance, &recordInfo) != false) {
pData = (uint8_t *)NDEFT2T_GetRecordPayload(instance, &len);
switch (recordInfo.type) {
case NDEFT2T_RECORD_TYPE_TEXT:
if ((size_t)len <= MAX_TEXT_PAYLOAD) {
memcpy(sText, pData, (size_t)len);
memset(sText + len, 0, MAX_TEXT_PAYLOAD - (size_t)len);
}
break;
case NDEFT2T_RECORD_TYPE_MIME:
if ((size_t)len <= MAX_MIME_PAYLOAD) {
memcpy(sBytes, pData, (size_t)len);
memset(sBytes + len, 0, MAX_MIME_PAYLOAD - (size_t)len);
}
break;
default:
/* ignore */
break;
}
}
}
}
// 1. Set the configuration of the analog pins to IOCON_FUNC_1
// 2. Connect the DAC to ANA1, set a continuous conversion of 1.25V.
void adcdac_nss_example_1(void) // Modified IOCON_ANA0_0 --> IOCON_ANA0_1 & ADCDAC_IO_ANA0_0 --> ADCDAC_IO_ANA0_1
{
//! [adcdac_nss_example_1]
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_1, IOCON_FUNC_1); // IOCON_FUN_1
Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxDAC(NSS_ADCDAC0, ADCDAC_IO_ANA0_1);
Chip_ADCDAC_SetModeDAC(NSS_ADCDAC0, ADCDAC_CONTINUOUS);
Chip_ADCDAC_WriteOutputDAC(NSS_ADCDAC0, 3000);
//! [adcdac_nss_example_1]
}
/* ------------------------------------------------------------------------- */
// 3. Connect the I2D to ANA4, configure correctly and start a conversion. Only when a conversion is started, current will start flowing over your resistor. The current will continue to flow when the conversion ends. -> a
// FROM i2d_nss_example_1
void i2d_nss_example_1(void)
{
//! [i2d_nss_example_1]
int i2dValue;
int i2dNativeValue;
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_4, IOCON_FUNC_1); // IOCON_FUN_1
Chip_I2D_Init(NSS_I2D);
Chip_I2D_Setup(NSS_I2D, I2D_SINGLE_SHOT, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_LOW, 100);
Chip_I2D_SetMuxInput(NSS_I2D, I2D_INPUT_ANA0_4);
Chip_I2D_Start(NSS_I2D);
while (!(Chip_I2D_ReadStatus(NSS_I2D) & I2D_STATUS_CONVERSION_DONE)) {
; /* wait */
}
i2dNativeValue = Chip_I2D_GetValue(NSS_I2D);
i2dValue = Chip_I2D_NativeToPicoAmpere(i2dNativeValue, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_HIGH, 100);
Chip_I2D_DeInit(NSS_I2D);
//! [i2d_nss_example_1]
current_native = i2dNativeValue;
current_picoampere = i2dValue;
}
// 4. Connect the ADC to ANA4, and measure the voltage. -> v4
//FROM Example 3 - Single-shot Analog-to-Digital Conversion without IRQ
// The conversion: adc_input_voltage = (native_value * 1.2V) / 2825 + 0.09V
void adcdac_nss_example_3(void) // Modifications: IOCON_ANA0_5--> IOCON_ANA0_4 & converted adcinput_4= (adcInput_4 * 1.2) / 2825 + 0.09
{
//! [adcdac_nss_example_3]
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_4, IOCON_FUNC_1);
//Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO_ANA0_4);
Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0, ADCDAC_INPUTRANGE_WIDE);
Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_SINGLE_SHOT);
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_4 = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);
adcInput_4= (adcInput_4 * 1.2) / 2825 + 0.09; // CONVERSION added line
//! [adcdac_nss_example_3]
}
void adcdac_nss_example_3_2(void) // Modifications: IOCON_ANA0_5--> IOCON_ANA0_1 & converted adcinput_1= (adcInput_1 * 1.2) / 2825 + 0.09
{
//! [adcdac_nss_example_3]
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_1, IOCON_FUNC_1);
//Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO_ANA0_1);
Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0, ADCDAC_INPUTRANGE_WIDE);
Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_SINGLE_SHOT);
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_1 = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);
adcInput_1= (adcInput_1 * 1.2) / 2825 + 0.09; // CONVERSION added line
//! [adcdac_nss_example_3]
}
// MAIN
int main(void)
{
Board_Init();
NDEFT2T_Init();
NVIC_EnableIRQ(PIO0_IRQn); /* PIO0_IRQHandler is called when this interrupt fires. */
Chip_GPIO_EnableInt(NSS_GPIO, 0, 1);
// for ever, WHILE field is detected: 2. Connect the DAC to ANA1, set a continuous conversion of 1.25V.
for (;;) {
while (sFieldPresent) {
// 2. Connect the DAC to ANA1 -output Voltage
adcdac_nss_example_1();
// 3. Connect the I2D to ANA4, - read current ana4 through resistor
i2d_nss_example_1();
// 4. Connect the ADC to ANA4, and measure the voltage. ->v4
adcdac_nss_example_3();
// 5. Connect the ADC to ANA1, and measure the voltage. -> v1
adcdac_nss_example_3_2();
// generate the message only once per field???
GenerateNdef_TextMime();
resval = (adcInput_1-adcInput_4)/(current_picoampere * 1e-12); // (v1-v4)/(I4pico * 1e-12) V/I=R [V/A =ohm]
sprintf((char *)sText, "adc_1: %6.2f adc_4: %6.2f current_picoampere: %8.d resistance: %e current_native: %6.d", adcInput_1, adcInput_4,current_picoampere, resval,current_native );//commented in from Thesis, changes payloadText to sText
}
//Chip_PMU_PowerMode_EnterDeepSleep();
}
return 0;
}