nRF905 TX power and frequency

Since my other one seems to have mysteriously vanished, I will give the update on this brand new post. I was able to figure out how to use most of what I need but I still am stumped with setting the frequency.

/*
 * Project: nRF905 AVR/Arduino Library/Driver
 * Author: Zak Kemble, contact@zakkemble.co.uk
 * Copyright: (C) 2013 by Zak Kemble
 * License: GNU GPL v3 (see License.txt)
 * Web: http://blog.zakkemble.co.uk/nrf905-avrarduino-librarydriver/
 */

/*
 * Time how long it takes to send some data and get a reply
 * Should be around 14-16ms with default settings.
 *
 * 7 -> CE
 * 8 -> PWR
 * 9 -> TXE
 * 2 -> CD
 * 3 -> DR
 * 10 -> CSN
 * 12 -> SO
 * 11 -> SI
 * 13 -> SCK
 */

#include <nRF905.h>
#include <SPI.h>

#define RXADDR {0xFE, 0x4C, 0xA6, 0xE5} // Address of this device (4 bytes)
#define TXADDR {0x58, 0x6F, 0x2E, 0x10} // Address of device to send to (4 bytes)

#define TIMEOUT 1000 // 1 second ping timeout




void setup()
{
	// Start up
	nRF905_init();

//  Transmit level 10db
	nRF905_setTransmitPower(NRF905_PWR_10);

nRF905_setFrequency(nRF905_band_t band, uint32_t 915000000);

	// Set address of this device
	byte addr[] = RXADDR;
	nRF905_setRXAddress(addr);

	// Put into receive mode
	nRF905_receive();

	Serial.begin(9600);
	
	Serial.println(F("Client started"));
}

void loop()
{
	static byte counter;

	// Make data
	char data[NRF905_MAX_PAYLOAD] = {0};
	sprintf(data, "test %hhu", counter);
	counter++;

	unsigned long startTime = millis();

	// Set address of device to send to
	byte addr[] = TXADDR;
	nRF905_setTXAddress(addr);

	// Set payload data
	nRF905_setData(data, sizeof(data));

	// Send payload (send fails if other transmissions are going on, keep trying until success)
	while(!nRF905_send());

	// Put into receive mode
	nRF905_receive();

	// Make buffer for reply
	byte buffer[NRF905_MAX_PAYLOAD];
	bool success;

	// Wait for reply with timeout
	unsigned long sendStartTime = millis();
	while(1)
	{
		success = nRF905_getData(buffer, sizeof(buffer));
		if(success)// Got data
			break;

		// Timeout
		if(millis() - sendStartTime > TIMEOUT)
			break;
	}

	if(success)
	{
		unsigned int totalTime = millis() - startTime;
		Serial.print(F("Ping time: "));
		Serial.print(totalTime);
		Serial.println(F("ms"));

		// Printout ping contents
		Serial.print(F("Data from server: "));
		Serial.write(buffer, sizeof(buffer));
		Serial.println();
	}
	else
		Serial.println(F("Ping timed out"));

	delay(1000);
}

This is the line that has me stumped:

nRF905_setFrequency(nRF905_band_t band, uint32_t 915000000);

I was trying to figure it out from:

/**

  • Set frequency, workout the channel from the frequency
  • 433MHz band: 422.4MHz - 473.5MHz, 100KHz steps
  • 868/915MHz band: 844.8MHz - 947MHz, 200KHz steps
  • @param [band] Frequency band
  • @param [freq] Frequency in Hz
  • @return (none)
    */
    void nRF905_setFrequency(nRF905_band_t band, uint32_t freq);

All that is in the header nRF905.h

Library I got from github:

Thanks in advance!

Bob

Hi Bob

Looks like you need to change your function call to this:

nRF905_setFrequency(NRF905_BAND_915, 915000000UL);

In the library .h file, there are three options defined for the first argument:

NRF905_BAND_433 = 0x00,	/**< 433MHz band */
NRF905_BAND_868 = 0x02,	/**< 868MHz band */
NRF905_BAND_915 = 0x0

Regards

Ray

nRF905_setFrequency(NRF905_BAND_915, 915000000UL);

I see what I did wrong with the first part, I had lowercase letters because I wasn't paying close attention. I never did find the other half of it though (The 2nd argument), I'm not sure where that was pointing to. I also don't understand the "UL" after it. Thanks!

Thanks so much for that hackscribble, it compiled for me, now I just need to figure out why :slight_smile:

Bob

Edit: I read up on UL and found that it is for Unsigned Long. I assume this is just a default when nothing else really goes there?