I2C and timer interrupt mixed up

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I am using I2C (master mode) to interface sensors. What I would like to do is to read from I2C periodically through timer interrupt.
I notice that I2C driver code uses interrupt already. Can someone tell me how to enable nested interrupts or how to interface I2C without interrupt.
Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is this for an xmega? xmega has three different interrupt levels for tiered interrupt levels.

TWI can be used in interrupt mode or polled mode.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since this is an xmega forum, it is xmega without saying.
I know TWI can be used in pulled mode, but the driver from Atmel doesn't have code for it. Anyone has a pulled driver code? I also noticed 3 levels of interrupts, but it is irrelevant because I am talking about nested interrupt.E.g. TWI interrupt called within timer interrupt.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the ugly_hack way:
Never enable the I2C interrupt. Change the driver ISR to a function, make a wrapper function (or add to the former ISR) that checks the i2c interrupt flag(s), if interrupt flag(s) set; run the interrupt function (and probably clear interrupt flags), if not; return.

Don't know how feasable this is, and I haven't looked at the xmega I2C, so please take this with a grain of salt and factor in my two friday beers :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clearsky1494 wrote:
Can someone tell me how to enable nested interrupts...
clearsky1494 wrote:
...I also noticed 3 levels of interrupts, but it is irrelevant because I am talking about nested interrupt.E.g. TWI interrupt called within timer interrupt.
Changing the interrupt priority is how you enable nested interrupts.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clearsky1494 wrote:
What I would like to do is to read from I2C periodically through timer interrupt.

In TWI interrupt you can set a flag as an indication for new data and timer interrupt can read this new data when the flag is set. Then timer routine clears the flag and waits for next new data in the following interrupts.

Ozhan KD
Knowledge is POWER