AVR One! AS6 & sei cli

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Finally got around to trying the AVR ONE! and switch to AS6 (from 4). I made a simple program for an Atmega32u4. However, most of the time when debugging, stepping thru, etc, I noticed that the global interrupt bit is not being set. Sometimes even if the I bit is showing as cleared, I could still trigger the external interrupt on INT2, but other times I could not. Seemed very random. I saw a few threads with same problem in the simulator, but did not see a thread with the same problem on live hardware. So, take a look at the code below. Look OK? Know what I'm doing wrong in the debugger? I've tried different optimaztion levels, but saw no difference.

#include 
#include 

volatile uint8_t tester1;
volatile uint8_t tester2;
volatile uint8_t tester3;
volatile uint8_t flag;

int main(void)
{
	uint16_t temp = 0;
	DDRD = 0x00;
	EICRA = (1<<ISC21);	// INT2 Falling edge
	EIMSK = (1<<INT2);  // INT2 interrupt
	TCCR1B = (1<<CS11);	// Enable timer1, scale by 8
	sei();	// Enable global interrupts
    while(1)
    {
		if(flag)
		{
			cli();	// Disable interrupts
			temp = tester1;	
			temp = (temp<<8);
			temp = temp + tester2;
			tester3 = (uint8_t)(65500/ temp) ;
			flag = 0;	// Reset flag
			sei();	// Re-enable interrupts
		}
		
    }
}

//**********************************************
//	ISR Routines
//**********************************************
ISR(INT2_vect)
{
	// Read Low Byte first, then High Byte
	tester1 = TCNT1L;
	tester2 = TCNT1H;
	flag = 1;	// Signal to main
}

Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To add, I am using the JTAG with the squid. Just trying to run some simple code to familarize myself with the AVR one!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The sei() thing is a know bug. See previous threads about this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looked like a known bug when using the simulator, but seemed like folks did not have the same problems with live hardware. I tried adding instructions around the sei calls, per the other threads, but I have the same problem.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Apparently the issue is in single stepping the opcodes - so don't. Instead if you see one coming up set a breakpoint beyond it then free-run over it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The only other "option" that works is to totally turn off optimization. But that doesnt really help me much when debugging real projects.

Quote:
Apparently the issue is in single stepping the opcodes - so don't. Instead if you see one coming up set a breakpoint beyond it then free-run over it.

Is that for 'sei' only?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kind of funny. The one instruction that assemblies to a single instruction, is the one instruction that cannot be single stepped thru.