// Reset CC1101 (requires implementation here since microsecond delay can't be done reliably via serial)
void resetRf()
{
	cc1101_Deselect(); 
	delayMicroseconds(5);
  cc1101_Select();
	delayMicroseconds(10);
	cc1101_Deselect();
	delayMicroseconds(41);
	cc1101_Select();

  wait_Miso();
	SPI.transfer(0x30); // SRES
  wait_Miso();

	cc1101_Deselect();
}
Beispiel #2
0
void    CC110x::readBurst(uint8_t *buf, uint8_t regAddr, uint8_t len) {					// read burst data from CC1101 via SPI
	cc1101_Select();																	// select CC1101
	wait_Miso();																		// wait until MISO goes low
	sendSPI(regAddr | READ_BURST);														// send register address
	for(uint8_t i=0 ; i<len ; i++) buf[i] = sendSPI(0x00);								// read result byte by byte
	cc1101_Deselect();																	// deselect CC1101
}
Beispiel #3
0
void    CC110x::writeBurst(uint8_t regAddr, uint8_t *buf, uint8_t len) {				// write multiple registers into the CC1101 IC via SPI
	cc1101_Select();																	// select CC1101
	wait_Miso();																		// wait until MISO goes low
	sendSPI(regAddr | WRITE_BURST);														// send register address
	for(uint8_t i=0 ; i<len ; i++) sendSPI(buf[i]);										// send value
	cc1101_Deselect();																	// deselect CC1101
}
Beispiel #4
0
/**
 * cmdStrobe
 * 
 * Send command strobe to the CC1101 IC via SPI
 * 
 * 'cmd'	Command strobe
 */     
void CC1101::cmdStrobe(byte cmd) 
{
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  spi.send(cmd);                        // Send strobe command
  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #5
0
/**
 * readReg
 *
 * Read CC1101 register via SPI
 *
 * 'regAddr'    Register address
 * 'regType'    Type of register: CC1101_CONFIG_REGISTER or CC1101_STATUS_REGISTER
 *
 * Return:
 *      Data byte returned by the CC1101 IC
 */
byte CC1101_readReg(byte regAddr, byte regType)
{
  byte addr, val;

  addr = regAddr | regType;
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low

//  // have to do it twice for some reason, first read fails
//  spi_send(addr);                       // Send register address
//  //val = spi_send(addr);
//  DSK6713_waitusec(5);
//  //DSK6713_waitusec(25);
//  val = spi_send(0x00);                 // Read result
//  DSK6713_waitusec(20);
//
//  spi_send(addr);                       // Send register address
//  DSK6713_waitusec(5);
//  val = spi_send(0x00);                 // Read result
//  DSK6713_waitusec(20);

  val = spiReadReg(addr);

  cc1101_Deselect();                    // Deselect CC1101

  return val;
}
Beispiel #6
0
uint8_t CC110x::detectBurst(void) {														// wake up CC1101 from power down state
	// 10 7/10 5 in front of the received string; 33 after received string
	// 10 - 00001010 - sync word found
	// 7  - 00000111 - GDO0 = 1, GDO2 = 1
	// 5  - 00000101 - GDO0 = 1, GDO2 = 1
	// 33 - 00100001 - GDO0 = 1, preamble quality reached
	// 96 - 01100000 - burst sent
	// 48 - 00110000 - in receive mode
	//
	// Status byte table:
	//	0 current GDO0 value
	//	1 reserved
	//	2 GDO2
	//	3 sync word found
	//	4 channel is clear
	//	5 preamble quality reached
	//	6 carrier sense
	//	7 CRC ok
	//
	// possible solution for finding a burst is to check for bit 6, carrier sense

	// set RXTX module in receive mode
	cc1101_Select();																	// select CC1101
	wait_Miso();																		// wait until MISO goes low
	cc1101_Deselect();																	// deselect CC1101
	cmdStrobe(CC1101_SRX);																// set RX mode again
	_delay_ms(3);																		// wait a short time to set RX mode

	// todo: check carrier sense for 5ms to avoid wakeup due to normal transmition
	//Serial << F("rx\n");
//	return bitRead(hm.cc.monitorStatus(),6);											// return the detected signal
	return bitRead(monitorStatus(),6);													// return the detected signal
}
Beispiel #7
0
void    CC110x::writeReg(uint8_t regAddr, uint8_t val) {								// write single register into the CC1101 IC via SPI
	cc1101_Select();																	// select CC1101
	wait_Miso();																		// wait until MISO goes low
	sendSPI(regAddr);																	// send register address
	sendSPI(val);																		// send value
	cc1101_Deselect();																	// deselect CC1101
}
Beispiel #8
0
/**
 * writeReg
 * 
 * Write single register into the CC1101 IC via SPI
 * 
 * 'regAddr'	Register address
 * 'value'	Value to be writen
 */
void CC1101::writeReg(byte regAddr, byte value) 
{
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  spi.send(regAddr);                    // Send register address
  spi.send(value);                      // Send value
  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #9
0
uint8_t CC110x::readReg(uint8_t regAddr, uint8_t regType) {								// read CC1101 register via SPI
	cc1101_Select();																	// select CC1101
	wait_Miso();																		// wait until MISO goes low
	sendSPI(regAddr | regType);															// send register address
	uint8_t val = sendSPI(0x00);														// read result
	cc1101_Deselect();																	// deselect CC1101
	return val;
}
Beispiel #10
0
/**
 * reset
 * 
 * Reset CC1101
 */
void CC1101::reset(void) 
{
  cc1101_Deselect();                    // Deselect CC1101
  delayMicroseconds(5);
  cc1101_Select();                      // Select CC1101
  delayMicroseconds(10);
  cc1101_Deselect();                    // Deselect CC1101
  delayMicroseconds(41);
  cc1101_Select();                      // Select CC1101

  wait_Miso();                          // Wait until MISO goes low
  spi.send(CC1101_SRES);                // Send reset command strobe
  wait_Miso();                          // Wait until MISO goes low

  cc1101_Deselect();                    // Deselect CC1101

  setDefaultRegs();                     // Reconfigure CC1101
  setRegsFromEeprom();                  // Take user settings from EEPROM
}
Beispiel #11
0
/**
 * reset
 *
 * Reset CC1101
 */
void CC1101_reset(void)
{
  cc1101_Deselect();                    // Deselect CC1101
  DSK6713_waitusec(5);
  cc1101_Select();                      // Select CC1101
  DSK6713_waitusec(10);
  cc1101_Deselect();                    // Deselect CC1101
  DSK6713_waitusec(41);
  cc1101_Select();                      // Select CC1101

  wait_Miso();                          // Wait until MISO goes low
  //spi_send(CC1101_SRES);                // Send reset command strobe
  spiWriteReg(CC1101_SRES,0x00);
  wait_Miso();                          // Wait until MISO goes low

  cc1101_Deselect();                    // Deselect CC1101

  CC1101_setDefaultRegs();                     // Reconfigure CC1101
  //setRegsFromEeprom();                  // Take user settings from EEPROM
}
Beispiel #12
0
/**
 * readBurstReg
 * 
 * Read burst data from CC1101 via SPI
 * 
 * 'buffer'	Buffer where to copy the result to
 * 'regAddr'	Register address
 * 'len'	Data length
 */
void CC1101::readBurstReg(byte * buffer, byte regAddr, byte len) 
{
  byte addr, i;
  
  addr = regAddr | READ_BURST;
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  spi.send(addr);                       // Send register address
  for(i=0 ; i<len ; i++)
    buffer[i] = spi.send(0x00);         // Read result byte by byte
  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #13
0
/**
 * readReg
 * 
 * Read CC1101 register via SPI
 * 
 * 'regAddr'	Register address
 * 'regType'	Type of register: CC1101_CONFIG_REGISTER or CC1101_STATUS_REGISTER
 * 
 * Return:
 * 	Data byte returned by the CC1101 IC
 */
byte CC1101::readReg(byte regAddr, byte regType) 
{
  byte addr, val;

  addr = regAddr | regType;
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  spi.send(addr);                       // Send register address
  val = spi.send(0x00);                 // Read result
  cc1101_Deselect();                    // Deselect CC1101

  return val;
}
Beispiel #14
0
/**
 * writeBurstReg
 * 
 * Write multiple registers into the CC1101 IC via SPI
 * 
 * 'regAddr'	Register address
 * 'buffer'	Data to be writen
 * 'len'	Data length
 */
void CC1101::writeBurstReg(byte regAddr, byte* buffer, byte len)
{
  byte addr, i;
  
  addr = regAddr | WRITE_BURST;         // Enable burst transfer
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  spi.send(addr);                       // Send register address
  
  for(i=0 ; i<len ; i++)
    spi.send(buffer[i]);                // Send value

  cc1101_Deselect();                    // Deselect CC1101  
}
Beispiel #15
0
/**
 * CC1101_writeReg
 *
 * Write single register into the CC1101 IC via SPI
 *
 * 'regAddr'    Register address
 * 'value'      Value to be writen
 */
void CC1101_writeReg(byte regAddr, byte value)
{
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low

//  // waits are needed since CSn is triggered by GPIO which is not in accordance with SPI peripheral which takes few cycles to shift out after you order it
//  spi_send(regAddr);                    // Send register address
//  DSK6713_waitusec(5);
//  spi_send(value);                      // Send value
//  DSK6713_waitusec(20);

  spiWriteReg(regAddr, value);

  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #16
0
/**
 * cmdStrobe
 *
 * Send command strobe to the CC1101 IC via SPI
 *
 * 'cmd'        Command strobe
 */
void CC1101_cmdStrobe(byte cmd)
{
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low

//  spi_send(cmd);                        // Send strobe command
//
//  // send again, for some reason first send does not work
//  DSK6713_waitusec(10);
//  spi_send(cmd);                        // Send strobe command
//
//  DSK6713_waitusec(20);

  spiWriteReg(cmd,0x00);	// basically we only need to send 1 byte

  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #17
0
/**
 * readBurstReg
 *
 * Read burst data from CC1101 via SPI
 *
 * 'buffer'     Buffer where to copy the result to
 * 'regAddr'    Register address
 * 'len'        Data length
 */
void CC1101_readBurstReg(byte * buffer, byte regAddr, byte len)
{
  byte addr, i;

  addr = regAddr | READ_BURST;
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  //spi_send(addr);                       // Send register address
  spiWriteAddr(addr);
  //DSK6713_waitusec(5);

  for(i=0 ; i<len ; i++)
  {
    //buffer[i] = spi_send(0x00);         // Read result byte by byte
	  buffer[i] = spiReadData();         // Read result byte by byte
  	//DSK6713_waitusec(15);
  }

  //DSK6713_waitusec(20);

  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #18
0
/**
 * writeBurstReg
 *
 * Write multiple registers into the CC1101 IC via SPI
 *
 * 'regAddr'    Register address
 * 'buffer'     Data to be writen
 * 'len'        Data length
 */
void CC1101_writeBurstReg(byte regAddr, byte* buffer, byte len)
{
  byte addr, i;

  addr = regAddr | WRITE_BURST;         // Enable burst transfer
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  //spi_send(addr);                       // Send register address
  spiWriteAddr(addr);
  //DSK6713_waitusec(5);

  for(i=0 ; i<len ; i++)
  {
    //spi_send(buffer[i]);                // Send value
	  spiWriteData(buffer[i]);
    //DSK6713_waitusec(10);
  }

  //DSK6713_waitusec(20);

  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #19
0
/**
 * wakeUp
 * 
 * Wake up CC1101 from Power Down state
 */
void CC1101::wakeUp(void)
{
  cc1101_Select();                      // Select CC1101
  wait_Miso();                          // Wait until MISO goes low
  cc1101_Deselect();                    // Deselect CC1101
}
Beispiel #20
0
void    CC110x::cmdStrobe(uint8_t cmd) {												// send command strobe to the CC1101 IC via SPI
	cc1101_Select();																	// select CC1101
	wait_Miso();																		// wait until MISO goes low
	sendSPI(cmd);																		// send strobe command
	cc1101_Deselect();																	// deselect CC1101
}
void loop() 
{
  
  if (Serial.available() > 0) 
  {
    char inChar = Serial.read();

    // Filter all requests by having first char start with '{' and last char with '}'
    // Prevents serial garbage from affecting the parser (e.g. other app probing all serial ports)
    if (!isReading)
    {
      if (inChar == '{')
      {
        isReading = true;
      }
      else 
      {
        return;
      }
    }
    // read incoming serial data:
    inputBuffer[bufferIndex] = inChar;
    bufferIndex++;

    if (bufferIndex == 5)
    {
      bufferIndex = 0;
    }


    if (inChar == '}')
    {
      isReading = false;
      bufferIndex = 0;

      if (inputBuffer[4] != '}')
      {
        // command is not terminated correctly
        Serial.print("z0");
      }
      else 
      {
        byte command = inputBuffer[1];
        byte firstParameter = (convertCharToByte(inputBuffer[2]) << 4) | convertCharToByte(inputBuffer[3]);

        if (command == 'a')
        {
          resetRf();
          Serial.println("a1");
        }
        else if (command == 'b')
        {
          delay(firstParameter);
          Serial.println("b1");
        }
        else if (command == 'c')
        {
          cc1101_Select();
          Serial.println("c1");
        }
        else if (command == 'd')
        {
          cc1101_Deselect();
          Serial.println("d1");
        }
        else if (command == 'e')
        {
          wait_Miso();
          Serial.println("e1");
        }
        else if (command == 'f')
        {
          SPI.transfer(firstParameter);
          Serial.println("f1");
        }
        else if (command == 'g')
        {
          Serial.println("ATMEGA328P PRO MINI 0.1");
        }
      }
    }
  }  

}