Esempio n. 1
0
int main(void) {
	//
	// Enable lazy stacking for interrupt handlers.  This allows floating-point
	// instructions to be used within interrupt handlers, but at the expense of
	// extra stack usage.
	//
	FPULazyStackingEnable();
	FPUEnable();

	//
	// Set the clocking to run directly from the crystal.
	// Clock to 80MHZ
	//
	SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
					   SYSCTL_OSC_MAIN);

	IntMasterEnable();

	//set up the radio
	if( !nrf24l01p_setup(&nrf, GPIO_PORTC_BASE, GPIO_PIN_4, SSI0_BASE) ){
		//we couldn't communicate with the radio
		return 1;
	}

	nrf24l01p_set_PA_level(&nrf, RF24_PA_LOW);

	nrf24l01p_open_writing_pipe(&nrf, addresses[0]);
	nrf24l01p_open_reading_pipe(&nrf, 1,addresses[1]);

	nrf24l01p_start_listening(&nrf);

	while(1){
		if (nrf24l01p_available(&nrf)) {
			uint32_t got_time;

			// Variable for the received timestamp
			while (nrf24l01p_available(&nrf)) {                 // While there is data ready
				nrf24l01p_read(&nrf, &got_time, sizeof(uint32_t));     // Get the payload
			}

			nrf24l01p_stop_listening(&nrf);        // First, stop listening so we can talk
			nrf24l01p_write(&nrf, &got_time, sizeof(uint32_t)); // Send the final one back.
			nrf24l01p_start_listening(&nrf); // Now, resume listening so we catch the next packets.

		}

		//give it a little space
		SysCtlDelay((SysCtlClockGet() >> 12) * 5);
	}

	return 0;
}
Esempio n. 2
0
File: main.c Progetto: Drooids/nrf
int main(void)
{
  uint8_t buf[NRF24L01P_PAYLOAD_WIDTH];
  uint32_t counter = 0;
#if 0
  uint8_t x;
#endif

  /* setup spi first */
  spi_setup_master();
  spi_set_sck_freq(SPI_SCK_FREQ_FOSC2);

  uart_setup();

  nrf24l01p_setup();

  /* sparkfun usb serial board configuration */
  /* NOTE: nrf24l01p_enable_crc8(); for nrf24l01p board */
  /* nrf24l01p_enable_crc16(); */
  nrf24l01p_disable_crc();
  /* auto ack disabled */
  /* auto retransmit disabled */
  /* 4 bytes payload */
  /* 1mbps, 0dbm */
  /* nrf24l01p_set_rate(NRF24L01P_RATE_1MBPS); */
  nrf24l01p_set_rate(NRF24L01P_RATE_2MBPS);
  /* nrf24l01p_set_rate(NRF24L01P_RATE_250KBPS); */
  /* channel 2 */
  nrf24l01p_set_chan(2);
  /* 5 bytes addr width */
  /* nrf24l01p_set_addr_width(NRF24L01P_ADDR_WIDTH_5); */
  nrf24l01p_set_addr_width(NRF24L01P_ADDR_WIDTH_3);
  /* rx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_RX_ADDR_P0);
  /* tx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_TX_ADDR);
  /* enable tx no ack command */
  nrf24l01p_enable_tx_noack();

  nrf24l01p_powerdown_to_standby();
  nrf24l01p_standby_to_tx();
  if (nrf24l01p_is_tx_empty() == 0) nrf24l01p_flush_tx();

#if 0
  uart_write((uint8_t*)"tx side\r\n", 9);
  uart_write((uint8_t*)"press space\r\n", 13);
  uart_read_uint8(&x);
  uart_write((uint8_t*)"starting\r\n", 10);
#endif

  /* enable interrupts */
  sei();

  while (1)
  {
    if ((++counter) != (200000UL / 8UL)) continue ;
    counter = 0;

    make_pattern(buf);
    nrf24l01p_write_tx_noack_zero(buf);
    nrf24l01p_complete_tx_noack_zero();
    while (nrf24l01p_is_tx_irq() == 0) ;
  }

  return 0;
}
Esempio n. 3
0
File: main.c Progetto: Drooids/nrf
int main(void)
{
  uint16_t counter;
  uint8_t x;

#define CONFIG_CHECK 0
#if CONFIG_CHECK
  uint16_t error;
#endif

  /* setup spi first */
  spi_setup_master();
  spi_set_sck_freq(SPI_SCK_FREQ_FOSC2);

  uart_setup();

  /* setup timer1, normal mode, interrupt on match 0xffff */
  OCR1A = 0xffff;
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1C = 0;
  TIMSK1 = 1 << 1;

  /* enable interrupts */
  sei();

  nrf24l01p_setup();

  /* sparkfun usb serial board configuration */
  /* NOTE: nrf24l01p_enable_crc8(); for nrf24l01p board */
  /* nrf24l01p_enable_crc16(); */
  nrf24l01p_disable_crc();
  /* auto ack disabled */
  /* auto retransmit disabled */
  /* 4 bytes payload */
  /* 1mbps, 0dbm */
  /* nrf24l01p_set_rate(NRF24L01P_RATE_1MBPS); */
  nrf24l01p_set_rate(NRF24L01P_RATE_2MBPS);
  /* nrf24l01p_set_rate(NRF24L01P_RATE_250KBPS); */
  /* channel 2 */
  nrf24l01p_set_chan(2);
  /* 5 bytes addr width */
  /* nrf24l01p_set_addr_width(NRF24L01P_ADDR_WIDTH_5); */
  nrf24l01p_set_addr_width(NRF24L01P_ADDR_WIDTH_3);
  /* rx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_RX_ADDR_P0);
  /* tx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_TX_ADDR);
  /* enable tx no ack command */
  nrf24l01p_enable_tx_noack();

  nrf24l01p_powerdown_to_standby();

  uart_write((uint8_t*)"rx side\r\n", 9);

 redo_receive:

#if CONFIG_CHECK
  error = 0;
#endif
  counter = 0;
  is_timer1_irq = 0;

  uart_write((uint8_t*)"press space\r\n", 13);
  uart_read_uint8(&x);
  uart_write((uint8_t*)"starting\r\n", 10);

  nrf24l01p_standby_to_rx();

  /* wait for the starting packet */
  if (nrf24l01p_is_rx_full()) nrf24l01p_flush_rx();
  while (nrf24l01p_is_rx_irq() == 0) ;
  nrf24l01p_read_rx();

  /* clock source disabled, safe to access 16 bits counter */
  TCNT1 = 0;

  /* prescaler set to 256 */
  /* interrupt every 16000000 / (65535 * 256) = 0.954 s */
  TCCR1B = 1 << 2;

  while (1)
  {
    if (is_timer1_irq == 1)
    {
      break ;
    }
    else if (nrf24l01p_is_rx_irq())
    {
#if CONFIG_CHECK
      uint8_t i;
      for (i = 0; i < NRF24L01P_PAYLOAD_WIDTH; ++i)
	nrf24l01p_cmd_buf[i] = 0x00;
#endif

      nrf24l01p_read_rx();

#if CONFIG_CHECK
      for (i = 0; i < NRF24L01P_PAYLOAD_WIDTH; ++i)
      {
	if (nrf24l01p_cmd_buf[i] != (0x2a + i))
	{
	  ++error;
	  break ;
	}
      }
#endif

      ++counter;
    }
  }

  /* print counter */
  uart_write((uint8_t*)"counter: ", 9);
  uart_write((uint8_t*)uint16_to_string(counter), 4);
  uart_write((uint8_t*)"\r\n", 2);

#if CONFIG_CHECK
  /* print error */
  uart_write((uint8_t*)"error: ", 7);
  uart_write((uint8_t*)uint16_to_string(error), 4);
  uart_write((uint8_t*)"\r\n", 2);
#endif

  /* still in rx mode */
  nrf24l01p_set_standby();

  goto redo_receive;

  return 0;
}
Esempio n. 4
0
File: main.c Progetto: Drooids/nrf
int main(void)
{
  uint16_t counter;
  uint8_t x;

  /* setup spi first */
  spi_setup_master();
  spi_set_sck_freq(SPI_SCK_FREQ_FOSC2);

  uart_setup();

  /* setup timer1, normal mode, interrupt on match 0x8000 */
  OCR1A = 0x8000;
  TCCR1A = 0;
  TCCR1B = 0;
  TCCR1C = 0;
  TIMSK1 = 1 << 1;

  /* enable interrupts */
  sei();

  nrf24l01p_setup();

  /* sparkfun usb serial board configuration */
  /* NOTE: nrf24l01p_enable_crc8(); for nrf24l01p board */
  /* nrf24l01p_enable_crc16(); */
  nrf24l01p_disable_crc();
  /* auto ack disabled */
  /* auto retransmit disabled */
  /* 4 bytes payload */
  /* 1mbps, 0dbm */
  /* nrf24l01p_set_rate(NRF24L01P_RATE_1MBPS); */
  nrf24l01p_set_rate(NRF24L01P_RATE_2MBPS);
  /* nrf24l01p_set_rate(NRF24L01P_RATE_250KBPS); */
  /* channel 2 */
  nrf24l01p_set_chan(2);
  /* 5 bytes addr width */
  /* nrf24l01p_set_addr_width(NRF24L01P_ADDR_WIDTH_5); */
  nrf24l01p_set_addr_width(NRF24L01P_ADDR_WIDTH_3);
  /* rx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_RX_ADDR_P0);
  /* tx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_TX_ADDR);
  /* enable tx no ack command */
  nrf24l01p_enable_tx_noack();

  nrf24l01p_powerdown_to_standby();

  uart_write((uint8_t*)"tx side\r\n", 9);

 redo_transmit:

  counter = 0;
  is_timer1_irq = 0;

  uart_write((uint8_t*)"press space\r\n", 13);
  uart_read_uint8(&x);
  uart_write((uint8_t*)"starting\r\n", 10);

  nrf24l01p_standby_to_tx();

  if (nrf24l01p_is_tx_empty() == 0) nrf24l01p_flush_tx();

  /* clock source disabled, safe to access 16 bits counter */
  TCNT1 = 0;

  /* prescaler set to 1024 */
  /* interrupt every 2.01s (match on 0x8000) */
  TCCR1B = 5 << 0;

  while (1)
  {
#define CONFIG_CHECK 0
#if CONFIG_CHECK
    uint8_t i;
    for (i = 0; i < NRF24L01P_PAYLOAD_WIDTH; ++i)
      nrf24l01p_cmd_buf[i] = 0x2a + i;
#endif

    nrf24l01p_write_tx_noack();
    while (nrf24l01p_is_tx_irq() == 0) ;
    ++counter;
    if (is_timer1_irq == 1) break ;
  }

  /* print counter */
  uart_write((uint8_t*)"counter: ", 9);
  uart_write((uint8_t*)uint16_to_string(counter), 4);
  uart_write((uint8_t*)"\r\n", 2);

  goto redo_transmit;

  return 0;
}
Esempio n. 5
0
File: main.c Progetto: Drooids/nrf
int main(void)
{
  uart_setup();

  nrf24l01p_setup();

  /* sparkfun usb serial board configuration */
  /* NOTE: nrf24l01p_enable_crc8(); for nrf24l01p board */
  nrf24l01p_enable_crc16();
  /* auto ack disabled */
  /* auto retransmit disabled */
  /* 4 bytes payload */
  /* 1mbps, 0dbm */
  nrf24l01p_set_rate(NRF24L01P_RATE_1MBPS);
  /* channel 2 */
  nrf24l01p_set_chan(2);
  /* 5 bytes addr width */
  nrf24l01p_set_addr_width(NRF24L01P_ADDR_WIDTH_5);
  /* rx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_RX_ADDR_P0);
  /* tx address */
  nrf24l01p_cmd_buf[0] = 0xe7;
  nrf24l01p_cmd_buf[1] = 0xe7;
  nrf24l01p_cmd_buf[2] = 0xe7;
  nrf24l01p_cmd_buf[3] = 0xe7;
  nrf24l01p_cmd_buf[4] = 0xe7;
  nrf24l01p_write_reg40(NRF24L01P_REG_TX_ADDR);
  /* enable tx no ack command */
  nrf24l01p_enable_tx_noack();

  nrf24l01p_powerdown_to_standby();

  uart_write((uint8_t*)"starting\r\n", 10);

#if 1
  nrf24l01p_standby_to_tx();

  if (nrf24l01p_is_tx_empty() == 0) nrf24l01p_flush_tx();
  nrf24l01p_cmd_buf[0] = '0';
  nrf24l01p_cmd_buf[1] = '1';
  nrf24l01p_cmd_buf[2] = '2';
  nrf24l01p_cmd_buf[3] = '3';
  nrf24l01p_write_tx_noack();
  while (nrf24l01p_is_tx_irq() == 0) ;

  uart_write((uint8_t*)"first\r\n", 7);

  if (nrf24l01p_is_tx_empty() == 0) nrf24l01p_flush_tx();
  nrf24l01p_cmd_buf[0] = 'a';
  nrf24l01p_cmd_buf[1] = 'b';
  nrf24l01p_cmd_buf[2] = 'c';
  nrf24l01p_cmd_buf[3] = 'd';
  nrf24l01p_write_tx_noack();
  while (nrf24l01p_is_tx_irq() == 0) ;

  uart_write((uint8_t*)"second\r\n", 8);

  /* still in standby mode */
#endif

 redo_receive:

  nrf24l01p_standby_to_rx();

  if (nrf24l01p_is_rx_full()) nrf24l01p_flush_rx();

  while (nrf24l01p_is_rx_irq() == 0) ;

  nrf24l01p_read_rx();

  if (nrf24l01p_cmd_len == 0)
  {
    uart_write((uint8_t*)"ko", 2);
  }
  else
  {
    uint8_t saved_buf[4];
    uint8_t i;

    uart_write((uint8_t*)nrf24l01p_cmd_buf, nrf24l01p_cmd_len);

    /* save before new commands */
    for (i = 0; i < nrf24l01p_cmd_len; ++i)
      saved_buf[i] = nrf24l01p_cmd_buf[i];

    /* result in setting standby mode */
    nrf24l01p_rx_to_tx();

    if (nrf24l01p_is_tx_empty() == 0)
    {
      uart_write((uint8_t*)"\r\nNE", 4);
      nrf24l01p_flush_tx();
    }

    /* restore saved buf */
    nrf24l01p_cmd_len = i;
    for (i = 0; i < nrf24l01p_cmd_len; ++i)
      nrf24l01p_cmd_buf[i] = saved_buf[i];

    /* push into the tx fifo, then pulse ce to send */
    nrf24l01p_write_tx_noack();
    while (nrf24l01p_is_tx_irq() == 0) ;
  }
  uart_write((uint8_t*)"\r\n", 2);

  goto redo_receive;

  return 0;
}