[Icc-avr] SPI does not work when code imported from Atmega8 to Atmega32

ali malihi ali_malihi at yahoo.com
Mon Feb 11 08:59:10 PST 2008


  Dear friends,

I interfaced AT45DB161 16 Megabit data flash to Atmeag8 using SPI sucessfully. 
and can read and write without problems.

void M8_SPI_init (void)
{
SetBit(PORTB,PB2); //Set SS high 
DDRB |= BIT(DDB2) | BIT(DDB3)| BIT(DDB5); //Set SS, MOSI and SCK as outputs
ClrBit(DDRB, DDB4); // MISO as input
SPCR = BIT(SPE) | BIT(MSTR) | BIT(CPHA) | BIT(CPOL); //Enable SPI in Master mode, mode 3
//SPR1,SPR0=00 means SPI clock rate fcpu/4 8/4=2MHz
while(!(Read_DF_status() & 0x80)) WDR(); 
}

but when it is imported to Atmega32, considering SPI pin differance and <iom32v.h> 
istead of <iom8v.h>, it does not work.
here is new initialization routine:

void M32_SPI_init (void)
{
SetBit(PORTB,PB4); //Set SS high 
DDRB |= BIT(DDB4) | BIT(DDB5)| BIT(DDB7); //Set SS, MOSI and SCK as outputs
ClrBit(DDRB, DDB6); // MISO as input
SPCR = BIT(SPE) | BIT(MSTR) | BIT(CPHA) | BIT(CPOL); //Enable SPI in Master mode, mode 3
//SPR1,SPR0=00 means SPI clock rate fcpu/4 8/4=2MHz
while(!(Read_DF_status() & 0x80)) WDR(); 
}
Is there something different between Atmega8 and Atmega32 SPI?
your comments are welcome.

I use ICCAVR 6.30B.
SS pin is used for data flash chip select(CS).


Ali Malihi


       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080211/d16daf1d/attachment.html


More information about the Icc-avr mailing list