Hey, guys...
I have a problem in using interrupt in arduino...
So i tried to add interrupt in my setup function to read ADC result. But it is end up with nothing's happening.
here is my code where i used my interrupt:
#include <intrinsics.h>
#include <string.h>
#include "AFE4490.h"
#include <SPI.h>
const int SOMI = 12; //data out connect to MISO
const int SIMO = 11; //data in connect to MOSI //butuh logic level converter
const int SCLK = 13;
const int SPISTE = 9; //butuh logic level converter
volatile unsigned long ReadLED2VAL;
volatile unsigned long ReadALED2VAL;
volatile unsigned long ReadLED2ABSVAL;
volatile unsigned long ReadLED1VAL;
volatile unsigned long ReadALED1VAL;
volatile unsigned long ReadLED1ABSVAL;
void setup()
{
Serial.begin(9600);
SPI.begin();
pinMode (SOMI,INPUT);
pinMode (SPISTE,OUTPUT);
pinMode (SCLK, OUTPUT);
pinMode (SIMO, OUTPUT);
SPI.setClockDivider (SPI_CLOCK_DIV128);
SPI.setDataMode (SPI_MODE1);
SPI.setBitOrder (MSBFIRST);
AFE4490Init ();
for(int count = 0; count<60; count++)
{
// AFE4490Write(CONTROL2,0x020200); // Disable crystal, 0.5V TX_REF */
AFE4490Write(TIAGAIN,0x000000); // LED_RANGE=100mA, LED=50mA
AFE4490Write(TIA_AMB_GAIN,0x000000); // Timers ON, average 3 samples
AFE4490Write(LEDCNTRL,0x011414); // Switch to READ mode
AFE4490Write(CONTROL2,0x000000); // LED_RANGE=100mA, LED=50mA
AFE4490Write(CONTROL1,0x000107); // Timers ON, average 3 samples
AFE4490Write(CONTROL0,0x000001); // Switch to READ mode
Serial.println(count);
delay (1000);
if (digitalRead (SOMI)== HIGH)
{
attachInterrupt (1, InterruptEnab, RISING);
Serial.println ("SOMI is connected, Reading register is proceed!");
Serial.print("Red Data:");
Serial.println(ReadLED2VAL);
Serial.print("Red Ambient Data:");
Serial.println(ReadALED2VAL);
Serial.print("Red Different:");
Serial.println(ReadLED2ABSVAL);
Serial.print("IR Data:");
Serial.println(ReadLED1VAL);
Serial.print("IR Ambient:");
Serial.println(ReadALED1VAL);
Serial.print("IR Different:");
Serial.println(ReadLED1ABSVAL);
detachInterrupt (1);
//AFE4490Write(CONTROL0,0x000000); // disable READ mode
}
else //else SOMI
{
Serial.println ("SOMI is not connected, check the wire!");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void InterruptEnab ()
{
ReadLED2VAL = AFE4490Read(LED2VAL);
ReadALED2VAL = AFE4490Read(ALED2VAL);
ReadLED2ABSVAL = AFE4490Read(LED2ABSVAL);
ReadLED1VAL = AFE4490Read(LED1VAL);
ReadALED1VAL = AFE4490Read(ALED1VAL);
ReadLED1ABSVAL = AFE4490Read(LED1ABSVAL);
}
}
i am expecting that this interrupt able to use according to this datasheet on the attachment.
Can someone enlighten me what i miss?
sorry if you think my code is very messy... i am purely new about interrupt stuff.
Stella
