Re: SPI problem

"Theodore A. Roth" <[email protected]> Tue, 13 Jan 2004 14:26:02 -0800 (PST)
Newsgroups gmane.comp.hardware.avr.general
Message-ID <[email protected]>

On Tue, 13 Jan 2004, David VanHorn wrote:

>
> >
> >Does setting PORTB to 0x24 help? I see this in the datasheet:
>
> Not by itself.
>
> >  PB2 -> SS*
> >  PB3 -> MOSI
> >  PB4 -> MISO
> >  PB5 -> SCK
> >
> >Also, you might want to set PB2 high.
>
> Tried PORTB=0x26, also no go.
>
>
> >Might also consider clearing DDRB4 in DDRB since it's an input.
>
> DDRB is 0xEF, that's 11101111b which has that pin cleared (input)
> Right?

Yeah. I goofed that one. You are correct.

>
>
> >I assume you tried simple SPI output in a real device already and it works.
>
> Not recently, I don't have real hardware for this one yet.

It's really easy to make a test circuit with a 74*595 shift register. I
made one that has 8 leds on the outputs of the 595 on a little board
with a 10pin header that can plug right into the PORTB header of the
stk500 board.

I wired it up like this (16-pin DIP part):

  mosi -> pin 14 (SDI)
  mosi <- pin 9  (SDO)
  sck  -> pin 11 (Shift clock)
  CS   -> pin 12 (Latch clock)    ; CS is an arbitrary pin choice on MCU

  outupts like this:

  vcc --- resistor --- LED --- Qx (parallel output of 595)

This at least let's me see the software is working. You could probably
get the same results using an o-scope.

>
>
> >I've had best results if I make sure that the SPI bits of DDRB
> >and PORTB are the same.
>
> Tried it, no go.
>
>
> I'm using the studio 4.08 sim, AFAIK it's the latest update.

Keith Gudger has recently added SPI support to simulavr for USB devices.
Should be in cvs now (which I hope to release once savannah is back up).
I haven't tried it yet, but it might work for a simple spi test program
with the mega8.

Ted Roth