Exemplo n.º 1
0
uint8_t BayRF24::sendPayload(void) {
	if (_powerdown)
		powerUp();
	else
		stopListening();
	openWritingPipe (_pipe);
	uint8_t res;

	res = RF24::write(getPayload(), getPacketLength());
	uint8_t curr_pa = 0;
	while (!res && curr_pa < 4) {
		setPALevel((rf24_pa_dbm_e) curr_pa);
		delayMicroseconds(random(2000));
		res = RF24::write(getPayload(), getPacketLength());
		curr_pa++;
	}

	if (_powerdown)
		powerDown();
	else {
		txStandBy();
		startListening();
	}

	return !res;
}
Exemplo n.º 2
0
static void initHardware(void)
{
	Chip_SetupXtalClocking();
	Chip_SYSCTL_SetFLASHAccess(FLASHTIM_100MHZ_CPU);
    SystemCoreClockUpdate();


/*====================[PARA MODULO RF]====================*/
	Chip_GPIO_WriteDirBit(LPC_GPIO, CE_PIN, 1); //Puerto CE
	Chip_GPIO_SetPinOutLow(LPC_GPIO, CE_PIN); //Puerto CE
	InitSPI ();

	begin();
	setPALevel(RF24_PA_LOW);
	openWritingPipe(&addresses2[0]);
	openReadingPipe(1,&addresses1[0]);	//1Node: Transmite paquetes el tx por este pide (addres)

	startListening();

/*========================================================*/



//    Board_Init();

//    Board_LED_Set(0, false);

    SysTick_Config(SystemCoreClock/1000);		//1000 ticks por segundo

	InitPWM_motores(0);			//Función inicialización modulo PWM
	InitPWM_motores(1);			//Función inicialización modulo PWM
	InitPWM_motores(2);			//Función inicialización modulo PWM
	InitPWM_motores(3);			//Función inicialización modulo PWM
	InitPWM0();
	InitGPIO(0);			//Llamo función para inicializar GPIO
	InitGPIO(1);			//Llamo función para inicializar GPIO
	InitGPIO(2);			//Llamo función para inicializar GPIO
	InitGPIO(3);			//Llamo función para inicializar GPIO
	Stop_and_Default(0);	//Condiciones iniciales
	Stop_and_Default(1);	//Condiciones iniciales
	Stop_and_Default(2);	//Condiciones iniciales
	Stop_and_Default(3);	//Condiciones iniciales


    P2_6ER = 1;    P2_7ER = 1;    P2_8ER = 1;

    P2_6EF = 1;    P2_7EF = 1;    P2_8EF = 1;



    P0_15ER = 1;    P0_16ER = 1;    P2_9ER = 1;

    P0_15EF = 1;    P0_16EF = 1;    P2_9EF = 1;

    NVIC_SetPriority(EINT3_IRQn,1);			//Le pongo la mayor prioridad a la interrupcion
    NVIC_EnableIRQ(EINT3_IRQn);


}
Exemplo n.º 3
0
void BayRF24::init(uint64_t address, uint8_t c = 0x71, rf24_pa_dbm_e pa_level =
		RF24_PA_HIGH, rf24_datarate_e rate = RF24_250KBPS) {
	_pipe = address;
	RF24::begin();
	setChannel(c);
	setPayloadSize(32);
	enableDynamicPayloads();
	setCRCLength (RF24_CRC_16);
	setDataRate(rate);
	setPALevel(pa_level);
	_pa_level = pa_level;
//changed 0.1.2 - as we normally have a storage on board
//User can call client.setRetries(15,15) after client.init
	setRetries(15, 8);
	setAutoAck(true);
	if (_powerdown)
		powerDown();
}
Exemplo n.º 4
0
bool QRF24::begin()
{
    debug = true;

    // Init BCM2835 chipset for talking with us
    if (!bcm2835_init())
        return false;

    // Initialise the CE pin of NRF24 (chip enable)
    bcm2835_gpio_fsel(ce_pin, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_write(ce_pin, LOW);

    // used to drive custom I/O to trigger my logic analyser
    // bcm2835_gpio_fsel(GPIO_CTRL_PIN , BCM2835_GPIO_FSEL_OUTP);

    // start the SPI library:
    // Note the NRF24 wants mode 0, MSB first and default to 1 Mbps
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);

    // Set SPI bus Speed
    bcm2835_spi_setClockSpeed(spi_speed);

    // This initialize the SPI bus with
    // csn pin as chip select (custom or not)
    bcm2835_spi_begin(csn_pin);

    // wait 100ms
    delay(100);

    // Must allow the radio time to settle else configuration bits will not necessarily stick.
    // This is actually only required following power up but some settling time also appears to
    // be required after resets too. For full coverage, we'll always assume the worst.
    // Enabling 16b CRC is by far the most obvious case if the wrong timing is used - or skipped.
    // Technically we require 4.5ms + 14us as a worst case. We'll just call it 5ms for good measure.
    // WARNING: Delay is based on P-variant whereby non-P *may* require different timing.
    delay( 5 ) ;

    // Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier
    // WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet
    // sizes must never be used. See documentation for a more complete explanation.
    //printf("write_register(%02X, %02X)\n", SETUP_RETR, (0b0100 << ARD) | (0b1111 << ARC));
    writeRegister(SETUP_RETR,(0b0100 << ARD) | (0b1111 << ARC));

    // Restore our default PA level
    setPALevel( RF24_PA_MAX ) ;

    // Determine if this is a p or non-p RF24 module and then
    // reset our data rate back to default value. This works
    // because a non-P variant won't allow the data rate to
    // be set to 250Kbps.
    if( setDataRate( RF24_250KBPS ) )
    {
        p_variant = true ;
    }

    // Then set the data rate to the slowest (and most reliable) speed supported by all
    // hardware.
    setDataRate( RF24_1MBPS ) ;

    // Initialize CRC and request 2-byte (16bit) CRC
    setCRCLength( RF24_CRC_16 ) ;

    // Disable dynamic payloads, to match dynamic_payloads_enabled setting
    writeRegister(DYNPD,0);

    // Reset current status
    // Notice reset and flush is the last thing we do
    writeRegister(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

    // Set up default configuration.  Callers can always change it later.
    // This channel should be universally safe and not bleed over into adjacent
    // spectrum.
    setChannel(76);

    // Flush buffers
    flushRx();
    flushTx();

    return true;
}