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.
7 years, 9 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 } }