attiny20 and SPI: weird issue

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

Hi,

 

I swear I've never had so much trouble with an Atmel.  I have a time set up to produce interrupts at 1mS intervals:

void timer_init(void)
{
	// for 8.0000MHz clock
	// timer 0 is the 1mS ticker (verified)
	TCCR0A  = (1<<WGM01);					// ctc mode
	TCCR0B  = (1<<CS02); 					// divide by 256
	OCR0A   = 0x1E;							// or 30 decimal
	TIMSK	= 1<<OCIE0A;					// output compare A match irq
}
//	1mS timer tick for
//	button timeout, etc
ISR(TIM0_COMPA_vect)
{
	static uint8_t tmrButton;

	tmrButton++;
	
	if(tmrButton>=BUTTONTIMEOUT) {
		
		tmrButton=0;
		//SwitchHandler();
	}	
}

This works hunky dory .. at least until I enable SPI:

	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);			// SPI enable

This line kills the timer interrupts.  If I comment out the SPCR line then the timer interrupts work.

 

I've done this with other Atmels with no problem. In fact this code was copied from production code running on a mega164A.

 

What am I missing?

 

 

Tim Ressel
Portland, OR
timr@earthling.net

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

This line kills the timer interrupts.

What does 'kill' mean?  How have you determined this?

 

Post a >>complete<< (builds without errors) and >>minimal<< (no other code) test program which demonstrates the problem.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

I toggle an output pin in the ISR code.

 

Tim Ressel
Portland, OR
timr@earthling.net

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

Which pin? Obviously as soon as SPE is set you lose access to PB1, PB2, PA7

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

clawson wrote:

Which pin? Obviously as soon as SPE is set you lose access to PB1, PB2, PA7

Doh .. stupid me. I'm using PB2 which of course is MISO and of course gets redirected when SPI is enabled.

 

Thanks.

Tim Ressel
Portland, OR
timr@earthling.net