Esempio n. 1
0
app_states_t app_init(void)
{
	if(usb_get_state() == USB_REM_WU_ENABLE)   
  	{   
    	return APP_SUSP_WE;    
  	}   
       
  	if(usb_get_state() == USB_REM_WU_DISABLE)   
  	{   
    	return APP_SUSP_WD;    
  	}
   /*
   	I3FR = 1;             // rising edge SPI ready detect
  	INTEXP = 0x01; //Slave SPI Interrupt
	SPI = 1; // Enable SPI Interrupt
	 */
	hal_nrf_enable_ack_payload(1);
	hal_nrf_enable_dynamic_payload(1);
	hal_nrf_setup_dynamic_payload(1 << 0); // Set up PIPE 0 to handle dynamic lengths
	hal_nrf_set_operation_mode(HAL_NRF_PRX);  		// Configure radio as primary receiver (PTX) 
	//hal_nrf_set_rx_payload_width(HAL_NRF_PIPE0, 30);	// Set payload width to 30 bytes
	hal_nrf_set_power_mode(HAL_NRF_PWR_UP);	 		// Power up radio
	CE_HIGH();	   // Enable receiver
	
	return APP_NORMAL; 	
}
Esempio n. 2
0
// Configures RF parameters before Enhanced Shockburst can be used.
void configureRF()
{
  packet_received = false;
  send_success = false;

  // Enable the radio clock
  RFCKEN = 1;
  // Set payload width to 32 bytes
  hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, PAYLOAD_SIZE);
  // Set auto-retries to 5 with 500 us intervals
  hal_nrf_set_auto_retr(5, 500);
  // Set pipe address
  hal_nrf_set_address(HAL_NRF_PIPE0, default_pipe_address);
  hal_nrf_set_address(HAL_NRF_TX, default_pipe_address);
  // Set initial channel
  hal_nrf_set_rf_channel(default_channels[1]);
  // Configure radio as primary receiver (PTX)
  hal_nrf_set_operation_mode(HAL_NRF_PRX);
  // Wait for the xtal to power up
  while (hal_clk_get_16m_source() != HAL_CLK_XOSC16M) ;
  // Power up radio
  hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
  // Enable receiver
  CE_HIGH();

  return;
}
Esempio n. 3
0
/** Initialized the RF configurations and powre up the RF.
 * Use this function to initialize RF configurations.
 * Note that the pipe isn't opened in this function,
 * please use "rf_rcv_pipe_config" after using this
 * function to configure RX pipe.
 *
 * @param in_channel RF Frequency (in_channel + 2400MHz)
 * @param in_datarate Data rate of the RF transmission. (1Mbps or 2Mbps)
 * @param in_output_power RF output power configuration.
 * @param in_auto_retr Enable auto retransmission or not.
 * @param in_auto_retr_delay Auto retransmission delay.
 * @param in_addr_width Address width configuration for both PTX and PRX pipe.
 * @param in_crc_mode CRC enable or disable configuration.
 * @param in_spi_clk_rate SPI clock rate. (SPI speed)
 * @param in_rf_int RF interrupt enable bit.
 */
void epl_rf_en_init(unsigned char in_channel, epl_rf_en_datarate_t in_datarate, char in_output_power, unsigned char in_auto_retr, unsigned int in_auto_retr_delay, char in_addr_width, epl_rf_en_crc_mode_t in_crc_mode, unsigned char in_rf_int)
{

	RFCKEN = 1;	// RF clock enable.

	CE_LOW();

	//--- Default static setup. These setting is optimized to match the RF protocol with nRF24E1. ---//
	hal_nrf_close_pipe(HAL_NRF_ALL); // Close all pipes first. By default, pipe0 and pipe1 are opened.

	hal_nrf_set_datarate(in_datarate);
	hal_nrf_set_auto_retr(in_auto_retr, in_auto_retr_delay); // First parameter is set to zero indicating the auto retransmission is off.
	hal_nrf_set_output_power(in_output_power); // Maximum radio output power (0dbm).
	hal_nrf_set_crc_mode(in_crc_mode);

	hal_nrf_set_address_width(in_addr_width); // Both RX and TX's address width are Configured.

	hal_nrf_set_operation_mode(HAL_NRF_PTX); // Enter RF TX mode

	hal_nrf_set_rf_channel(in_channel);
	hal_nrf_set_power_mode(HAL_NRF_PWR_UP); // Power up radio

	hal_nrf_get_clear_irq_flags();

	// IEN1 RF interrupt enable bit
	RF = in_rf_int;
}
Esempio n. 4
0
void radio_sb_init( hal_nrf_operation_mode_t operational_mode )
{
    if( !bus_initialized  )
        radio_bus_init();
        
    switch( operational_mode )
    {
        case HAL_NRF_PRX:
            radio_mode = DEVICE_PRX_SB;
            break;
        case HAL_NRF_PTX:
            radio_mode = DEVICE_PTX_SB;
            break;
    }

    hal_nrf_close_pipe(HAL_NRF_ALL);               // First close all radio pipes
    // Pipe 0 and 1 open by default
    hal_nrf_open_pipe(HAL_NRF_PIPE0, false);       // Open pipe0, without/autoack

    hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT);       // Operates in 16bits CRC mode
    hal_nrf_set_auto_retr(0, RF_RETRANS_DELAY);    // Disables auto retransmit

    hal_nrf_set_address_width(HAL_NRF_AW_5BYTES);  // 5 bytes address width
    hal_nrf_set_address(HAL_NRF_TX, address);      // Set device's addresses
    hal_nrf_set_address(HAL_NRF_PIPE0, address);   // Sets recieving address on
    // pipe0

    if(operational_mode == HAL_NRF_PTX)            // Mode depentant settings
    {
        hal_nrf_set_operation_mode(HAL_NRF_PTX);     // Enter TX mode
    }
    else
    {
        hal_nrf_set_operation_mode(HAL_NRF_PRX);     // Enter RX mode
        hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH);
        // Pipe0 expect
        // PAYLOAD_LENGTH byte payload
        // PAYLOAD_LENGTH in radio.h
    }

    hal_nrf_set_rf_channel(RF_CHANNEL);            // Operating on static channel
    // Defined in radio.h.
    // Frequenzy =
    //        2400 + RF_CHANNEL
    hal_nrf_set_power_mode(HAL_NRF_PWR_UP);        // Power up device

    //hal_nrf_set_datarate(HAL_NRF_1MBPS);           // Uncomment this line for
    // compatibility with nRF2401
    // and nRF24E1

    radio_wait();

    radio_set_status (RF_IDLE);                    // Radio now ready
}
Esempio n. 5
0
void radio_esb_init( hal_nrf_operation_mode_t operational_mode )
{
    if( !bus_initialized  )
        radio_bus_init();
        
    switch( operational_mode )
    {
        case HAL_NRF_PRX:
            radio_mode = DEVICE_PRX_ESB;
            break;
        case HAL_NRF_PTX:
            radio_mode = DEVICE_PTX_ESB;
            break;
    }

    hal_nrf_close_pipe( HAL_NRF_ALL );               // First close all radio pipes
    // Pipe 0 and 1 open by default
    hal_nrf_open_pipe( HAL_NRF_PIPE0, true );        // Then open pipe0, w/autoack
    // Changed from sb/radio_sb.c

    hal_nrf_set_crc_mode( HAL_NRF_CRC_16BIT );       // Operates in 16bits CRC mode
    hal_nrf_set_auto_retr( RF_RETRANSMITS, RF_RETRANS_DELAY );
    // Enables auto retransmit.
    // 3 retrans with 250ms delay
    // Changed from sb/radio_sb.c

    hal_nrf_set_address_width( HAL_NRF_AW_5BYTES );  // 5 bytes address width
    hal_nrf_set_address( HAL_NRF_TX, address );      // Set device's addresses
    hal_nrf_set_address( HAL_NRF_PIPE0, address );   // Sets recieving address on
    // pipe0

    if( operational_mode == HAL_NRF_PTX )            // Mode depentant settings
    {
        hal_nrf_set_operation_mode( HAL_NRF_PTX );     // Enter TX mode
    }
    else
    {
        hal_nrf_set_operation_mode( HAL_NRF_PRX );     // Enter RX mode
        hal_nrf_set_rx_pload_width( (uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH );
        // Pipe0 expect
        // PAYLOAD_LENGTH byte payload
        // PAYLOAD_LENGTH in radio.h
    }

    hal_nrf_set_rf_channel( RF_CHANNEL );            // Operating on static channel
    // Defined in radio.h.
    // Frequenzy =
    //        2400 + RF_CHANNEL
    hal_nrf_set_power_mode( HAL_NRF_PWR_UP );        // Power up device

    radio_wait();

    radio_set_status( RF_IDLE );                     // Radio now ready
}
Esempio n. 6
0
void radio_sb_init (const uint8_t *address, hal_nrf_operation_mode_t operational_mode)
{
  hal_nrf_close_pipe(HAL_NRF_ALL);               // First close all radio pipes
                                                 // Pipe 0 and 1 open by default
  hal_nrf_open_pipe(HAL_NRF_PIPE0, FALSE);       // Open pipe0, without/autoack

  hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT);       // Operates in 16bits CRC mode
  hal_nrf_set_auto_retr(0, RF_RETRANS_DELAY);    // Disables auto retransmit

  hal_nrf_set_address_width(HAL_NRF_AW_5BYTES);  // 5 bytes address width
  hal_nrf_set_address(HAL_NRF_TX, address);      // Set device's addresses
  hal_nrf_set_address(HAL_NRF_PIPE0, address);   // Sets recieving address on 
                                                 // pipe0  
  
  if(operational_mode == HAL_NRF_PTX)            // Mode depentant settings
  {
    hal_nrf_set_operation_mode(HAL_NRF_PTX);     // Enter TX mode
  }
  else
  {
    hal_nrf_set_operation_mode(HAL_NRF_PRX);     // Enter RX mode
    hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH);
                                                 // Pipe0 expect 
                                                 // PAYLOAD_LENGTH byte payload
                                                 // PAYLOAD_LENGTH in radio.h
  }

  hal_nrf_set_rf_channel(RF_CHANNEL);            // Operating on static channel 
                                                 // Defined in radio.h. 
                                                 // Frequenzy = 
                                                 //        2400 + RF_CHANNEL
  hal_nrf_set_power_mode(HAL_NRF_PWR_UP);        // Power up device

  hal_nrf_set_datarate(HAL_NRF_250KBPS);         // Uncomment this line for 
                                                 // compatibility with nRF2401 
                                                 // and nRF24E1
  //hal_nrf_set_output_power(hal_nrf_output_power_t power); //default reset value is 0dbm

  // Wait for the radio to power up, max. 4.5ms depending on crystal Ls
  Timeout_SetTimeout2(5);
  while(!Timeout_IsTimeout2());

  radio_set_status (RF_IDLE);                    // Radio now ready
}                                                
Esempio n. 7
0
void main()
{

 	P0DIR =  ~((1<<4)|(1<<0));
  	// hal_spi_slave_init( HAL_SPI_MODE_0, HAL_SPI_LSB_MSB);
	 SPISCON0 = 0x40;
	  I3FR = 1;             // rising edge SPI ready detect
  P0_0 = 0;
  INTEXP = 0x01; //Slave SPI Interrupt

  //  ET0 = 1; // enable timer interrupt
  // EX0 = 1; 

	SPISDAT = 0xAA;
	SPISDAT = 0xAA;
  	SPI = 1; // Enable SPI Interrupt
	
  	SPISCON0 |= 0x01;

	    // Enable the radio clock
//  RFCKEN = 1;
  	// Enable RF interrupt
//	RF = 1; 

	// Enable global interrupt
  	EA = 1;
  	// Power up radio
  	hal_nrf_set_power_mode(HAL_NRF_PWR_UP);

	while(1)
	{
		while(radio_busy);
	    hal_nrf_write_tx_payload('a', 1);
			
	    // Toggle radio CE signal to start transmission 
	    CE_PULSE();				  
		
	    radio_busy = true;
	}
}
Esempio n. 8
0
void init_radio()
{
  // Enable the radio clock
  RFCKEN = 1;
  // Enable RF interrupt
  RF = 1;
    // Power up radio
  hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
	hal_nrf_set_output_power(HAL_NRF_0DBM);
  	hal_nrf_enable_ack_payload(1);
	hal_nrf_enable_dynamic_payload(1);
	hal_nrf_setup_dynamic_payload(1); // Set up PIPE 0 to handle dynamic lengths
	hal_nrf_set_rf_channel(125); // 2525 MHz
   	hal_nrf_set_auto_retr(5, 250); // Retry 5x
    // Configure radio as primary receiver (PTX) 
  hal_nrf_set_operation_mode(HAL_NRF_PTX);
 
      // Set payload width to 32 bytes
//  hal_nrf_set_rx_payload_width(HAL_NRF_PIPE0, MAXLENGTH);
   // Enable global interrupt
  EA = 1;
}
Esempio n. 9
0
void main()
{
#ifdef MCU_NRF24LE1
  while(hal_clk_get_16m_source() != HAL_CLK_XOSC16M)
  {
    // Wait until 16 MHz crystal oscillator is running
  }
#endif
  
  #ifdef MCU_NRF24LU1P
  // Enable radio SPI
  RFCTL = 0x10;
  #endif

  // Set P0 as output
  P0DIR = 0;

  // Enable the radio clock
  RFCKEN = 1;

  // Enable RF interrupt
  RF = 1;
  // Enable global interrupt
  EA = 1;

  // Configure radio as primary receiver (PTX)
  hal_nrf_set_operation_mode(HAL_NRF_PRX);

  // Set payload width to 3 bytes
  hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, 3);

  // Power up radio
  hal_nrf_set_power_mode(HAL_NRF_PWR_UP);

  // Enable receiver
  CE_HIGH();

  for(;;){}
}
Esempio n. 10
0
// Resets RF parameters to default values.
// Must be called before jumping to new firmware.
void resetRF()
{
  // Reset values set by the RF setup.
  CE_LOW();
  // PWR_UP = 0
  hal_nrf_set_power_mode(HAL_NRF_PWR_DOWN);
  // PRIM_RX = 0
  hal_nrf_set_operation_mode(HAL_NRF_PTX);
  // RF_CH = 0x02;
  hal_nrf_set_rf_channel(reset_channel);
  // AW = 11 (Default = 5 bytes)
  // RX_ADDR_P0 = TX_ADDR = 0xE7E7E7E7E7
  hal_nrf_set_address(HAL_NRF_TX, reset_pipe_address);
  hal_nrf_set_address(HAL_NRF_PIPE0, reset_pipe_address);
  // ARD = 0000, ARC = 0011
  hal_nrf_set_auto_retr(3, 250);
  // RX_PW_P0 = 0x00
  hal_nrf_set_rx_payload_width((int)HAL_NRF_PIPE0, 0);
  // Disable radio clock
  RFCKEN = 0;

  return;
}
Esempio n. 11
0
app_states_t app_susp_we(void)   
{   
//  wdp_host_rx_setup(WDP_RX_SUSPEND);          // Set up WDP low power receive mode   
	
	usb_wakeup();
	return APP_NORMAL;
	CE_LOW();
	hal_nrf_set_power_mode(HAL_NRF_PWR_DOWN);	 		// Power up radio
	
  	RFCKEN = 0;  	// disable the radio clock    
  //  usb_wakeup();   
 //   return APP_NORMAL;    
      
  // Minimize the powerconsumption by powering down the MCU    
  cklf_gpio_wakeup(0x0000, 0x0000);           // GPIO wakeup off   
  cklf_rtc_disable();   
  cklf_rtc_init(0x00, 0x1FFF);                // Setup power down timeout to app. 1 s   
  cpu_pwr_down();                             // MCU goto sleep   
          
  WUF = 0;                                    // Clear WU flag   
   
  return APP_SUSP_WE;      
} 
Esempio n. 12
0
void radio_pl_init (const uint8_t *address, hal_nrf_operation_mode_t operational_mode)
{
  hal_nrf_close_pipe(HAL_NRF_ALL);               // First close all radio pipes
                                                 // Pipe 0 and 1 open by default
  hal_nrf_open_pipe(HAL_NRF_PIPE0, true);        // Then open pipe0, w/autoack 

  hal_nrf_set_crc_mode(HAL_NRF_CRC_16BIT);       // Operates in 16bits CRC mode
  hal_nrf_set_auto_retr(RF_RETRANSMITS, RF_RETRANS_DELAY);
                                                 // Enables auto retransmit.
                                                 // 3 retrans with 250ms delay

  hal_nrf_set_address_width(HAL_NRF_AW_5BYTES);  // 5 bytes address width
  hal_nrf_set_address(HAL_NRF_TX, address);      // Set device's addresses
  hal_nrf_set_address(HAL_NRF_PIPE0, address);   // Sets recieving address on 
                                                 // pipe0

/*****************************************************************************
 * Changed from esb/radio_esb.c                                              *
 * Enables:                                                                  *
 *  - ACK payload                                                            *
 *  - Dynamic payload width                                                  *
 *  - Dynamic ACK                                                            *
 *****************************************************************************/
  hal_nrf_enable_ack_pl();                       // Try to enable ack payload

  // When the features are locked, the FEATURE and DYNPD are read out 0x00
  // even after we have tried to enable ack payload. This mean that we need to
  // activate the features.
  if(hal_nrf_read_reg(FEATURE) == 0x00 && (hal_nrf_read_reg(DYNPD) == 0x00))
  {
    hal_nrf_lock_unlock ();                      // Activate features
    hal_nrf_enable_ack_pl();                     // Enables payload in ack
  }

  hal_nrf_enable_dynamic_pl();                   // Enables dynamic payload
  hal_nrf_setup_dyn_pl(ALL_PIPES);               // Sets up dynamic payload on
                                                 // all data pipes.
/*****************************************************************************
 * End changes from esb/radio_esb.c                                          *
 *****************************************************************************/
   
  if(operational_mode == HAL_NRF_PTX)            // Mode depentant settings
  {
    hal_nrf_set_operation_mode(HAL_NRF_PTX);     // Enter TX mode
  }
  else
  {
    hal_nrf_set_operation_mode(HAL_NRF_PRX);     // Enter RX mode
    hal_nrf_set_rx_pload_width((uint8_t)HAL_NRF_PIPE0, RF_PAYLOAD_LENGTH);
                                                 // Pipe0 expect 
                                                 // PAYLOAD_LENGTH byte payload
                                                 // PAYLOAD_LENGTH in radio.h
  }

  hal_nrf_set_rf_channel(RF_CHANNEL);            // Operating on static channel
                                                 // Defined in radio.h. 
                                                 // Frequenzy = 
                                                 //        2400 + RF_CHANNEL
  hal_nrf_set_power_mode(HAL_NRF_PWR_UP);        // Power up device
  
  start_timer(RF_POWER_UP_DELAY);                // Wait for the radio to 
  wait_for_timer();                              // power up
  
  radio_set_status (RF_IDLE);                    // Radio now ready
}    
Esempio n. 13
0
int main(void)
{
    int ch;
    bool_t eol=FALSE, spi_ini=FALSE, gpio_ini=FALSE;

    spi_hndl_t spi_h;
    gpio_hndl_t gpio_h;

    if (gpio_init(&gpio_h, gpio_drv_io)!=LREC_SUCCESS) goto finish;
    else gpio_ini=TRUE;

    gpio_direction_output(&gpio_h, GPIO_CE, 0);

    if (spi_init(&spi_h, 0, SPI_CS, SPI_MODE_0, FALSE, 8,
        SPI_USE_DEF, SPI_USE_DEF, SPI_USE_DEF)!=LREC_SUCCESS) goto finish;
    else spi_ini=TRUE;

    signal(SIGINT, term_handler);
    signal(SIGTERM, term_handler);

    errno = 0;
    hal_nrf_set_spi_hndl(&spi_h);

    hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
    usleep(1500);

    NRF_EXEC(hal_nrf_set_operation_mode(HAL_NRF_PRX));

    for (ch=0; ch<128 && !scan_finish; ch++)
    {
        int i;

        if (eol) printf("\n");

        NRF_EXEC(hal_nrf_set_rf_channel(ch));
        assert(hal_nrf_get_rf_channel()==ch);

        chip_enable();

        for (i=0; i<500; i++) {
            if (hal_nrf_get_carrier_detect()) break;
            usleep(1000);
        }

        if (i<500) {
            if (!eol) printf("\n");
            printf("Carrier detected on channel %d", ch);
            eol=TRUE;
        } else {
            printf(".");
            fflush(stdout);
            eol = (!((ch+1)%10) ? TRUE : FALSE);
        }

        chip_disable();
    }
    if (!eol) printf("\n");

finish:
    if (errno==ECOMM) printf("SPI communication error\n");
    if (spi_ini) spi_free(&spi_h);
    if (gpio_ini) gpio_free(&gpio_h);

    return 0;
}