Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 3 months ago.
nRF51822 PinDetect and interrupts
Hi,
I'm working with nRF51822-EK and I want to use PinDetect in my project.
But when I'm using PinDetect with other interrupts, all Interrupts stop working.
Here is example code:
#include "mbed.h" #include "PinDetect.h" Serial pc(USBTX, USBRX); #define DEBUG(...) { pc.printf(__VA_ARGS__); } DigitalOut led1(LED1); DigitalOut led2(LED2); PinDetect pb(p16); void periodicCallback(void) { led1 = !led1; } void keyPressed (void) { DEBUG("0\n\r"); } void keyReleased( void ) { DEBUG("1\n\r"); } void keyPressedHeld( void ) { DEBUG("2\n\r"); } void keyReleasedHeld( void ) { DEBUG("3\n\r"); } int main(void) { led1 = 1; led2 = 0; pc.baud(38400); pb.mode(PullUp); pb.attach_asserted( &keyPressed ); pb.attach_deasserted( &keyReleased ); pb.attach_asserted_held( &keyPressedHeld ); pb.attach_deasserted_held( &keyReleasedHeld ); pb.setSampleFrequency(); Ticker ticker_led; ticker_led.attach(periodicCallback, 1); while(1) { led2 = !led2; wait(0.2); } }
Here if I delete pb.setSampleFrequency(); line and don't start PinDetect then ticker_led will be working and it's callback will be calling. Next if I delete ticker_led.attach(periodicCallback, 1); line then PinDetect callbacks will be calling. But if PinDetect and ticker is run together then no callbacks will be called, but led2 will still blink.
Is PinDetect library incompatibility with nRF51822?
If I place creating ticker outside of main and place ticker callback attach after calling setSampleFrequency() in main then it all works fine.
If I place ticker attach before setSampleFrequency() then it still hang.
UPD:
Still there is some troubles with PinDetect and softdevice.
posted by Nikita Polotnyanko 30 Aug 2014If I use PinDetect then when I disconnect from my device it'll hang somewhere in application (softdevice still works, device advertising and I can connect).
If I comment PinDetect start (setSampleFrequency()) then I can connect and disconnect without any hangs.
So there is still some problems in the PinDetect source code.