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, 5 months ago.
[RESOLVED] DigitalOut write method during interrupt
Hello everyone,
I have a strange behavior here: In a class constructor I initialize a DigitalOut like this:
declaration
output = new DigitalOut(LED1);
With output declared as private member of my class.
On the other hand I have a Ticker interrupt that tries to do:
interrupt
output->write(1);
When this code is called, the programm crashes.
The thing is that when I declare output direclty in the class file (.cpp) like this:
declaration
DigitalOut output(LED1);
And then replacing the previous code by this one
interrupt
output = 1;
It works!!!
Do you have any idea of why the first code isn't working? I am missing something?
Thank you in advance
My guess would be that output isn't properly initialized, but for that we would need to see your code. If it isn't sensitive, could you publish it as public(unlisted)? (Or if really short copy paste).
posted by Erik - 05 Jun 2014Hello, The code is here, located in Note::applyDesiredState(). As you can see the "engine" can either activate the output on demand or on tick.
posted by Benoît GEISLER 05 Jun 2014http://mbed.org/users/ggmero67/code/ActivateOutput/
posted by Benoît GEISLER 05 Jun 2014This is getting to the limits of my c++ abilities but initialization could be the issue. Can you switch engine.h / .cpp to having an array of Note pointers rather than Notes and then initialize them using new Note(pin) in the engine constructor?
posted by Andy A 06 Jun 2014Thank you for your reply, I'll try this ASAP!
posted by Benoît GEISLER 06 Jun 2014You were right, I needed to declare:
and init the notes like this: