LPC8N04 read a button over NFC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC8N04 read a button over NFC

1,972 Views
m_spit
Contributor III

Hi,

I recently bought the LPC8N04 devkit from NXP to figure out a relatively simple task;

Use the LPC8N04 as a passive tag (with energy-harvesting) that sends back information about the button state.

The devkit contains a userbutton (S2) and a toggleswitch (S1) and I'm curious how I can read this button and switch and place this information in the NFC EEPROM to be read out by an external NFC connected device.

I am new to NXP devices, but I do have experience with Eclipse (so hopefully MCUXpresso won't be a steep learning curve). I was planning to use the Energy Harvesting example included with the devkit and add button-read functionality to this 'template' code.

I'd greatly appreciate the kickstart/pseudo code anyone could give me!

With kind regards,

Merijn

Labels (1)
0 Kudos
9 Replies

1,664 Views
m_spit
Contributor III

So what I've managed so far, is that I can read a button over NFC. The button is normally written as 'button off' in the EEPROM and when i press the button, the EEPROM is loaded with "button on". This is working correctly over USB power.

But I can't seem to make it work with NFC power (VNFC). I can read the tag with my phone as a passive tag saying 'button off', but when I press the button when the phone is present, remove the phone, and read the passive tag again with the phone, it still says 'button off' instead of 'button on'.

I have a feeling that the code in the MCU isn't executed when it is powered by NFC. Can anyone help me with this? I tuned down the systemclock to 2MHz according to demo code provided by the BSP, but to no avail.

0 Kudos

1,664 Views
m_spit
Contributor III

After some more troubleshooting (if anyone is reading this), I'm still trying to figure some things out:

* On battery (small coincell near the LP8N04, not on the debug side), the program works, but the program RESETS when i remove my NFC antenna. It clears all set EEPROM memory that I had stored while it has no reason to do this.

* On VNFC power, the board doesn't execute its code. I do 'see' and couple with an NFC chip but the NDEF storage isn't populated.

* Energy harvesting from the BSP demo code works, I can light up the LEDS on the devkit with only NFC power, so it isn't a power issue.

* The BSP energy harvesting code does not support the SDK and the SDK doesn't support the BSP code. I cant seem to merge both projects.

Can anyone help me troubleshoot why this is happening?? I am really stuck at this point.

0 Kudos

1,664 Views
nxf58474
NXP Employee
NXP Employee

Hi Merijn,

 

Hope you doing well. What SDK version are you using?, What are the projects you want to combine?, When you tried to do it, which errors appears? Please help me with this to have all the information.

 

Best Regards,

Ricardo

0 Kudos

1,664 Views
m_spit
Contributor III

Hi Ricardo, thanks for your interest!

I flipped the code around to work with the demo code delivered in BSP v1.1 that I got from this topic: Can someone provide me with the out-of-the-box firmware/code? It doesn't use an SDK but its functionality is complete, so I don't have to merge projects.

The code works a bit strange; Ít has a main loop and an interrupt timer loop (CT32B0) and it references to 2 different projects (lib_board_bp and lib_chip_8Nxx) to use as libraries, where the BSP V1.0 (provided on the LPC8N04) uses these projects as included libraries. Anyhow, it works.

The interrupt timer is programmed to poll the level of the button and applies debouncing. I have no idea why they didn't implement a simple rising edge interrupt on pin 0_0, but I made it work with a state machine. The state machine was needed to avoid a bug when you held down the button, the code was executed over and over again.

But now back to my problem:

I made the code work, it stores my button value (on/off text message) in the EEPROM that I can read again in the next start-up of the device.

Every time the button is pressed, it toggles between the 'button on' and 'button off' state.

while (1){ // if running on NFC power (Merijn) (True == NFC, false == battery. Use '1' for both states. This loops forever with CT32B0 timer interrupting for button press state)
                        //g_LPC8N04PSTAT = Chip_PMU_Switch_GetVNFC();                                            // get powerstate
                        __WFI();                                                                            // wait for clock interrupt for button press

                        if ((switchPressed == true) && (exFlag == false)){                                    // if button is pressed and this button press hasnt been executed yet
                               exFlag = true;
                               changeFont = false;                                                                //pre programmed trigger in demo code, set low to avoid weird behavior
                               textSize = eepromReadTag(EE_DISP_TEXT, (uint8_t *)eepromCheck, 6);                // Copied from earlier in the code, checks length I think.
                               smallDelay();                                                                    // small delay to give extra time to modules (not crucial)

                               if(!strcmp(eepromCheck, btnTextOff) || (!strcmp(eepromCheck, btnHexOff))){                                            // check if data last time was 'off'
                                   //BtnTextOn = Ascii, BtnHexOn = Hex Bytes for test
                                   smallDelay();
                                   writeNFCDisplayMsg(btnTextOn, strlen(btnTextOn));                                // set to 'on', write NDEF message
                                   smallDelay();
                                   eepromWriteTag(EE_DISP_TEXT, (uint8_t *)btnTextOn, strlen(btnTextOn));        // store state in EEPROM

                               } else if ((!strcmp(eepromCheck, btnTextOn))  || (!strcmp(eepromCheck, btnTextBug)) || (!strcmp(eepromCheck, btnHexOn))){    // check if data was 'on' or bugged

                                   smallDelay();
                                   writeNFCDisplayMsg(btnTextOff, strlen(btnTextOff));                            // set to off
                                   smallDelay();
                                   eepromWriteTag(EE_DISP_TEXT, (uint8_t *)btnTextOff, strlen(btnTextOff));    // store state

                               } else {                                                                        // in any other case when data is unexpected
                                   writeNFCDisplayMsg(btnTextBug, strlen(btnTextBug));                            // send 'bugged'
                                   smallDelay();
                                   eepromWriteTag(EE_DISP_TEXT, (uint8_t *)btnTextBug, strlen(btnTextBug));    // store state
                                   smallDelay();

                               }
                               //releaseMemSemaphore();                                                            // release memory usage, just to be sure

                        } else if ((switchPressed == false) && (exFlag == true)){                            // reset executed flag when button is low
                               exFlag = false;
                           }
                    }

(There are some small tests I have tried in this code above, ignore those, like the small delay and MemSemaphore/PMU state)

This works beautifully on battery/USB power, but I still can't get it to work on VNFC, antenna power.

When I press the button, the old value is still read in the NFC NDEF message on my phone app. The state of the button didn't update from off to on or vice versa.

It seems like pressing the button draws too much current and it resets my MCU code before it can execute my button code. Is this correct? And if it is, how can I fix it? I have no errors in my code according to MCUXpresso.

0 Kudos

1,664 Views
nxf58474
NXP Employee
NXP Employee

Hi Merijn,

 

The main project includes the other two projects in the paths (compiler) and in the libraries (linker). You can see this in the Configuration of the project.

 

The program could be done with an interrupt as you mentioned, but is just a design election.

 

Actually, when you use Energy Harvesting, your code is executing. But if the app is not requesting another read operation, it won't see any change in the memory, until another "tap" (but will lose the energy and restarts the program).

 

Another observation. In the section 8.4.1 of the Data Sheet there is a Remark:

 

pastedImage_2.png

 

In a previous reply you mentioned "I tuned down the systemclock to 2MHz according to demo code provided by the BSP, but to no avail". Are you still using the 2 MHz clock?

 

Hope this helps.

 

Best Regards,

Ricardo.

0 Kudos

1,664 Views
m_spit
Contributor III

Thanks for your reply!

"Actually, when you use Energy Harvesting, your code is executing. But if the app is not requesting another read operation, it won't see any change in the memory, until another "tap" (but will lose the energy and restarts the program)"

The code reads with the LPC8N04 demo app on Android. I hold the phone close to the board, within NFC range, when I press the button. After ive pressed the button, the memory in the EEPROM should have changed on that moment. When I tap read in the demo app again, I re-read the old value and not the updated one.

This is why I think button S2 is pulling too much power when I press it, lowering the supply voltage to the cpu and resetting my program. Or could it be that in energy-harvesting mode the NDEF/EEPROM functions are disabled and are only static/read-only?

The systemclock for the demo-code is initialized on 2MHz and I see the LEDs on the back of the board being lit up in a moving pattern while energy-harvesting as I expect. I do not force the 2MHz clock however.

0 Kudos

1,664 Views
nxf58474
NXP Employee
NXP Employee

Hi Merijn,

 

Let me apologize for the late response. Are you building your project in MCUXpresso as Debug or Release?

 

And the button can work correctly with Energy Harvesting, the problem should not be there.

 

Is it possible to share a video of what you see when you do the test? Just to identify the possible reason.

 

Best Regards,

Ricardo

0 Kudos

1,664 Views
m_spit
Contributor III

My apologies as well for the late reply, the project has been on hold since it does work on battery. A video of the current set-up is sadly not possible for now. 

The project has been built with MCUXpresso as a Release. The code works like a charm with a battery. But without the battery, the code doesn't seem to execute the button functionality.

Is there a way to check what the current clockfrequency is while debugging?

0 Kudos

1,664 Views
nxf58474
NXP Employee
NXP Employee

Hi Merijn,

 

Could you please try to toggle a led when the Push Button is pressed? With this we can be sure if the code of the Push Button is working correctly.

 

Regards,

Ricardo

0 Kudos