Go Down

Topic: Unable to run this code on arduino uno. (Read 411 times) previous topic - next topic

fuzail

May 12, 2013, 03:58 pm Last Edit: May 12, 2013, 04:05 pm by fuzail Reason: 1
Hi
i am trying to run this program, however after uploading it
i do not get anything on the serial monitor. it remains blank.
what could be the reason ?
i tried to see if the interrupt was getting triggered somehow, but doesn't seem that way.
here is the code
edit : i forgot to add, the programs gets uploaded without any issues.
Code: [Select]

/*
 IR Capture
 Copyright 2012, all rights reserved.
 James M. Eli
 1/14/2012

 project parts:
   (1) arduino 16MHz
   (1) 38KHz IR receiver
   (1) breadboard
   (3) wires

 IR - Arduino
 SIG - D2
 GND - GND
 VCC - VCC
*/

//definitions
#define IN_PIN 2
#define MAX_CAPTURE 584  // Line number 1

//globals
uint32_t now, start, capture[MAX_CAPTURE];
volatile bool flag_complete;
uint16_t i;    // Line number 2 uint8_t to uint16_t Key point of RAWBUF. uint8_t maximum range 255

void setup() {
 flag_complete = false;
 start = 0;
 now = 0;
 i = 0;
 Serial.begin(9600);
 Serial.print("Ready to capture.");
 attachInterrupt(0, IRInterrupt, CHANGE);
}
 
//interrupt fires on ir event (rise/fall)
void IRInterrupt() {
 Serial.print("entered interrupt");
 now = micros();
 capture[i++] = now - start;
 start = now;
 if (i >= MAX_CAPTURE) {
   detachInterrupt(0);
   flag_complete = true;
 }
}


void loop() {
 while (1) {
   if (flag_complete) {
     for (i=0; i < MAX_CAPTURE; i++) {        
       Serial.println(capture[i]);
       //Serial.print(",");
       flag_complete = false;
     }
   }
 }
}

afremont

You can't call serial.print inside of an ISR.  You should at least be seeing the "Ready to capture" message after removing the print from the ISR.
Experience, it's what you get when you were expecting something else.

fuzail

i do not get the "ready to capture" message.
i thought for some reason the isr is getting triggered. so i added the serial print there to see if it was in fact entering the isr. but good to know that u cant use Serial.print in an isr

fuzail

i have noticed something,
the maximum voltage i am getting is around 4.5 volts(between any of the high pins and ground) and not 5 volts.
would this be effecting the program in any way?

tim7

Quote
Code: [Select]
#define MAX_CAPTURE 584  // Line number 1
uint32_t now, start, capture[MAX_CAPTURE];


584 * 4 = 2.3 k-bytes RAM.


Go Up