# Forum: ARM programming with GCC/GNU tools ATMega324P and ATA5811 problem

 Author: Chris H. (rentien) Posted on: 2008-02-24 10:58

Rate this post
 0 ▲ useful ▼ not useful
So i'm trying to get my atmega324p (both atmel parts) and ata5811
transceiver to work and begin trasmission for my school project. I can't
seem to get the two to work... i was wondering if anyone could give me
any insight as to whats wrong with my setup or code.

Basically i have wired over the ATA5811 via SPI to the
Microcontroller... and i have PORTA going to 8 LED's to display over to
me what... numbers are being passed around so... here is my code.

void SPI_init(void){

DDRB = ((1<<DDB4)|(1<<DDB5)|(0<<DDB6)|(1<<DDB7)); //spi pins on port b
MOSI,SCK,SS outputs, MISO input
SPCR =
((1<<SPE)|(1<<MSTR)/*|(1<<SPR0)*/|(1<<CPOL)|(1<<CPHA)|(0<<DORD));  //
SPI enable, Master, f/16

}

char SPI_Transmit(char cData){

SPDR = cData;
while(!(SPSR & (1<<SPIF)))
;
return SPDR;
}

void main()
{
DDRA=0xFF;     //All A port pins as output
PORTA=~0;
DDRC=0xFF;    //All C port pins as output
SPI_init();

while(1)
{

PORTC=~1;
PORTC=~0;

SPI_Transmit(96);
//h=SPDR;
SPI_Transmit(194);
SPI_Transmit(72);
SPI_Transmit(72);
a=SPDR;

PORTA=~a;
for (n=1; n<5; n++)
_delay_loop_2(20000);
and i didn't finish the closed brackets.

anyways the problem is... no matter what i put for the SPI_Transmit
command 2 commands before a = SPDR, i just get an echo of the command
out on the LEDs... so in this case, i get 72... so... and the data sheet
says if i send a read command of a control register i should get back
the... settings on that register... which isn't the same as the command
i sent to read it. (for write commands however, you are supposed to just
to the ata5811 i guess)

so my question is why can't i get the read command to send me the
settings on the registers instead of... just an echo of the read command
i sent in... which is useless to me. Thanks in advance for you guys'
help.

Chris

• $formula (LaTeX syntax)$