mercredi 27 juillet 2016

C++ variable changed during interrupt resets after interrupt

I'm trying to use a flag to see if an event has finished.

Via the debugger, I have seen that the interrupt triggers correctly and does set the value of transmitComplete to 1. When I return to the if statement which checks whether or not the flag has been set to 1, it has been reset to 0.

The only 2 locations where i alter the value of transmitComplete are after the if statement and in the interrupt routine.

I'm running the following bits of code. The declaration of transmitComplete is done in the header file of the class. fireEvent() is a member function of the class I2c.

volatile uint8_t transmitComplete;

void I2c::foo() {
    if (transmitComplete) {

        transmitComplete = 0;

        // trigger event which sets transmitComplete back to 0 when done
        fireEvent();
   }
}

void I2c::sendHandler(XIic *InstancePtr) {
    transmitComplete = 1;
}

Aucun commentaire:

Enregistrer un commentaire