In need of a little SPI help / setup configuration mega 8535
2003-12-10 by cpp103
I seem to have SPI communication problems, my guess is the
hardware/register setup. Can anyone offer suggestions??
I seem to drop bits. I am sending the byte 0x1c (00011100), on the
receive I get 0x0e ( 00001110 ) occasionally, and its completely
random in occurance.
I have set up counters on the slave device, on some tests I will get
> 50 million bytes sent before errors occur, on some runs < 1000
before errors, once errors occur they continue to happen more
frequent.
I do not believe there is any software related issues, all ISR's are
only a couple of lines long, and my spi freq 115.2khz ( 14.7456 mhz
clock)
My hardware setup is a self made protoboard, plenty of 5v clean
power, 10k pullups on the 3 spi lines, ss line tied to gnd. LCD
telling me what is happening in the processor.
I only have the two processors, supporting r's and c's and an LCD.
I question the register setup and data direction, and internal pullup
usage. What is the correct configuration of each?
I hope someone can help, I'm a little lost here.
Thanks in Advance -
Ray
CodeVision compiler used, here is my setup configurations:
slave device:
PORTB=0x52; // State0=0 State1=P State2=0 State3=0 State4=1 State5=0
State6=P State7=0 ORIGINAL SET SORT OF WORKS
DDRB=0xBD; // Func0=Out Func1=In Func2=Out Func3=Out Func4=Out
Func5=Out Func6=In Func7=Out
// SPI initialization
// SPI Type: Slave
// SPI Clock Rate: 115.200 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0xC2;
SPDR = 0x00;// an initial setting
#asm
in r30,spsr
in r30,spdr
#endasm
interrupt [SPI_STC] void SPI_Recv_ISR(void)
{
unsigned char chardata;
chardata = SPDR;
SPDR = 0;
if(chardata != 28)
{
if(++ErrorCount == 0) // sent to display
{
++erroverflow; // sent to display
}
}
if(++BytesReceived == 0)
{
if(++BytesRecvOverflow == 0) // sent to display
{
++Overflow2; // sent to display
}
}
Master Device:
#include <spi.h>
PORTB=0x40; // State0=T State1=T State2=T State3=T State4=0 State5=0
State6=P State7=0
DDRB=0xB0; // Func0=In Func1=In Func2=In Func3=In Func4=Out
Func5=Out Func6=In Func7=Out
// SPI Type: Master Clock Rate: 115.200 kHz Clock Phase: Cycle Half
Polarity: Low Data Order: MSB First
SPCR=0x53;
SPSR=0x00;
void main(void)
{
while(1)
{
spi(28);
};
}