SV: [Icc-avr] SPI does not work when code imported from Atmega8
toAtmega32
Bengt Ragnemalm
benra at imt.liu.se
Mon Feb 11 23:33:29 PST 2008
Hi.
I do not think there are any difference in the way you are using the SPI.
You have set the correct pins to output, SPCR is the same and so on.
I think you should look into other reasons like SPI double speed setting or
AVR clock speed. Are you using the same type of data flash chip? Also check
that you are not touching any unused register bits in the mega8 code that
may have a purpose in mega32. I can see that you are using the Watchdog and
that module have changed. See WDTCR.
/Bengt
_____
Från: icc-avr-bounces at imagecraft.com [mailto:icc-avr-bounces at imagecraft.com]
För ali malihi
Skickat: den 11 februari 2008 17:59
Till: icc-avr at imagecraft.com
Ämne: [Icc-avr] SPI does not work when code imported from Atmega8 toAtmega32
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
<http://us.rd.yahoo.com/evt=51438/*http:/www.yahoo.com/r/hs> your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080212/045b9f3a/attachment.html
More information about the Icc-avr
mailing list