Example #1
0
void TxData(unsigned char length) 
{
	unsigned char data2[6] = "techno", i;

	// Make sure that the radio is in IDLE state before flushing the FIFO
	SendStrobe(CC2500_IDLE);
	// Flush TX FIFO
	SendStrobe(CC2500_FTX);

	// SIDLE: exit RX/TX
	SendStrobe(CC2500_IDLE);

	for (i = 0; i < length; i++) {
		WriteReg(CC2500_TXFIFO, data2[i]);
	}
	// STX: enable TX
	SendStrobe(CC2500_TX);

	// Wait for GDO0 to be set -> sync transmitted
	while(!(GPIOA->IDR & GPIO_Pin_3));
//	while (!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3));

//      while (!GDO);

	// Wait for GDO0 to be cleared -> end of packet
		while(GPIOA->IDR & GPIO_Pin_3);
//	while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3));

//       while (GDO);

//lcd_data('k');
} // Rf TX Packet
Example #2
0
void RxData(void) 
{
	unsigned char data[6];
	char i, k;
	unsigned long int tag = 0;

	for (k = 0; k < 6; k++) {
		data[k] = '\0';
	} //CLEARING ARRAY

	// RX: enable RX
	SendStrobe(CC2500_RX);

	// Wait for GDO0 to be set -> sync received
	//    while (!GDO)
	//while (!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3))
	while(GPIOA->IDR &=(1<<3))
//	while(!(GPIOA->IDR & GPIO_Pin_3))
	{
		tag++;
		if (tag > 6500000)
		{
			tag = 0;
			break;
		}
	}

//    // Wait for GDO0 to be cleared -> end of packet

//    while (GDO)
//	while (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3))
//	while((GPIOA->IDR & GPIO_Pin_3))
	while(GPIOA->IDR &=(1<<3))
	{
		tag++;
		if (tag > 6500000)
		{
			tag = 0;
			break;
		}
	}

	// Read data from RX FIFO and store in rxBuffer
	for (i = 0; i < 6; i++) {
		data[i] = Read(CC2500_RXFIFO);
	}

	SendStrobe(CC2500_IDLE);
	// Flush RX FIFO
	SendStrobe(CC2500_FRX);

//lcd_str(data);
	tag = 0;
} // Rf RxPacket
//sets the frequency for the radio oscillator.
//int frequency = desired center frequency in Hz
//returns true if success, or false if failure. Should not fail.
boolean CC1200::SetFrequency(uint32_t frequency)
{
	//digitalWrite(8,HIGH);
	setState(CC1200_IDLE);
	SendStrobe(SFRX);
	int freq = 0.0065536f * frequency; //magic number comes from simplification of calculations from the datasheet with 40MHz crystal and LO Divider of 4.
	byte f0 = 0xFF & freq;
	byte f1 = (freq & 0xFF00) >> 8;
	byte f2 = (freq & 0xFF0000) >> 16;
#ifdef DEBUG_FREQUENCY
	Serial.print("Programming Frequency ");
	Serial.print(frequency);
	Serial.print(" MHz. Registers 0, 1, and 2 are 0x");
	Serial.print(f0, HEX);
	Serial.print(" 0x");
	Serial.print(f1, HEX);
	Serial.print(" 0x");
	Serial.println(f2, HEX);
#endif
	WriteReg(REG_FREQ0, f0);
	WriteReg(REG_FREQ1, f1);
	WriteReg(REG_FREQ2, f2);
	setState(CC1200_RX);

	if (ReadReg(REG_FREQ0) == f0 && ReadReg(REG_FREQ1) == f1 && ReadReg(REG_FREQ2) == f2)
	{
		//digitalWrite(8,LOW);
		return true;
	}
	else
	{
		//digitalWrite(8,LOW);
		return false;
	}
}
boolean CC1200::transmit(byte *txBuffer, byte start, byte length)
{
	if (asleep == true)
	{
		return false;
	}

	//check FIFO and radio state here
	byte txBytesUsed = 0;
	// Read number of bytes in TX FIFO
	ccReadReg(REG_NUM_TXBYTES, &txBytesUsed, 1);

	if (txBytesUsed > 0)
	{
		// Make sure that the radio is in IDLE state before flushing the FIFO
		setState(CC1200_IDLE);
		SendStrobe(SFTX); //flush buffer if needed
	}

	setState(CC1200_FSTX); //spin up frequency synthesizer
	byte data[length];

	for (int i = 0; i < length; i++)
	{
		data[i] = txBuffer[i + start]; //TODO: alter fifo access functions to allow passing txBuffer directly to read or write from a specific chunk of it
	}

	ccWriteTxFifo(data, length); //TODO: do error checking for underflow, CCA, etc.
#ifdef DEBUG1
	Serial.print("Writing ");
	Serial.print(length);
	Serial.println(" bytes: ");
	printBuffer(txBuffer, length);
#endif
	setState(CC1200_TX); //spin up frequency synthesizer
	return true;
}
Example #5
0
void CC2500::reset()
{
  SendStrobe(CC2500_CMD_SRES); 
}
void CC1200::reset()
{
	SendStrobe(SRES);
	delay(5);
	SendStrobe(SRES); //is twice necessary? Probably not. Does it cause problems? You tell me...
}