Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] SPI on an ATmega not quite working

2004-02-03 by Dave VanHorn

At 11:53 PM 2/2/2004 -0500, Brian Dean wrote:
>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.

<VBG>
My current project is running 4 MHz SPI, and at that, I have two pushpops 
waiting for the byte to clear. :)
If I could get the SPI on the M8, with internal RC osc, up to 6 MHz, then I 
wouldn't have to wait.

It's only bugging me because it's too fast to go interrupt driven, but I 
don't have enough waste cycles to do anything useful.

I'm also taking data from the host at 800kbits/sec, and doing a fun pixel 
count.
I have to count, in a 104 byte string, how many total black bits, and how 
many under each of 0x88, 0x44, 0x22, and 0x11 masks.
Then I do compensated burn time calculations for either four burns masked 
like that, or two masked as 0xAA,0x55
I also have to load the head either two or four times per burn line.
Tonights test gives 33 lines/sec print speed, roughly 1.5x the 
competition's top of the line machine..

I had a different problem though. I asked them to put resistors in series 
with the SPI clock and data leads, to keep EMI down..
They put in values 50 TIMES larger than I asked for..
Input is a sharp square wave, output looks like wiggling a rope..

>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.

check that the polarity is right, it might be loosing it in setup time.

>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.

My first version of the printer was software driven, no spi.
I was so pushed for speed, that I didn't loop the byte, or the line routines.
104 straightlined calls to a straightlined byte output engine.
Ouch.


>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.

Well, you can always underclock, or use the FDIV register.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.