I am a beginer.I have some trouble in writing and reading data when controling the RF chip,SI4432.The problem is,i read what i write to the slaver,and cannot read the right value of the selected register.Here are some related codes.
SPI initial
void Spi_Init()
{
U0CTL = CHAR + SYNC + MM + SWRST; // 8-bit, SPI, Master
U0TCTL = SSEL1 + STC; // Polarity, SMCLK, 3-wire
U0BR0 = 0x08; // SPICLK = SMCLK/2
U0BR1 = 0x000;
U0MCTL = 0x000;
ME1 |= USPIE0; // Module enable
U0CTL &= ~SWRST; // SPI enable
P3DIR |= (BIT1 + BIT3 + BIT5 + BIT4);
P3DIR &= ~BIT2;
}
Write one byte to the selected register
void SpiWriteRegister(uint8 addr, uint8 value)
{
RF4432_SEL_0;
IFG1 &= ~UTXIFG0;
TXBUF0 = (addr|WR);
while ((IFG1 & UTXIFG0) == 0);
IFG1 &= ~UTXIFG0;
TXBUF0 = value;
while ((IFG1 & UTXIFG0) == 0);
RF4432_SEL_1;
}
Read one byte from the selected register
uint8 SpiReadRegister(uint8 addr)
{
uint8 value=0;
RF4432_SEL_0;
IFG1 &= ~UTXIFG0;
TXBUF0 = (addr|RR);
while (!(IFG1 & UTXIFG0));
IFG1 &= ~UTXIFG0;
TXBUF0 = 0xff;
while (!(IFG1 & URXIFG0));
value = U0RXBUF;
while (!(IFG1 & UTXIFG0));
RF4432_SEL_1;
return value;
}
When excuting SpiReadRegister(0x03),for example,the return value is 0x03,not the value of this register.I wonder if there is someone can help,many thanks!