Here is all the code to date, its based on the elechouse CC1101 libraries. I have 10k pull up resistors on the CS lines (D8 and D9) and 10k resisters to Vcc and GND for the MISO line as described in the www.dorkbotpdx.org blog
The voltage divider for the MISO line is clearly described as a test mechanism for chips with badly designed SPI interface. This is not a circuit that should be used in normal operation.
The pull-ups on the CS lines is a blog author's way to remedy a lack of software knowledge with half-baked hardware modifications. My recommendation: don't use it.
To your code:
Eliminate all occurrences of this:
while(digitalRead(MISO_PIN));
It's not needed if the hardware is correct (see above).
Reset(CC1101_PATABLE,TSS_PIN);
but
void Reset (int SLAVEPIN, byte SRES)
I guess the reset is not doing what you intend it to do as the calling parameters don't match the routine definition.
void SpiWriteReg(byte ADDR, byte VALUE, int SLAVEPIN)
{
SPI.beginTransaction(settingsR);
digitalWrite(SLAVEPIN,LOW);
while(digitalRead(MISO_PIN));
SPI.transfer(ADDR);
delay(100);
SPI.transfer(VALUE);
digitalWrite (SLAVEPIN, HIGH);
SPI.endTransaction();
}
Eliminate the delay() call! In the 100ms you wait there the SPI bus can transfer 50kB of data. A chip may expect a bus failure if the delay after the register address is sent to the sending of the value is that long.
void SendData(byte *txBuffer,byte Datasize,int SLAVEPIN,int GDO0_PIN,int GDO2_PIN,byte SFTX)
{
Serial.println("In Send Data......");
digitalWrite (SLAVEPIN, LOW);
SpiWriteReg(CC1101_TXFIFO,Datasize,SLAVEPIN);
digitalWrite (SLAVEPIN, LOW);
SpiWriteBurstReg(CC1101_TXFIFO,txBuffer,Datasize,SLAVEPIN); //write data to send
digitalWrite (SLAVEPIN, LOW);
SpiStrobe(CC1101_STX,SLAVEPIN); //start send
while (!digitalRead(GDO0_PIN)); // Wait for GDO0 to be set -> sync transmitted
while (digitalRead(GDO0_PIN)); // Wait for GDO0 to be cleared -> end of packet
digitalWrite (SLAVEPIN, LOW);
SpiStrobe(SFTX,SLAVEPIN); //flush TXfifo
}
Introduce a timeout in the while loops to be able to react on bad transmission failures.
byte SpiReadReg(byte addr, int SSPIN)
{
byte temp, value;
SPI.beginTransaction(settingsR);
temp = addr|READ_SINGLE;
digitalWrite(SSPIN, LOW);
while(digitalRead(MISO_PIN));
SPI.transfer(temp);
value=SPI.transfer(0);
digitalWrite(SSPIN, HIGH);
SPI.endTransaction();
return value;
}
byte SpiReadStatus(byte addr, int SLAVEPIN)
{
byte value,temp;
temp = addr | READ_BURST;
digitalWrite(SLAVEPIN, LOW);
while(digitalRead(MISO_PIN));
SPI.transfer(temp);
value=SPI.transfer(0);
digitalWrite(SLAVEPIN, HIGH);
return value;
}
Please explain the lack of SPI.beginTransaction() in the second function. On a Nano the SPI.beginTransaction and SPI.endTransaction calls are not really necessary but you should use them consistently.