Report
2 years, 7 months ago.

Using I2C in a ticker called funktion

hey there!

Following problem: I need to read an I2C device in an interrupt. My analyzer showed me that the SDL & SCL pins get pulled down in the Interrupt but the clock isn't cycling and neither are the bytes transferred.

I started breaking it apart and found that the interrupt is the troublemaker. So I had a long search in the forum and the questions and found that the priority of the interrupts is the problem so I took out the line I needed and had a long search to find the "29" standing in there.

The board I'm developing for is STF411RE.

I would really appreciate help :)

Lorenz

#include "mbed.h"

Ticker my_ticker; // ticker for interrupt

void read()
{   
    char reg = 0x1a;
    int16_t value;
    char data[3];
    
    data[0] = reg;
    
    i2c.write(0x50, data, 1, true);
    i2c.read(0x50, data, 2, false);
    
    value = data[1] << 8 | data[0];
    value = (double)value/16;    
}


int main()
{
    
    NVIC_SetPriority((IRQn_Type)29, 255);
    
    i2c.frequency(200000);
    wait(1);
    
    my_ticker.attach(&read, 1);
    
    while(true) 
    {
        //noting yet
    }
}
Comment on this question

1 Answer

1 year, 5 months ago.

Any update?

It worked with i2c.transfer() used instead of i2c.write()

posted by Lorenz Ruprecht 02 Apr 2018

You need to log in to post a question