CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I2C read or write during an interrupt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jdelphi



Joined: 31 Jul 2010
Posts: 3

View user's profile Send private message

I2C read or write during an interrupt
PostPosted: Sat Jul 31, 2010 6:22 am     Reply with quote

How can I use a I2C Read or write during a timer interrupt on a dsPic ???
wireless



Joined: 02 Nov 2003
Posts: 16
Location: London England

View user's profile Send private message

PostPosted: Sat Jul 31, 2010 6:33 am     Reply with quote

Yes you can use I2C in an interrupt routine but be careful of reentrancy.

For example, if you were in an I2C routine in your main() program and an interrupt occured, also calling the same I2C routine, you would have problems.

It is likely that during compile you will get a warning message saying something like "Interrupts disable in i2c_receive routine to avoid re-entrancy".

Good luck

Regards
Terry
Ttelmah



Joined: 11 Mar 2010
Posts: 19346

View user's profile Send private message

PostPosted: Sun Aug 01, 2010 1:35 am     Reply with quote

I'd actually suggest, that if wanting to use the I2C hardware in an interrupt, one considers just talking directly to the buffer register, rather than using the CCS functions. It is a one line #byte operation to set this up, then you can just write a byte to the I2C buffer, and leave the hardware to get on with sending it. On the next interrupt, check the I2C status (standard fucntions for this), and send another byte if wanted etc..
This way you don't 'wait' inside the interrupt for the transfer, and let the hardware get on and do the actual work for you, while the code is doing other things.

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Aug 01, 2010 11:37 am     Reply with quote

Ttelmah wrote:
I'd actually suggest, that if wanting to use the I2C hardware in an interrupt, one considers just talking directly to the buffer register, rather than using the CCS functions. It is a one line #byte operation to set this up, then you can just write a byte to the I2C buffer, and leave the hardware to get on with sending it. On the next interrupt, check the I2C status (standard fucntions for this), and send another byte if wanted etc..
This way you don't 'wait' inside the interrupt for the transfer, and let the hardware get on and do the actual work for you, while the code is doing other things.


I can't help but ask myself:

"Is he asking if he can have some other interrupt enabled (Timers, UARTs, PWM) while reading/writing I2C in a normal function"

OR

"Is he asking to use IRQ's to handle receiving and transmitting I2C data" like one might do for a UART.

Of course both answers are "yes" -- but have different details.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group