Other Parts Discussed in Thread: TMS320F28027, CC2500
Hello everybody
I try to connect the CC2500 to my TMS320F28027. So i set up the SPI Interface and it works already. For example i can change the frequency of the CC2500.
Now i need to read out a register value of the CC2500. My code looks like this:
char CC2500_SPIReadReg(char addr)
{
Uint16 i;
char x; /* Return variable */
i = (addr | CC2500_READ_SINGLE); /* Add Single Read to Register address */
while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1) /* Wait for SPITXBUF is free */
{
}
SpiaRegs.SPITXBUF = (i<<8); /* Send Register address */
while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1) /* Wait for SPITXBUF is free */
{
}
SpiaRegs.SPITXBUF = 0x00; /* Send dummy data */
CC2500_Wait(500);
x = SpiaRegs.SPIRXBUF; /* Read RXBUF */
return x; /* Return RXBUF */
}
It works fine and gives me the correct register value back. My Problem is now that i have to use the CC2500_Wait function. If i change the data rate the Delay time has to be changed also. So i want to realize it by using the Flags in the SPI Status Register.
My Code looks like this now:
char CC2500_SPIReadReg(char addr)
{
Uint16 i;
char x; /* Return variable */
i = (addr | CC2500_READ_SINGLE); /* Add Single Read to Register address */
while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1) /* Wait for SPITXBUF is free */
{
}
SpiaRegs.SPITXBUF = (i<<8); /* Send Register address */
while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1) /* Wait for SPITXBUF is free */
{
}
x = SpiaRegs.SPIRXBUF; /* Read RXBUF to clear INT_FLAG */
SpiaRegs.SPISTS.bit.OVERRUN_FLAG = 1;
SpiaRegs.SPITXBUF = 0x00; /* Send dummy data */
while (SpiaRegs.SPISTS.bit.INT_FLAG == 0) /* Wait for Tx to finish */
{
}
x = SpiaRegs.SPIRXBUF; /* Read RXBUF */
return x; /* Return RXBUF */
}
With this code i don't get the right value back. I think when i read the SPIRXBUF the INT_Flag is cleared and set again when the next data is placed in the SPIRXBUF. But it seems that my while (SpiaRegs.SPISTS.bit.INT_FLAG == 0) doesn't wait for the new data. After i called the function i see that in the RXBUF is the correct register value but in the x variable is the dummy data. So i read out the RXBUF to soon. If i use breakpoints inside the function it gives me the correct register value back.
Can somebody tell me my fault? Do i use the wrong flags?