SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By ursus8
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


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.

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;

// 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		
		// start only ones
			I20CONSET |= STA; //enable
//test signals
	if (I20CONSET & SI) {IOSET0=0x10;}else IOCLR0=0x10; 
	if (I20STAT== 0x20){IOSET0=0x20;}else IOCLR0=0x20;


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

please HELP! :cry:

By stevech
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
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.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]