chipKIT® Development Platform

Inspired by Arduino™

I2C and Interrupt routine

Created Tue, 25 Aug 2015 03:21:34 +0000 by YOBE.


YOBE.

Tue, 25 Aug 2015 03:21:34 +0000

Hello,

some good suggestions? Im running a I2C communication to a MPU board and simultaniously triggering interrupts from encoder readings. Now, it seems that the interrupt routine is "hanging" the Chipkit because of interference with the I2C communication. Took me 2 days to find out :evil: Thought it was the DC-motor creating spikes on the I2C comm ports........

I will now try to reduce the workload from the interrupt routine by using direct port-steering.

Somebody has a better solution for this?? As soon as I deactivate the encoder-readings, the process keep running fine.

Thx


YOBE.

Tue, 25 Aug 2015 14:16:56 +0000

Sorry to bother,

but does anybody has a clue how to solve this???? Seems the combination of external interrupt (high freq, because of motor-encoder) and the "wire" library for I2C are conflicting!!! I don't see how to solve the issue. As soon the interrupts are enabled and pulses are generated and even with no code in the subroutine (jump & return) , the chipkit "hangs" with the I2C communication. If I disable "interrupt" during I2C communication, I will loose encoder pulses.

I am end of idea's now....

Thx for the help.


EmbeddedMan

Tue, 25 Aug 2015 14:59:51 +0000

One thing you could try is to use the DTWI library rather than Wire. It is more robust than straight Wire, and may help your situation.

*Brian


YOBE.

Wed, 26 Aug 2015 04:32:28 +0000

One thing you could try is to use the DTWI library rather than Wire. It is more robust than straight Wire, and may help your situation. *Brian

Any idea where I can find this? Tried google, but no real links....

So stupid that the I2C communication fails when external interrupts are called....


GastonLagaffe

Wed, 26 Aug 2015 11:14:47 +0000

Salut,

I found the DTWI library as part of the mpide distribution (latest 150 stable) in the wire subdirectory: mpide\hardware\pic32\libraries\Wire\

It is included in the chipKit-Git core as a library as well. The example of the Wire library called I2CMasterEEPROM uses DTWI. You have to selecet the right core and compiler (chipKit-Git and pic32-tools-MZ) to compile. Unfortunately, it failed to compile on my side when I checked it quickly:

C:\UECIDE\cores\chipKIT-Git\libraries\DTWI\DTWI.cpp: In constructor 'DTWI0::DTWI0()':
C:\UECIDE\cores\chipKIT-Git\libraries\DTWI\DTWI.cpp:1429:105: error: '_DTWI0_SCL_PIN' was not declared in this scope
C:\UECIDE\cores\chipKIT-Git\libraries\DTWI\DTWI.cpp:1429:121: error: '_DTWI0_SDA_PIN' was not declared in this scope
C:\UECIDE\cores\chipKIT-Git\libraries\DTWI\DTWI.cpp: In constructor 'DTWI1::DTWI1()':
C:\UECIDE\cores\chipKIT-Git\libraries\DTWI\DTWI.cpp:1454:105: error: '_DTWI1_SCL_PIN' was not declared in this scope
C:\UECIDE\cores\chipKIT-Git\libraries\DTWI\DTWI.cpp:1454:121: error: '_DTWI1_SDA_PIN' was not declared in this scope

looking at the boards definition of the mpide distribution I find this declaration in the uno32:

/* Declarations for Digilent DTWI library.
**		DTWI0 is on A4/A5 (see above comment).
**		DTWI1 is on digital pins 40 & 39.
*/
#define	_DTWI0_BASE		_I2C1_BASE_ADDRESS
#define	_DTWI0_BUS_IRQ	_I2C1_BUS_IRQ
#define	_DTWI0_VECTOR	_I2C_1_VECTOR
#define	_DTWI0_IPL_ISR	IPL3SOFT
#define	_DTWI0_IPL		3
#define	_DTWI0_SPL		0
#define _DTWI0_SCL_PIN  46 
#define _DTWI0_SDA_PIN  45

#define	_DTWI1_BASE		_I2C2_BASE_ADDRESS
#define	_DTWI1_BUS_IRQ	_I2C2_BUS_IRQ
#define	_DTWI1_VECTOR	_I2C_2_VECTOR
#define	_DTWI1_IPL_ISR	IPL3SOFT
#define	_DTWI1_IPL		3
#define	_DTWI1_SPL		0
#define _DTWI1_SCL_PIN  40 
#define _DTWI1_SDA_PIN  39

Adding this to the Boards_Defs.hI of the uno32 compiles the code.

hope this helps

Ciao, Mathias