Using NHS3152 I am tyring to:
The code is working, however i cannot remove semihosting becuase i am using a sprintf (Link to question with dries comment )
I have the following questions:
1. Can you confirm that i cannot flash to NHS3152 due to sprintf ?
2. How do i commit a message that contains the values of the variables V1, V2, I, RES ?
I basically need to be able to disconnect the NHS3152 from hte LPCLINK, and still see my code running, but its been quite frustrating and everything i've tried hasn't worked, obviously i am not able to understand what the issue is.
@converse I am answering here since when i reply, it keeps telling me " Post flooding detected "
Thanks for the help,
So following on from This post I selected Quickstart --> set library/header --> redlibnohost. I then debugged and ran the code.
At this point when i bring the phone near the tag, The LED goes red and the message " adc_1: 0....." is displayed.
I then stopped debug and the message still updates normally every time i bring the tag in contact.
I disconnected the USB from the PC, now the tag RED LED lights up, but as previously NO message "Tag is empty or not alligned"
Below is extra information incase the issue isn't a simple fix:
Here I am assuming that the steps "Debug-->Resume-->stop Debug--> disconnect USB" Should allow the chip to have the program onboard, since it works with the blinky example ?
For reference i have included the main and the libraries my code (full code here)is using: I have commeted out
//Chip_PMU_PowerMode_EnterDeepSleep();
perhaps this causes an issue ?
The Libraries I imported:
#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"
// 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();
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
// generate the message only once per field???
GenerateNdef_TextMime();
}
//Chip_PMU_PowerMode_EnterDeepSleep();
}
return 0;
}
EDIT2: reply to @driesmoors :
Hi Driers,
I have modified loopx as you suggested, i am still running into the same problem: once i disconnect the USB from PC, "tag is empty or not alligned".
To store values in fixed memory, i have created these two following voids that i modified from : Example Read modify_ and write EEPROM content in the section eeprom: EEPROM driver
void Chip_reads_a_fixed_memory_location_in_EEPROM (void)
{
Chip_EEPROM_Init(NSS_EEPROM);
Chip_EEPROM_Read(NSS_EEPROM, 61, &sText, sizeof(sText-1));
Chip_EEPROM_DeInit(NSS_EEPROM);
}
void Chip_stores_values_in_fixed_memory_location_in_EEPROM (void)
{
Chip_EEPROM_Init(NSS_EEPROM);
Chip_EEPROM_Write(NSS_EEPROM, 61, &sText, sizeof(sText-1));
Chip_EEPROM_Flush(NSS_EEPROM, true);
Chip_EEPROM_DeInit(NSS_EEPROM);
}
Here is the code that i modified from the main, covering points 2-5 of your suggested loopx:
// 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. Chip reads a fixed memory location in EEPROM
Chip_reads_a_fixed_memory_location_in_EEPROM();
// 3. Chip creates and commits an NDEF message
GenerateNdef_TextMime();
// 4. Chip calculates sensors resistance R: V1, V2, I, and R= (V1-V2)/I
// 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();
resval = (adcInput_1-adcInput_4)/(current_picoampere * 1e-12); // (v1-v4)/(I4pico * 1e-12) V/I=R [V/A =ohm]
// 5. Chip stores values in fixed memory location in EEPROM
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 );
Chip_stores_values_in_fixed_memory_location_in_EEPROM();
GenerateNdef_TextMime();
}
}
return 0;
}
After debug-resume --> message is updating correctly
Stop --> message still updating correclty
Remove USB --> tag is empty or not alligned
Solved! Go to Solution.
Hi @driesmoors ,
I have done the tests that you asked for:
I have setup the code with Chip_GPIO_SetPinOutHigh instead of toggle since it was clearer in the oscilloscope. I place a HIGHbefore the For loop, then LOW after Store values and HIGH after generate ndef; as shown below:
...
Chip_IOCON_SetPinConfig(NSS_IOCON, 7, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE);
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
for (;;) {
...
...
Chip_stores_values_in_fixed_memory_location_in_EEPROM();
Chip_GPIO_SetPinOutLow(NSS_GPIO, 0, 7);
GenerateNdef_TextMime();
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
}
After debug-run while still connected, I have:
With HIGH =3.3V
I then disconnected the USB cable and powered by NFC (phone):
I get the same results except High is 1.9V instead of 3.3V
What do you think the problem is? Perhaps the message isn't being retrieved from EEPROM ?
Thanks for your help,
Leo
Below is the new 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);
Chip_IOCON_SetPinConfig(NSS_IOCON, 7, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE);
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
// for ever, WHILE field is detected: 2. Connect the DAC to ANA1, set a continuous conversion of 1.25V.
for (;;) {
// main gets control for loop starts
// 2. Chip reads a fixed memory location in EEPROM adds value to sText
Chip_reads_a_fixed_memory_location_in_EEPROM();
//Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
//Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
// 3. Chip creates and commits an NDEF message
GenerateNdef_TextMime();
//Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
// 4. Chip calculates sensors resistance R: V1, V2, I, and R= (V1-V2)/I
// 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();
resval = (adcInput_1-adcInput_4)/(current_picoampere * 1e-12); // (v1-v4)/(I4pico * 1e-12) V/I=R [V/A =ohm]
// 5. Chip stores values in fixed memory location in EEPROM
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_stores_values_in_fixed_memory_location_in_EEPROM();
Chip_GPIO_SetPinOutLow(NSS_GPIO, 0, 7);
GenerateNdef_TextMime();
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
// GenerateNdef_TextMime finishes
}
return 0;
}
Also, when powered by the phone NFC only (USB disconnected), it occasionly displays the message "adc_try road" the original sText was "country road" (song came on spotify, no meaning", so it seems to be only replacing a piece of the message:
Hi @driesmoors ,
I have done the tests that you asked for:
I have setup the code with Chip_GPIO_SetPinOutHigh instead of toggle since it was clearer in the oscilloscope. I place a HIGHbefore the For loop, then LOW after Store values and HIGH after generate ndef; as shown below:
...
Chip_IOCON_SetPinConfig(NSS_IOCON, 7, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE);
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
for (;;) {
...
...
Chip_stores_values_in_fixed_memory_location_in_EEPROM();
Chip_GPIO_SetPinOutLow(NSS_GPIO, 0, 7);
GenerateNdef_TextMime();
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
}
After debug-run while still connected, I have:
With HIGH =3.3V
I then disconnected the USB cable and powered by NFC (phone):
I get the same results except High is 1.9V instead of 3.3V
What do you think the problem is? Perhaps the message isn't being retrieved from EEPROM ?
Thanks for your help,
Leo
Below is the new 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);
Chip_IOCON_SetPinConfig(NSS_IOCON, 7, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE);
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
// for ever, WHILE field is detected: 2. Connect the DAC to ANA1, set a continuous conversion of 1.25V.
for (;;) {
// main gets control for loop starts
// 2. Chip reads a fixed memory location in EEPROM adds value to sText
Chip_reads_a_fixed_memory_location_in_EEPROM();
//Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
//Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
// 3. Chip creates and commits an NDEF message
GenerateNdef_TextMime();
//Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
// 4. Chip calculates sensors resistance R: V1, V2, I, and R= (V1-V2)/I
// 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();
resval = (adcInput_1-adcInput_4)/(current_picoampere * 1e-12); // (v1-v4)/(I4pico * 1e-12) V/I=R [V/A =ohm]
// 5. Chip stores values in fixed memory location in EEPROM
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_stores_values_in_fixed_memory_location_in_EEPROM();
Chip_GPIO_SetPinOutLow(NSS_GPIO, 0, 7);
GenerateNdef_TextMime();
Chip_GPIO_SetPinOutHigh(NSS_GPIO, 0, 7);
// GenerateNdef_TextMime finishes
}
return 0;
}
Also, when powered by the phone NFC only (USB disconnected), it occasionly displays the message "adc_try road" the original sText was "country road" (song came on spotify, no meaning", so it seems to be only replacing a piece of the message:
Hi Leo,
What do you mean with "Commit message"? Creating a text message so your phone can show the results?
The NFC controller of the NHS3152 is a type 2 tag. It cannot hold off reading the NFC memory. Is there a dedicated app running on your phone or PC to continually read the NFC memory? If not, it means the NDEF message must be made available almost immediately after tapping your passive tag. This leaves very little time to do stuff from the moment the IC starts and the moment the phone decides to read the NFC memory.
Br,
Dries.
Hi Dries,
What do you mean with "Commit message"? Creating a text message so your phone can show the results?
Exactly.
I am trying to Demostrate the tag fully passive reading my resitance sensor (X-ray radiaiton) and showing the result on the Phone screen. It's not the final product, but a DEMO to be delivered end of January so that the investors can decide whether to tranform it into a product or not.
Is there a dedicated app running on your phone or PC to continually read the NFC memory?
There is no dedicated app.
If not, it means the NDEF message must be made available almost immediately after tapping your passive tag. This leaves very little time to do stuff from the moment the IC starts and the moment the phone decides to read the NFC memory.
I understood that even without a dedicated APP, when under NFC field the IC would create a message and commit it to memory. Then if i bring the phone out and into the filed again, i would read the message, i thought it would work like so:
1. Bring phone within Chip reach
Loop 1
2. Chips sends back empty message
3. Chip calcualtes sensors resitance R: V1, V2, I, and R= (V1-V2)/I
4. Chip commits text message with value of R into memory (to be read next time)
5. Remove phone from NFC distance (chip stops operating)
Loop 2
6. Bring phone back into NFC field
7. Chip sends back Message saved in loop 1 (with Resitance value prev. measured)
Basically by entering and exiting the filed it reads the message twice, giving teh message it created the last loop. This is how it works while the Chip is connected to the PC (via LPC link).
However to convince investors that it is working powered only by phone i need it disconnected from the PC.
Obviously if investors do decide to fund the project to bring it to market, there will be a dedicated app, as the message it reads needs to be the current value. Also as we have discussed previusly, i cannot perfomr multiple reads and get a statistic without an app, so an app in the future is a must. But just to demostrate project viability this should be enough.
thanks again for your help,
Leo
Hi Leo,
Ok. Tx for sharing this.
The NFC memory exposed to the phone is partially NFC EEPROM, partially SRAM.
The ARM reads and writes into the SRAM region. After removing the phone, the NFC controller dies. In a passive setup, the chip dies too and the SRAM region is no longer refreshed.
Your loop can be modified to:
Loop x
Good to read you will use a dedicated app. Without that, you are relying on the background reading. On Android, NFC keeps powering the tag as along as the tag is in reach. On iOS, the NFC field is immediately shut off after reading the NDEF message, preventing steps 4,5,6 to be executed. When using an app, you can guarantee an NFC field on iOS too.
Kind regards,
Dries.
@driesmoors I have again added an EDIT to the question above, since in the reply it kees telling me "Post flooding detected ",
Thanks,
Leo
Hi,
Can you measure the time it takes from the moment main gets control and the call to GenerateNdef_TextMime finishes? And then to when Chip_stores_values_in_fixed_memory_location_in_EEPROM finishes? You can toggle a pin at different locations and detect the flank changes with a scope to measure this accurately.
Some smaller remarks:
BR,
Dries.
Hello Driers,
I will run the tests on Tuesday as I have to go back to the LAB to use the scope I will update you Tuesday afternoon or Wednesday. Below are the answers to the points you raised:
I have removed the while (sFieldPresent) loop (see main below)
I didn't understand this point. By actions what do you mean ?
I have Now removed Chip_EEPROM_Init/DeInit from the EEPROM loops:
void Chip_reads_a_fixed_memory_location_in_EEPROM (void)
{
// REMOVED : Chip_EEPROM_Init(NSS_EEPROM);
Chip_EEPROM_Read(NSS_EEPROM, 61, &sText, sizeof(sText-1));
// REMOVED : Chip_EEPROM_DeInit(NSS_EEPROM);
}
void Chip_stores_values_in_fixed_memory_location_in_EEPROM (void)
{
// REMOVED : Chip_EEPROM_Init(NSS_EEPROM);
Chip_EEPROM_Write(NSS_EEPROM, 61, &sText, sizeof(sText-1));
Chip_EEPROM_Flush(NSS_EEPROM, true);
// REMOVED : Chip_EEPROM_DeInit(NSS_EEPROM);
}
Can you measure the time it takes from the moment main gets control and the call to GenerateNdef_TextMime finishes? And then to when Chip_stores_values_in_fixed_memory_location_in_EEPROM finishes? You can toggle a pin at different locations and detect the flank changes with a scope to measure this accurately.
To toggle pins i have parts of the code from Example 1 - Configuring individual pins. I have toggled pin 7 with "Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);" 4 times, next line after:
Below is the main part of the code that i intend to run tomorrow. And i Will let you know the results.
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);
Chip_IOCON_SetPinConfig(NSS_IOCON, 7, IOCON_FUNC_0 | IOCON_RMODE_INACT | IOCON_LPF_DISABLE);
// for ever, WHILE field is detected: 2. Connect the DAC to ANA1, set a continuous conversion of 1.25V.
for (;;) {
// 2. Chip reads a fixed memory location in EEPROM
Chip_reads_a_fixed_memory_location_in_EEPROM();
Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
// 3. Chip creates and commits an NDEF message
GenerateNdef_TextMime();
Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
// 4. Chip calculates sensors resistance R: V1, V2, I, and R= (V1-V2)/I
// 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();
resval = (adcInput_1-adcInput_4)/(current_picoampere * 1e-12); // (v1-v4)/(I4pico * 1e-12) V/I=R [V/A =ohm]
// 5. Chip stores values in fixed memory location in EEPROM
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_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
Chip_stores_values_in_fixed_memory_location_in_EEPROM();
Chip_GPIO_SetPinToggle(NSS_GPIO, 0, 7);
GenerateNdef_TextMime();
}
return 0;
}
Hi Leo,
I found these issues (after running the code myself; I kept reading over them)
The call to read from EEPROM is wrong:
Line I used: Chip_EEPROM_Read(NSS_EEPROM, 61, sText, sizeof(sText));
Likewise, the call to write to EEPROM has the same issues.
Line I used: Chip_EEPROM_Write(NSS_EEPROM, 61, sText, sizeof(sText));
When writing the NDEF text record, you can better use strlen, as the string length is less than the array you use to store it in.
Line I used (in GenerateNdef_TextMime
After changing the above (plus some dead code removal, which is irrelevant) I got it working, both while debugging and when run stand-alone.
Try this, and let me know whether this helped for you.
Best,
Dries.
Hi @driesmoors ,
I did the corrections you suggested and it worked! thanks!
It still for some calibration issue is reads 40*actual_resitance, but this doesn't matter for the demos.
We even tried it witha textile humidity sensor collegues are developping and it worked for them too,
Thanks fo your valuable help,
Leo
"Post flooding detected" normally means that you are trying to post the same message multiple times (are you hitting Submit/Post/Reply more than once?)
One thing to try is to clear your browser cache for this website and see if that helps.
Hi,
Ok,
I selected "reply to this topic" and when i tried to submit it told me "incorrecly formatted HTML", so then i guess when i resubmitt it is considered a second submission and thus flooding.
Is the EDIT to my original POST enough, or do you want me to try and reply again here below?
thanks,
Leo
I have repied by adding an EDIT to the question above, since in the reply it kees telling me "Post flooding detected "
Do you have precise instructions to set semihosting to NONE?
I might be giving infomation that isn't relevant here, but a difference i see between my project and one like Blinky are:
Image 1: The DAC_ADC_toghether folder view : It doens't create a Release.launch (like blinky does)
2. I have checked in properties, but i cannot see other options:
3. For Blinky (that works also whilst disconnected from PC and only in NFC presence) i have a release available:
Please let me know the steps to remove semihosting.
thanks,
Leo
Semihosting is a library selection and has nothing to do with debug or release builds, or launch configuration. Read this faq, and the others listed at the bottom of the faq
Set semihosting to NONE. sprintf is not semihosting, but printf is (semihosting means that any i/o operations are carried out on the host - such as file read and write). sprintf does not use i/o.