Yahoo Groups archive

AVR-Chat

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

Message

Re: [AVR-Chat] Code stuck waiting for SPI transmission but only after power-up. (ATMega644P)

2010-03-13 by erikc

My two cents:

I find it helpful to provide the CPU with its very own voltage 
regulator (something like a 78L05 is sufficient) to be very helpful.
Make sure to properly bypass the regulator on both input and output 
with at least 2 uF.

Any routine I write that depends on a response from a peripheral is
also coded with a counter to act as a timer.  The number of counts
is chosen so that the expiration time is well in excess of the 
response time of the peripheral.  If the counter expires, it is
assumed that something caused the peripheral not to respond in a
timely manner.  This is especially useful with peripherals using
handshaking.

Here is how I do SPI.

bool SPISend( char c)
{
    short counter;

    SPDR = c;
    counter = 10000;           // or some other appropriate number
    while(!(SPSR & (1<<SPIF))  // Wait for transmission complete
        && (counter > 0)       // and counter not zeroed
    { counter--; }
    return( counter > 0)	      // counter > 0 so xmit successful
} /* SPISend */

Mike wrote:
> Cat,
> 
> All you emails seems to me to somehow keep pointing to Power Supply.
> BrownOut condition during start-up?
> 
> If I press the reset button all is fine, so maybe strange things happen because power might go up too slow.
> 
> Can you verify this, purhaps a different supply? Hopefully.
> 
> Wish I could be of more help.
> 
> Mike
> 
> 
> 
> 
>   ----- Original Message ----- 
>   From: Cat C 
>   To: avr-chat@yahoogroups.com 
>   Sent: Thursday, March 11, 2010 11:14 AM
>   Subject: [AVR-Chat] Code stuck waiting for SPI transmission but only after power-up. (ATMega644P)
> 
> 
>     
> 
>   Me again... :-)
> 
>   My code sends stuff over SPI, like this:
> 
>   SPDR = something;
>   while(!(SPSR & (1<<SPIF))) //Wait for transmission complete
>   { ; }
> 
>   I know I should have a counter and get out with an error, but... that's beside the point...
> 
>   This used to work fine, but at some point it started to get stuck on the "while" first time I power up the board.
>   It works fine after a reset.
> 
>   Any ideas please?
> 
>   Thanks,
> 
>   Cat

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.