Hi all,
I'm using the PIC32MX360F512L to control the CC2500 trasceiver through the SPI interface (in 8bit mode).
To read a single CC2550 register I need to send a header byte containing the R/W bit set to 1, the burst bit to 0 (single read) and the register address. Once this header byte is sent, the next 8 clock pulses will make me receive on the MISO pin the register value requested in the header.
However to successfully read the register content I need to perform this operation TWICE in a row, otherwise I read back a 15 (in decimal, meaning it's all 1).
Does anyone know why I have to make a dummy read first in order to get the proper value?
Same thing happens when I try to send a strobe command, in order to send it I need to send it twice.
I think I'm making a logical or TIMING mistake somewhere in my read function but I can't figure out what's wrong..
My read function is:
BYTE readRegister(BYTE registro){
BYTE value, mask,mask1;
//the register value has to be padded with the mask +10000000 (READ MODE and SINGLE ACCESS)
//the mask 10000000 in hex is 0x80
mask = 0x80; //this mask is used in the OR, it always adds the 1 for the reading 10000000
mask1 = 0xBF; //this mask is used to ensure the burst bit is always set to zero AND10111111 = 0xBF
value = 0;
CSlow(); //this enables the CC2500 trasceiver
while(!CCready()); //when the CC2500 is ready to communicate it puts MISO low and the function goes on
SPI1BUF = ((registro | mask) & mask1); //this sends the header with the register that i want to read
while(!SpiChnTxBuffEmpty(1)); //exits when the transmit buffer is empty
SPI1BUF = 0x00; //this sends a 0x00 just to make the clock toggle in order to read
while(!SpiChnTxBuffEmpty(1)); //exits when the transmit buffer is empty
value = SPI1BUF; // THIS SHOULD BE THE CORRECT RESULT BUT IF I RETURN THE VALUE AT THIS POINT I GET A 0 RESULT.. why??? :o
//here i do everythig again to workaround the problem, and the result at the end is correct..
SPI1BUF = ((registro | mask) & mask1);
while(!SpiChnTxBuffEmpty(1));
SPI1BUF=0x00;
while(!SpiChnTxBuffEmpty(1));
value = SPI1BUF; //now I get the correct result..
//In this way the read function works..
return value;
CShigh();
}
thanks in advance