After hooking up a scope and taking some measurements, I think the problem might be that the hardware SPI on the ATmega128 is too fast for the device I'm hooking up. At the largest prescale for the hardware SPI, I measure the SPI clock at around 116 KHz. This is close to what the datasheet says which at my crystal freq of 16 MHz, SPI clock should be fosc/128 = 125 KHz which is in the ballpark. When I switch over to my manual bit banging, I needed to insert a small delay to slow down the clock toggling for reliable communication. Right at the border for when it works and when it doesn't work, the clock is at around 36 KHz - significantly slower than the slowest I can make the hardware SPI clock run. So it looks like the problem is that the slave device is too slow to keep up, and that I cannot prescale the hardware SPI clock down enough. Bummer. The device I'm hooking up, BTW, is a Sony PS/2 gamepad. It's still possible I'm doing something wrong. I'd really like to use the hardware SPI if possible, it seems much more elegant than bit banging it. But whatever works, I guess. -Brian -- Brian Dean, bsd@bdmicro.com BDMICRO - Maker of the MAVRIC ATmega128 Dev Board http://www.bdmicro.com/
Message
Re: [AVR-Chat] SPI on an ATmega not quite working
2004-02-03 by Brian Dean
Attachments
- No local attachments were found for this message.