Hello Group.....<br><br>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:
<br clear="all"><br><br>void SpiWriteByte(unsigned char byte)<br>{<br> USISR = (1 << USIOIF);<br> USIDR = byte;<br>}<br>//---------------------------------------------------------------------<br>unsigned char Read_USI_SPI_Byte(void)
<br>{<br> USISR = (1 << USIOIF);<br> while(1)<br> {<br> if(USISR & (1 << USIOIF)) return USIDR;<br> if(!(PINA & ENABLE)) break;<br> }<br> <br> return USIDR;<br>}<br>//------------------------------------------------------------------
<br>main()<br>{<br> USICR = 0x18; // init usi for 3-wire mode, external clock<br> while(1)<br> {<br> if(PINA & ENABLE) // enable pin - PortA.0<br> { <br> SpiWriteByte(0x01); // 1st "ACK" after enable
<br><br> channel = Read_USI_SPI_Byte(); // read pwm channel <br> SpiWriteByte(0x02); // "ACK" after command<br> <br> a = Read_USI_SPI_Byte(); // read hi-byte
<br> SpiWriteByte(0x04); // "ACK" after command<br> }<br> }<br>}<br>//------------------------------------------------------------------<br>
<br>I would expect the values 1, 2, 4 to be sent, but never do. I get data but it is not correct.<br>Any clues as to what may be wrong????<br><br>-- <br>Paul Mateer, AA9GG<br>Elan Engineering Corp.<br><a href="http://www.elanengr.com">
www.elanengr.com</a>