Hello,
I'm trying to read data from the NFC memory using the NHS3152.
Basically, do the measure resistance many have done.
The program I have stems frome many exampale found on the blog and in the NHS3152 documents.
So here is the procedure from https://community.nxp.com/t5/NFC/Measure-resistance-NHS3152/m-p/831045
Set the configuration of the analog pins to IOCON_FUNC_1
Connect the DAC to ANA1, set a continuous conversion of 1.25V.
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
Connect the ADC to ANA4, and measure the voltage. -> v4
Connect the ADC to ANA1, and measure the voltage. -> v1
The resistor can now be calculated as (v1-v4)/a
I'm trying first to get an I2D conversion of the current through the resisto (a 75kOhms).
At the moment, I can set a voltage of 1.25V at ANA0_1 and get the curretn flowing through the R when calling the I2D conversion. I measurement a voltage of 0.79V accross R so I should get a 10e-6ish current.
Here is the code:
*
*
* https://community.nxp.com/t5/NFC/Measure-resistance-NHS3152/m-p/831045
* The best results to measure R
Set the configuration of the analog pins to IOCON_FUNC_1
Connect the DAC to ANA1, set a continuous conversion of 1.25V.
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
Connect the ADC to ANA4, and measure the voltage. -> v4
Connect the ADC to ANA1, and measure the voltage. -> v1
The resistor can now be calculated as (v1-v4)/a
//https://community.nxp.com/t5/LPC-Microcontrollers/NHS3152-Measure-resitance-correct-param-ADC-I2D-DA...
//https://community.nxp.com/t5/LPC-Microcontrollers/NHS3152-Write-NDEF-message-containing-integer-valu...
//https://community.nxp.com/t5/Other-NXP-Products/NHS3152-dynaimcally-update-message-dysplayed-on-phon...
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "board.h"
#include "ndeft2t/ndeft2t.h" // pour message NFC
/*Variables et Constantes */
//préférérable de définir ces variables comme static volatile car elles sont changées par l'exterieur du programme
static volatile int i2dNativeValue; // 3. store I2D ana 4
static volatile int i2dValue; // 3. store I2D ana4
static volatile int resval_int;
static volatile int adc_value_native;
static volatile int adc_value;
static volatile double diff = 0;
static volatile double volt1 = 5.0; // 4. stocke la tension sur input 1
static volatile double volt4 = 5.0; // 5. stocke la tension sur input 4
static volatile double resval = -1; // variable pour stocker la resistance calculée calculated: (dcInput_1-adcInput_4)/Current_picoampere*10e-6
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. */
#define AN1 IOCON_ANA0_1
#define ADCDAC1 ADCDAC_IO_ANA0_1
#define AN4 ADCDAC_IO_ANA0_4
#define ADCDAC4 ADCDAC_IO_ANA0_4
#define I2D4 I2D_INPUT_ANA0_4
/*function to configure the DAC */
static void Init_DAC(char IOCON_ANA, char ADCDAC_IO)
{
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA, IOCON_FUNC_1); /*utilise le GPO analogique IOCON_ANA comme sortie du DAC */
Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxDAC(NSS_ADCDAC0, ADCDAC_IO); /* connecte le DAC à la sortie ADCDAC_IO*/
Chip_ADCDAC_SetModeDAC(NSS_ADCDAC0, ADCDAC_CONTINUOUS);
}
/*function to configure the ADC */
static void Init_ADC(char IOCON_ANA, char ADCDAC_IO)
{
//ADC Single-shot
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA, IOCON_FUNC_1);
/* Set pin function to analogue */
Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO);
Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0,ADCDAC_INPUTRANGE_WIDE);
Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_SINGLE_SHOT);
}
/*function to configure the I2D */
static void Init_I2D(char I2D_In)
{
Chip_I2D_Init(NSS_I2D);
Chip_I2D_SetMuxInput(NSS_I2D, I2D_In);
Chip_I2D_Setup(NSS_I2D, I2D_SINGLE_SHOT, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_HIGH, 100); // courant max = , précision, 100 == 100ms integration time
}
// function to get the ADC value once a Init_ADC has been done
// Equation de convertion de l'ADC: adc_input_voltage = (native_value * 1.2V) / 2825 + 0.09V
// should be a "float" type, testing for now with native value which is int (double?)
int Mesure_Volt()
{
int adc_value_native;
//double adc_value;
Chip_ADCDAC_StartADC(NSS_ADCDAC0);
while (!(Chip_ADCDAC_ReadStatus(NSS_ADCDAC0) & ADCDAC_STATUS_ADC_DONE)) {
; /* Wait until measurement completes. For single-shot mode only! */
}
adc_value_native = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);
//adc_value = adc_value_native * 1.2/ 2825 + 0.09; //Chip_ADCDAC_GetValueADC(NSS_ADCDAC0) renvoie un int
return adc_value_native;
}
int main(void)
{
Board_Init();
Chip_Clock_System_SetClockFreq(4000000);
Chip_NFC_Init(NSS_NFC);
NDEFT2T_Init();
Chip_Clock_System_BusyWait_ms(1000);
/*Initialise DAC*/
Init_DAC(AN1, ADCDAC1);
/* native value range is [0..3800]
* Actual DAC output voltage is Vout = (native/2881)V + 0.262V
* Vout_min =0.262V (native = 0)
* Vout_max = 1.581 (native = 3800)
*/
/*Set DAC output @ 1.25V*/
Chip_ADCDAC_WriteOutputDAC(NSS_ADCDAC0,3000);
/* Get the current through the R
/* Initialise I2D, connect to IO ANA0_4 */
Init_I2D(I2D4);
/* current starts flowing through R connected between AN1 and AN4 when conversion starts*/
Chip_I2D_Start(NSS_I2D);
while (!(Chip_I2D_ReadStatus(NSS_I2D) & I2D_STATUS_CONVERSION_DONE))
{
; /* wait */
}
i2dNativeValue = Chip_I2D_GetValue(NSS_I2D); //integer value
/* Conversion en PicoAmp */
i2dValue = Chip_I2D_NativeToPicoAmpere(i2dNativeValue, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_HIGH, 100);
Chip_I2D_DeInit(NSS_I2D);
/*Get voltage Volt4 on pin AN4 */
//Init_ADC(AN4, ADCDAC4);
//volt4 = Mesure_Volt();
/*Get voltage Volt1 on pin AN1 */
//Init_ADC(AN1, ADCDAC1);
//volt1 = Mesure_Volt();
// 2. Conversion int to hexadecimal string
adc_value=1234;
//adc_value = i2dNativeValue; /*comment this line or the above to check tag memory content*/
char str_adcInput[16];
itoa(adc_value, str_adcInput, 10); //10 == int to convert is a decimal, so 1234 comes out as "1234"
// 3. Sending the NDEF message to the common memory
uint8_t instanceBuffer[NDEFT2T_INSTANCE_SIZE] __attribute__((aligned (4))); // comes from NHS31XX SW API description
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);
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);
//}
//}*/
// NSS_NFC->BUF[13]=1234;
return 0;
}
I first used the NDEFT2 message to pass an integer =1234 to the NFC memory , works fine, next figre
Hello,
I'm trying to read data from the NFC memory using the NHS3152.
Basically, do the measure resistance many have done.
The program I have stems frome many exampale found on the blog and in the NHS3152 documents.
So here is the procedure from https://community.nxp.com/t5/NFC/Measure-resistance-NHS3152/m-p/831045
Set the configuration of the analog pins to IOCON_FUNC_1
Connect the DAC to ANA1, set a continuous conversion of 1.25V.
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
Connect the ADC to ANA4, and measure the voltage. -> v4
Connect the ADC to ANA1, and measure the voltage. -> v1
The resistor can now be calculated as (v1-v4)/a
I'm trying first to get an I2D conversion of the current through the resisto (a 75kOhms).
At the moment, I can set a voltage of 1.25V at ANA0_1 and get the curretn flowing through the R when calling the I2D conversion. I measurement a voltage of 0.79V accross R so I should get a 10e-6ish current.
Befire computing the R, I wan tto check the current conversion.
Here is the code:
*
*
* https://community.nxp.com/t5/NFC/Measure-resistance-NHS3152/m-p/831045
* The best results to measure R
Set the configuration of the analog pins to IOCON_FUNC_1
Connect the DAC to ANA1, set a continuous conversion of 1.25V.
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
Connect the ADC to ANA4, and measure the voltage. -> v4
Connect the ADC to ANA1, and measure the voltage. -> v1
The resistor can now be calculated as (v1-v4)/a
//https://community.nxp.com/t5/LPC-Microcontrollers/NHS3152-Measure-resitance-correct-param-ADC-I2D-DA...
//https://community.nxp.com/t5/LPC-Microcontrollers/NHS3152-Write-NDEF-message-containing-integer-valu...
//https://community.nxp.com/t5/Other-NXP-Products/NHS3152-dynaimcally-update-message-dysplayed-on-phon...
*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "board.h"
#include "ndeft2t/ndeft2t.h" // pour message NFC
/*Variables et Constantes */
//préférérable de définir ces variables comme static volatile car elles sont changées par l'exterieur du programme
static volatile int i2dNativeValue; // 3. store I2D ana 4
static volatile int i2dValue; // 3. store I2D ana4
static volatile int resval_int;
static volatile int adc_value_native;
static volatile int adc_value;
static volatile double diff = 0;
static volatile double volt1 = 5.0; // 4. stocke la tension sur input 1
static volatile double volt4 = 5.0; // 5. stocke la tension sur input 4
static volatile double resval = -1; // variable pour stocker la resistance calculée calculated: (dcInput_1-adcInput_4)/Current_picoampere*10e-6
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. */
#define AN1 IOCON_ANA0_1
#define ADCDAC1 ADCDAC_IO_ANA0_1
#define AN4 ADCDAC_IO_ANA0_4
#define ADCDAC4 ADCDAC_IO_ANA0_4
#define I2D4 I2D_INPUT_ANA0_4
/*function to configure the DAC */
static void Init_DAC(char IOCON_ANA, char ADCDAC_IO)
{
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA, IOCON_FUNC_1); /*utilise le GPO analogique IOCON_ANA comme sortie du DAC */
Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxDAC(NSS_ADCDAC0, ADCDAC_IO); /* connecte le DAC à la sortie ADCDAC_IO*/
Chip_ADCDAC_SetModeDAC(NSS_ADCDAC0, ADCDAC_CONTINUOUS);
}
/*function to configure the ADC */
static void Init_ADC(char IOCON_ANA, char ADCDAC_IO)
{
//ADC Single-shot
Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA, IOCON_FUNC_1);
/* Set pin function to analogue */
Chip_ADCDAC_Init(NSS_ADCDAC0);
Chip_ADCDAC_SetMuxADC(NSS_ADCDAC0, ADCDAC_IO);
Chip_ADCDAC_SetInputRangeADC(NSS_ADCDAC0,ADCDAC_INPUTRANGE_WIDE);
Chip_ADCDAC_SetModeADC(NSS_ADCDAC0, ADCDAC_SINGLE_SHOT);
}
/*function to configure the I2D */
static void Init_I2D(char I2D_In)
{
Chip_I2D_Init(NSS_I2D);
Chip_I2D_SetMuxInput(NSS_I2D, I2D_In);
Chip_I2D_Setup(NSS_I2D, I2D_SINGLE_SHOT, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_HIGH, 100); // courant max = , précision, 100 == 100ms integration time
}
// function to get the ADC value once a Init_ADC has been done
// Equation de convertion de l'ADC: adc_input_voltage = (native_value * 1.2V) / 2825 + 0.09V
// should be a "float" type, testing for now with native value which is int (double?)
int Mesure_Volt()
{
int adc_value_native;
//double adc_value;
Chip_ADCDAC_StartADC(NSS_ADCDAC0);
while (!(Chip_ADCDAC_ReadStatus(NSS_ADCDAC0) & ADCDAC_STATUS_ADC_DONE)) {
; /* Wait until measurement completes. For single-shot mode only! */
}
adc_value_native = Chip_ADCDAC_GetValueADC(NSS_ADCDAC0);
//adc_value = adc_value_native * 1.2/ 2825 + 0.09; //Chip_ADCDAC_GetValueADC(NSS_ADCDAC0) renvoie un int
return adc_value_native;
}
int main(void)
{
Board_Init();
Chip_Clock_System_SetClockFreq(4000000);
Chip_NFC_Init(NSS_NFC);
NDEFT2T_Init();
Chip_Clock_System_BusyWait_ms(1000);
/*Initialise DAC*/
Init_DAC(AN1, ADCDAC1);
/* native value range is [0..3800]
* Actual DAC output voltage is Vout = (native/2881)V + 0.262V
* Vout_min =0.262V (native = 0)
* Vout_max = 1.581 (native = 3800)
*/
/*Set DAC output @ 1.25V*/
Chip_ADCDAC_WriteOutputDAC(NSS_ADCDAC0,3000);
/* Get the current through the R
/* Initialise I2D, connect to IO ANA0_4 */
Init_I2D(I2D4);
/* current starts flowing through R connected between AN1 and AN4 when conversion starts*/
Chip_I2D_Start(NSS_I2D);
while (!(Chip_I2D_ReadStatus(NSS_I2D) & I2D_STATUS_CONVERSION_DONE))
{
; /* wait */
}
i2dNativeValue = Chip_I2D_GetValue(NSS_I2D); //integer value
/* Conversion en PicoAmp */
i2dValue = Chip_I2D_NativeToPicoAmpere(i2dNativeValue, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_HIGH, 100);
Chip_I2D_DeInit(NSS_I2D);
/*Get voltage Volt4 on pin AN4 */
//Init_ADC(AN4, ADCDAC4);
//volt4 = Mesure_Volt();
/*Get voltage Volt1 on pin AN1 */
//Init_ADC(AN1, ADCDAC1);
//volt1 = Mesure_Volt();
// 2. Conversion int to hexadecimal string
adc_value=1234;
//adc_value = i2dNativeValue; /*comment this line or the above to check tag memory content*/
char str_adcInput[16];
itoa(adc_value, str_adcInput, 10); //10 == int to convert is a decimal, so 1234 comes out as "1234"
// 3. Sending the NDEF message to the common memory
uint8_t instanceBuffer[NDEFT2T_INSTANCE_SIZE] __attribute__((aligned (4))); // comes from NHS31XX SW API description
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);
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);
//}
//}*/
// NSS_NFC->BUF[13]=1234;
return 0;
}
I first used the NDEFT2 message to pass an integer =1234 to the NFC memory , works fine, next figure (read using ARduino and RC522)
I want first to check the value of the current through the 75k resistor
But I'm confused, when I replace the integer by native I2D value, the same bytes have a strange values
Questions:
1) what is the I2D conversion equation from native to value?
2) what is wrong with the value stored in NFC shared memeory?
3) I tried instead of NDEFT2 NSS_NFC->BUF[page number] = integer_value, with no success
what is wrong with my code?
4) I also tried to read the native voltage difference, from measurement and equation, I should read an integer of 1866. It is not working either. why?
Many questions, my level in programming such device is rather low...
Thanks
解決済! 解決策の投稿を見る。
Hi CyrilBZH,
1) The analog pins are default weakly grounded and not connected to the internal analog busses, therefore the current observed is not flowing into the I2D input but to VSS.
Assuming ANA0_4 is used as the I2D input, adding Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_4, IOCON_FUNC_1) in the initialization code should fix this.
2) The conversion function from native to pA is in SDK lib_chip_nss/src/i2d_nss.c, line 218 and following. The formula and some explanation on the calculation is in the comment field.
Kind regards,
Patrick
Hi CyrilBZH,
The NDEF message in the case of "adc_value = i2dNativeValue" is 0x30 0x00, which is the C string "0".
So the i2dNativeValue must have been zero when it was converted to ascii by itoa().
Can you implement the following changes and try again:
1) insert a short delay between init and start of the I2D block:
Init_I2D(I2D4);
Chip_Clock_System_BusyWait_ms(1);
Chip_I2D_Start(NSS_I2D);
2) possibly use converter gain low:
Chip_I2D_Setup(NSS_I2D, I2D_SINGLE_SHOT, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_LOW, 100);
i2dValue = Chip_I2D_NativeToPicoAmpere(i2dNativeValue, I2D_SCALER_GAIN_10_1, I2D_CONVERTER_GAIN_LOW, 100);
3) not related to the "0" problem but de-init the I2D block only after making all the ADC voltage measurements: Chip_I2D_DeInit(NSS_I2D);
Kind regards,
Patrick
Hello Patrick,
Thnaks for your answer. I have modified the code as you suggested.
What is causing the reading of "0" is that my DAC is not working anymore, hence a 0A current flowing through the resistor. It does seem to be a hardware problem rather than a code poblem. Is there any way I can solve that?
I have also modify my code so that it converts float to string, I do have a current of 0.000 read using the nfc.
So the code works, I can read the i2d value through the nfc.
Can you give me the equation converting i2d native into pA?
best regards
Cyril
thanks a lot
Hi CyrilBZH,
1) The analog pins are default weakly grounded and not connected to the internal analog busses, therefore the current observed is not flowing into the I2D input but to VSS.
Assuming ANA0_4 is used as the I2D input, adding Chip_IOCON_SetPinConfig(NSS_IOCON, IOCON_ANA0_4, IOCON_FUNC_1) in the initialization code should fix this.
2) The conversion function from native to pA is in SDK lib_chip_nss/src/i2d_nss.c, line 218 and following. The formula and some explanation on the calculation is in the comment field.
Kind regards,
Patrick