Re: SPI problem
"Theodore A. Roth" <[email protected]> Tue, 13 Jan 2004 12:19:12 -0800 (PST)
| Newsgroups | gmane.comp.hardware.avr.general |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 13 Jan 2004, David VanHorn wrote: > > What am I missing here? > > I'm setting up SPI as a master on a mega 8, but it never outputs any > data, and SPIF never sets. > > SPSR is 0x01 ( I want double speed mode) > SPCR is 0x50 ( I want fast, master, enabled, no int) > > DDRB is 0xEF > PORTB is 0x14 Does setting PORTB to 0x24 help? I see this in the datasheet: PB2 -> SS* PB3 -> MOSI PB4 -> MISO PB5 -> SCK Also, you might want to set PB2 high. The sim might be confusing things and think the DDRB:2 being high is not sufficient to stop the SS* signal from putting the part into slave mode. Might also consider clearing DDRB4 in DDRB since it's an input. I assume you tried simple SPI output in a real device already and it works. I've had best results if I make sure that the SPI bits of DDRB and PORTB are the same. > PINB is 0x0C, but I don't think it matters. > > When I drop the data in SPDR (in sim) the data dissapears on the next > cycle, but that's it. Nothing happens on the PORTB pins, and SPIF in > SPSR never sets, so I hang waiting for transmit to complete. If it works in the real device, but not in the sim, I would suspect a bug in the sim. Which sim are you using? Ted Roth