Studio 4.10 simulator SPI interrupt

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

I'm using the new AVR Studio 4.10 with JTAGICE MKII, STK500/501 with a mega128L and assembler 2 beta 5. In my initialization routine I turn off the SPI unit and try an clear any interrupts, using the code fragment below (I have already created a complete interrupt vector table, disabled global interrupts and Port B pin 0 (SS) is configured as in input with pull up enabled).

ldi r16, (0 << SPIE) | (0 << SPE)
out SPCR, r16 ; disable SPI unit
sbic SPSR, SPIF ; check for pre-existing interrupt
in r16, SPDR ; clear it if found

I read the data sheet about the SPI SS pin (port B pin 0) forcing the SPIF flag on, if the SS pin is configured as an input, SPI is a MASTR and the SS pin gets a low input.

When I debug this on the AVR simulator, as soon as global interrupts are enabled there is a SPI interrupt (vector $0022) waiting to be serviced, for no apparent reason at all (the SPI is still disabled). The only way I have found to prevent this interrupt is to configure the SS pin (port B pin 0) as an output. Servicing the stray interrupt with a SEI, RETI clears it and it does not re-occur (this stray interrupt is a startup one time event).

When I debug this on the JTAGICE MKII, when global interrupts are enabled, there is never a startup SPI interrupt waiting to be serviced (which is what I wanted/expected).

It looks like a simulator bug, but I am new to AVR and wanted to check with others who have more experience. I read the documentation for known simulator issues with the SPI and did not see this problem mentioned. I also searched the forum, but did not find this exact problem.

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

I have almost the same thing happen to me but with a different pin. The only solution I could figure out was to set a break point somewhere during initialization to set the corresponding PIN value in the IO window. My pin was PB7 so I expanded IO and PORT B and made sure the box for bit 7 in PINB register was checked. If not, I clicked it.

It seems that the PIN bits seem to be a random. Well, except for the ones that matter, they are always backwards. I would like to know if there is a better way.