I'm trying to transmit 4 bytes of data from a CC2530 configured as SPI slave. The problem is that the first byte is always transmitted twice as you can see from the image below taken from a logic analyzer:
Here's my code:
void SPI_Init(void)
{
PERCFG |= 0x02; // select alternative 2 location
P1SEL |= 0xF0; // set pins 4-7 as peripheral
U1CSR &= ~0x80; // set USART mode to SPI
U1CSR |= 0x20; // slave mode
U1GCR &= ~0x80; // polarity
U1GCR &= ~0x40; // phase: samples on rising edge
U1GCR |= 0x20; // MSB first
}
//**********Slave code: just polls for now*************//
for ( i=0; i<length; i++)
{
U1CSR &= ~0x04; // clear Rx flag
U1DBUF = data[i]; // write byte to buffer
while((U1CSR&0x04)==0x00); // wait for Rx flag
U1CSR &= ~0x04; // clear Rx flag
}
Any ideas?