[Icc-avr] USI SPI Write?

Paul Mateer paul.aa9gg at gmail.com
Thu May 17 09:33:08 PDT 2007


Hello Group.....

Does anyone have a GOOD example (in C) on how to do a write on the USI SPI?
I'm using a Tiny44 in SLAVE mode and I can get it to read the data coming
in, but I can't seem to get it to write correctly.  I'm trying to have it
send a response after it receives a command. Here is what I have:


void SpiWriteByte(unsigned char byte)
{
  USISR = (1 << USIOIF);
  USIDR = byte;
}
//---------------------------------------------------------------------
unsigned char Read_USI_SPI_Byte(void)
{
  USISR = (1 << USIOIF);
  while(1)
   {
      if(USISR & (1 << USIOIF)) return USIDR;
      if(!(PINA & ENABLE)) break;
   }

   return USIDR;
}
//------------------------------------------------------------------
main()
{
  USICR = 0x18;  // init usi for 3-wire mode, external clock
  while(1)
   {
       if(PINA & ENABLE)  // enable pin - PortA.0
        {
             SpiWriteByte(0x01);   // 1st "ACK" after enable

              channel = Read_USI_SPI_Byte();  // read pwm channel

              SpiWriteByte(0x02);  // "ACK" after command

              a = Read_USI_SPI_Byte();  // read hi-byte
              SpiWriteByte(0x04);  // "ACK" after command
        }
    }
}
//------------------------------------------------------------------

I would expect the values 1, 2, 4 to be sent, but never do.  I get data but
it is not correct.
Any clues as to what may be wrong????

-- 
Paul Mateer, AA9GG
Elan Engineering Corp.
www.elanengr.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20070517/b9894ddf/attachment.html


More information about the Icc-avr mailing list