TWIC interrupt

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

Hello to all,

In the CodeVision when we are using TWI it's function is TWI_master_trans ,... and it will be define an interrupt as bellow code,

why? Is it another TWI function that I can send start and stop manually? why we use interrupt for TWI?

There is a problem when we are in TWI function and another interrupt will be ask

the TWI_MASTER_TRANS will be pull down clock and the program will be paused!.

what is the solution?

thank you all.

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

hasanzadeh99 wrote:
why we use interrupt for TWI?
TWI is almost always done using interrupts because you signal some outgoing event on the wires then at some unknown future timer (or perhaps never if it's not present) the device(s) being communicated will respond back. You don't want to be sat waiting in a loop for this to occur. Instead TWI is set up so that when some distant event occurs it triggers an interrupt.

 

As always in embedded systems all interrupt handlers should be designed to operate as swiftly as possible so that, if they block other interrupts while processing, they are over very quickly so as not to block the handling of other interrupts that may occur at hte same time.

 

If you have designed a software system that spends a lot of time in interrupt handlers so that other interrupts are blocked - then you have done it wrong.

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

The Codevision TWI_master_trans() function looks after almost every conceivable I2C operation.

 

You just call it with the required arguments.

Observe the return value.

Process the data.

 

Yes,  it uses interrupts.

Yes,  it blocks until the I2C operations are complete.

 

As a general rule,   you start an I2C operation,   get on with the rest of your life,   check for completion.

If you want the best performance,   you just need to rearrange TWI_master_trans() to behave as two separate functions i.e. initiate_operations() and poll_for_completion().

 

Most punters will be happy with the current library TWI_master_trans() behaviour.

 

David.

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

You could try this on github: https://github.com/knightshrub/I...

Or Peter Fluery's twi code here: http://www.peterfleury.epizy.com...

See if it works better for you.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

The OP does not say what he wants to do.

 

In the real world you know how many bytes you want to write and how many you want to read.

Set the arguments.   Go ahead and make the I2C transactions.

 

This is a lot neater than messing around with individual primitive operations.

 

Obviously there are occasions when you do not know how many bytes you need to receive in advance.    But you can still reduce it to specific transactions.

 

Codevision contains both bit-bang and TWI library versions for Mega/Tiny AVRs.

It only supports hardware TWI for Xmega.

 

David.