|
|
View previous topic :: View next topic |
Author |
Message |
jdelphi
Joined: 31 Jul 2010 Posts: 3
|
I2C read or write during an interrupt |
Posted: Sat Jul 31, 2010 6:22 am |
|
|
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
|
|
Posted: Sat Jul 31, 2010 6:33 am |
|
|
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: 19504
|
|
Posted: Sun Aug 01, 2010 1:35 am |
|
|
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: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Aug 01, 2010 11:37 am |
|
|
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 |
|
|
|
|
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
|