SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By ursus8
#164682
Hello!
I'm trying to run some ADCs via I2C on LPC2148. I'm using Keil.
The "start" signal is transmitted, interrupt routine is entered and the first byte transmitted. after that I2C enters state 0x20 normally (there is no chip connected to the bus, so nACK assumed). However interrupt routine is not entered again (processor is interrupted only ones).

the following picture shows signals on the oscilloscope:
-pin 0x10 shows "SI" flag, which triggers the interrupt
-pin 0x20 corresponds to I2C0 state "0x20"
-pin 0x40 is set high as interrupt routine is entered and pulled low right before exiting interrupt routine

Image


It looks to me as if the interrupt routine can not be entered the second time. SI flag is set, I2C0 goes to state 0x20, BUT interrupt routine is not entered.
:think:

Here is the main.c:
Code: Select all
/*
i2c testni program
*/

#include "LPC214x.h"

//defines 131010 ursus
#define AA      (1 << 2)
#define SI      (1 << 3)
#define STO     (1 << 4)
#define STA     (1 << 5)
#define I2EN    (1 << 6)
// end defines

int swf;

void I2CISR(void);

/*************************** MAIN ************************/ 
int main() 
 { 
	PCONP |= 0x80; //da je i2c0 vklopljen (power)
	PINSEL0= 0x50;

	IODIR0=0xffffffff; 
    IOCLR0=0xff;
	 
	swf=1;
	
// Interrupt setup:
	//VICIntSelect	= 	0;	
	VICIntEnable |= (1<<9);
	VICVectCntl0 =  0x20 | 9; // isto kot 0x20 | 9; // 9 je zaporedna cifra za  int i2c.
	VICVectAddr0 = (unsigned)I2CISR;

// I2C0 setup
	//I20CONCLR = 0xff; //clear all
	I20SCLH = 140; //50k	
	I20SCLL	= 140; //50k
	I20CONCLR = STA| STO | AA; //clear all
	I20CONSET = I2EN; //enable
		
//----- main loop		
	 while(1) 
	{	
		// start only ones
		if(swf==1)
		{	
			I20CONSET |= STA; //enable
			swf=0;
		}
		
//test signals
	if (I20CONSET & SI) {IOSET0=0x10;}else IOCLR0=0x10; 
	if (I20STAT== 0x20){IOSET0=0x20;}else IOCLR0=0x20;
	IOCLR0=0x40;
	}

}

void I2CISR(void)
	{	
	// test signals
	if (I20CONSET & SI) {IOSET0=0x10;}else IOCLR0=0x10; 
	IOSET0=0x40;
	
	//state machine
	switch (I20STAT)
		{				
			case (0x08):
				I20DAT = 0x4;  
				I20CONCLR = STA | SI; 
				break;
		
			case (0x20):	
				I20DAT = 0x4;  
				I20CONCLR = STA | SI;
				I20CONSET = STO;			
				break;
				
			default :
				I20DAT = 0x4;  
				I20CONCLR = STA | SI; 
				I20CONSET = STO;
				break; 
		}
	if (I20CONSET & SI) {IOSET0=0x10;}else IOCLR0=0x10;
	IOCLR0=0x40;
	VICVectAddr = 0x00000000;
}



please HELP! :cry:

regards,
U
By stevech
#164790
Is the use of Interrupts essential? Rather than a one byte I/O loop?

Always get the interface working without interrupts. Then decide if you need the complexity of interrupts.
By ursus8
#164840
thanks for your answer, i wish interrupts were not necessary, but i think they are. The program showed will be included in much larger system and interrupts are needed.