Skip to main content
14 votes

Is it a good idea to perform I2C Communication in the ISR?

In the olden days, when we had a single thread of execution, and many sources of interrupts, you kept the ISR as short and quick as possible, so that it is able to keep up with many frequent interrupt ...
Simon Fitch's user avatar
  • 42.2k
11 votes

Is it a good idea to perform I2C Communication in the ISR?

I don't believe it's a good idea, in general. The I2C protocol allows for clock stretching, which means that any I2C device you're trying to talk to can effectively stop your bus, or at least dork ...
Scott Seidman's user avatar
7 votes
Accepted

CORTEX-M jump causes UFSR=2

Let's look at ARM's AN209 "Using Cortex-M3/M4/M7 Fault Exceptions": INVSTATE: [...] the processor has attempted to execute an instruction that makes illegal use of the Execution Program ...
Kuba hasn't forgotten Monica's user avatar
4 votes

Is it a good idea to perform I2C Communication in the ISR?

Well, assuming the I2C bus is running at 100 kbit/s, and you're reading/writing roughly 500 bits, the whole interrupt will take about 5 milliseconds. Do you care if your main program is paused for 5 ...
ilkkachu's user avatar
  • 1,107
3 votes

What happens if I short the MISO line and SCL line?

Bad idea. The I²C device has no idea about the CS line and could happily desturb the data during SPI communication if the pattern on the bus was just right. SPI usage will also violate the timing and ...
Turbo J's user avatar
  • 10.4k
3 votes

Is it a good idea to perform I2C Communication in the ISR?

Egregious examples of systems that disable interrupts for long periods of time: Early Macintoshes, which disabled interrupts for the entire duration of floppy disk operations, thereby preventing the ...
Robin Davies's user avatar
3 votes

Is it a good idea to perform I2C Communication in the ISR?

[General guidelines. We don’t know the nature of the sensor, the nature of the instrument. We’ll make working assumptions.] The general advice is not to do serial communication in an ISR. Don’t ...
Nick Alexeev's user avatar
  • 38.5k
3 votes

Is it a good idea to perform I2C Communication in the ISR?

In time-critical applications the RDY output of the chip/module/whatever can be useful to get the data or initialise a transmission immediately. Otherwise, it's still possible to read the RDY output ...
Rohat Kılıç's user avatar
3 votes

Is it a good idea to perform I2C Communication in the ISR?

It highly depends on the architecture of the processor. As a general rule, you should not put any time-consuming operation in an isr. Some architectures have some measures to prevent any long task in ...
Saadat's user avatar
  • 1,938
2 votes
Accepted

What is the best way to use asynchronous ("non-blocking") delay in embedded systems?

There are many different ways of handling this, and there is no way to know what's "the best" way as it depends what you are doing, how, and are all the options you suggested poor and ...
Justme's user avatar
  • 164k
2 votes

What is the best way to use asynchronous ("non-blocking") delay in embedded systems?

As you’ve noted, there a many different techniques for timing. Having a regular timer tick is very common. Yes, it does chew up some cpu cycles, but usually that is a small price to pay. With most ...
Kartman's user avatar
  • 6,513
2 votes

What is the best way to use asynchronous ("non-blocking") delay in embedded systems?

It feels like you're using non-standard language for blocking vs non-blocking delays. Blocking delays are delays during which no other code can run, and non-blocking means other code can run during ...
Scott Seidman's user avatar
2 votes

Is it a good idea to perform I2C Communication in the ISR?

In general, an ISR should avoid doing anything that would require that it wait a non-trivial amount of time for something to happen. If some action would require that a pin be asserted for at least ...
supercat's user avatar
  • 47.1k
1 vote

Is it a good idea to perform I2C Communication in the ISR?

As many of the other answers have said, it's generally a bad idea to do anything that stalls, in an ISR. Instead, do the minimum possible that MUST be done RIGHT NOW, and get out. Let some slower ...
AaronD's user avatar
  • 5,686
1 vote

What is the best way to use asynchronous ("non-blocking") delay in embedded systems?

Timer bit depth If you need a 16/24 bit timer depends on the required resolution of the time. From the looks of it you are counting milliseconds, so it does not matter that much. When the interrupt ...
Jeroen3's user avatar
  • 23.5k
1 vote

Why is TMR0 not producing an accurate waveform period?

The interrupt code is executed by the CPU. Each opcode takes 0.25 microseconds to execute, and the interrupt code is many opcodes. If you trigger an interrupt to happen every 0.25 microseconds, your ...
Justme's user avatar
  • 164k
1 vote
Accepted

What circuitry is needed to control several concurrent USB-C ports in device (UFP) mode?

What is the simplest circuitry I can add to an off-the-shelf SoM to give it the capability to act as a USB device for multiple different hosts simultaneously? USB to Ethernet. Your driver will then ...
Jeroen3's user avatar
  • 23.5k

Only top scored, non community-wiki answers of a minimum length are eligible