Report
3 years ago.

FRDM-KL25Z not capturring Interrupts

Hello,

I am working to catch an interrupt from the FXAS21002 with the FRDM-KL25Z bu tI am having no success. Using a logic analyzer I can see the interrupt firing but the interrupt routine is never called to deal with the interrupt, I have attached snippets of my code bellow.

include the mbed library with this snippet

#include "mbed.h"
#include "SDFileSystem.h"

//Setup UART to PC
Serial pc(USBTX, USBRX);

//Setup I2C
I2C sensors(PTE0, PTE1);


//FXAS21002C Control Pins
InterruptIn fxas_int1_21002(PTA5);  //INT1-21002
InterruptIn fxas_int2_21002(PTA13); //INT2-21002


//Interrupt for FXAS21002 INT_1
void read_fxas_data(){
    //Read data from FXAS21002 sensor
    i2c_write(FXAS_ADDRESS_W, FXAS_OUT_X_MSB, 0);
    sensors.read(FXAS_ADDRESS_R, sensor_data, 1, false);
//    FXAS_FIFO_FULL_FLAG = 1; //Set FIFO flag to enable main function to clear FXAS FIFO and pass that to the SD card
    led_3.write(0);
}


int main() {
    int initilised = 0;
    
    //Initlilise the FXOS8700CQ Accelorometer & the FXAS21002C Gyroscope
    initilised = fxas_init() & fxos_init();
    pc.printf("Returned value: %d\n\n\r", initilised);
    
    //Configure interrupts
    fxas_int1_21002.rise(&read_fxas_data);
    
    while(1) {

    }
}

This is a screen capture from the logic analyzer showing the interrupt firing but not being captured by the FRDM-KL25Z as it remains high and is never reset after firing.

/media/uploads/Kas_Lewis/interrupt_firing.png

Any answers as to why I cant seem to capture this interrupt or solutions as to how to resolve this issue would be very much appreciated.

Thankfully Kas

Question relating to:

It doesn't fire as in the interrupt routine isn't entered at all? What if you for example toggle led3 as first thing? Are you 100% sure you have it properly wired?

posted by Erik Olieman 16 Jul 2015

Hello Erik,

Nope the routine was not entered at all. I tried using printf and setting an LED in that routine and none produced a result so I assume the routine was never entered.

I finally tried moving the "fxas_int1_21002.rise(&read_fxas_data);" to be the second line in the main function and now it works, why moving up two lines of code makes a difference I am not sure, but tis is sure not the first peculiarity I have noticed so far with mbed.

include the mbed library with this snippet

int main() {
    int initilised = 0;
    
    //Configure interrupts
    fxas_int1_21002.rise(&read_fxas_data);

    //Initlilise the FXOS8700CQ Accelorometer & the FXAS21002C Gyroscope
    initilised = fxas_init() & fxos_init();
    pc.printf("Returned value: %d\n\n\r", initilised);
        
    while(1) {
 
    }
}

If you do have an explanation or reason why this might happen I would be happy to hear it so I can better work with mbed.

Thankfully Kas

posted by Kasriel Lewis 16 Jul 2015
Comment on this question

2 Answers

3 years ago.

@The comment: Which other problems did you run into? Mbed isn't perfect, and also the KL25 port not, however the KL25 is one of the oldest mbed platforms, and that effectively means one of the most reliable ones.

Now your problem, it suddenly all makes sense :).

Standard printf on mbed is still blocking. You can use alternatively libraries (such as BufferedSerial), but normal Serial blocks until the last character is put into the transmit buffer. The KL25 has a very small buffer on its Serial, so effectively it needs to wait until the last byte is sent. Now add that Serial is slow by default (9600 baud -> 1ms per character), and what you got in your code is between the init code and setting your interrupt a wait statement.

So the problem is simply that the rising edge happens before you set the interrupt. Setting the interrupt at the start solves this problem.

Erik thank you for your help and the explanation its people like you that make it worth it for me to keep working at learning this platform :)

The other issue I had which may not be directly related to mbed but I did find it interesting was in my initialization I do this " initialised = fxas_init() & fxos_init(); " but initially I had " initialised = fxas_init() && fxos_init(); ". Bitwise AND swapped with logic AND but I did not notice because for about 50+ times running the code it ran correctly but then I started getting funny behavior (system not initialized) and I could not work out why. I finally realized my silly error and removing the one & to give me my bitwise AND instead of a logical AND resolving thi sissue, but I was never able to understand why sometimes it worked and other times it did not with the logical AND there.

Anyhow I learned an old lesson of paying better attention to what your fingers type so as to not drive yourself nuts trying to understand why your code does not do what you THINK it should do.

Thankfully Kas

posted by Kasriel Lewis 17 Jul 2015

Glad to help :).

And yeah, bitwise vs logical AND/OR is a standard one :P. Or one I like: Forgetting the shift operator has the lowest priority every:

shift = input_msb << 8 + input_lsb

That does not what you want it to do.

However what you describe is really something which is in the compiler, and not the mbed libs. And in general you can assume the compiler is right ;). If they always return 0/1 (or preferably explicitly set as bool), the logican and bitwise and should be equal. Otherwise it is always risky.

posted by Erik Olieman 17 Jul 2015
3 years ago.

Running code in an ISR is usually trouble.

Try just setting a flag in the ISR and process the interrupt code in your main.

As a test I am running it like this, in fact I have cut it down to just turning a LED on, but this is not my issue. The issue is the KL25Z does not catch the interrupt... it NEVER goes into that routine, does NOT make the function call.

If I can get help as to why this is NOT catching the the interrupt (i.e. not calling the interrupt routine) that would be very much appreciated.

Thank you

posted by Kasriel Lewis 16 Jul 2015

To post an answer, please log in.