<FONT size=2> <div>Dear friends,<BR><BR>I interfaced AT45DB161 16 Megabit data flash to Atmeag8 using SPI sucessfully. <BR>and can read and write without problems.<BR><BR><B>void</B> M8_SPI_init (<B>void</B>)<BR>{<BR>SetBit(PORTB,PB2); </FONT><FONT color=#008000 size=2>//Set SS high </FONT><FONT size=2><BR>DDRB |= BIT(DDB2) | BIT(DDB3)| BIT(DDB5); </FONT><FONT color=#008000 size=2>//Set SS, MOSI and SCK as outputs</FONT><FONT size=2><BR>ClrBit(DDRB, DDB4); </FONT><FONT color=#008000 size=2>// MISO as input</FONT><FONT size=2><BR>SPCR = BIT(SPE) | BIT(MSTR) | BIT(CPHA) | BIT(CPOL); </FONT><FONT color=#008000 size=2>//Enable SPI in Master mode, mode 3</FONT><FONT size=2><BR></FONT><FONT color=#008000 size=2>//SPR1,SPR0=00 means SPI clock rate fcpu/4 8/4=2MHz</FONT><FONT size=2><BR><B>while</B>(!(Read_DF_status() & 0x80)) WDR(); <BR>}<BR><BR>but when it is imported to Atmega32, considering SPI pin differance and <iom32v.h> <BR>istead of <iom8v.h>, it does not
work.<BR>here is new initialization routine:<BR><BR><B>void</B> M32_SPI_init (<B>void</B>)<BR>{<BR>SetBit(PORTB,PB4); </FONT><FONT color=#008000 size=2>//Set SS high </FONT><FONT size=2><BR>DDRB |= BIT(DDB4) | BIT(DDB5)| BIT(DDB7); </FONT><FONT color=#008000 size=2>//Set SS, MOSI and SCK as outputs</FONT><FONT size=2><BR>ClrBit(DDRB, DDB6); </FONT><FONT color=#008000 size=2>// MISO as input</FONT><FONT size=2><BR>SPCR = BIT(SPE) | BIT(MSTR) | BIT(CPHA) | BIT(CPOL); </FONT><FONT color=#008000 size=2>//Enable SPI in Master mode, mode 3</FONT><FONT size=2><BR></FONT><FONT color=#008000 size=2>//SPR1,SPR0=00 means SPI clock rate fcpu/4 8/4=2MHz</FONT><FONT size=2><BR><B>while</B>(!(Read_DF_status() & 0x80)) WDR(); <BR>}<BR>Is there something different between Atmega8 and Atmega32 SPI?<BR>your comments are welcome.<BR><BR>I use ICCAVR 6.30B.<BR>SS pin is used <B>for</B> data flash chip select(CS).<BR><BR><BR>Ali Malihi<BR></div></FONT><p> 
<hr size=1>Never miss a thing. <a href="http://us.rd.yahoo.com/evt=51438/*http://www.yahoo.com/r/hs"> Make Yahoo your homepage.</a>