ATMega324P and ATA5811 problem

OP #1173519
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
get echoes of your commands so you can verify that your command made it
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

Reply

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.