Exemplo n.º 1
0
Arquivo: main.c Projeto: 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;
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: Drooids/nrf
int main(void)
{
  uint8_t tx_addr[4] = { 0xaa, 0xab, 0xac, 0xad };
  uint8_t rx_addr[4] = { 0xa1, 0xa2, 0xa3, 0xa4 };

  sys_setup();

  uart_setup();

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

  nrf905_setup();
  nrf905_set_tx_addr(tx_addr, 4);
  nrf905_set_rx_addr(rx_addr, 4);
  nrf905_set_payload_width(2);
  nrf905_commit_config();

#if 0
  {
    uint8_t i;
    dump_config();
    for (i = 0; i != sizeof(nrf905_config); ++i)
      nrf905_config[i] = 0x2a;
    nrf905_cmd_rc();
    dump_config();
  }
#endif

#if 0
  {
    uint8_t x;
    uart_write((uint8_t*)"rx 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

  led_setup();

  nrf905_set_rx();

  while (1)
  {
  wait_cd:
    if (nrf905_is_cd() == 0)
    {
      led_set(LED_RED);
      while (nrf905_is_cd() == 0) ;
      /* uart_write((uint8_t*)"cd\r\n", 4); */
    }

#if 0
    while (nrf905_is_am() == 0) ;
    uart_write((uint8_t*)"am\r\n", 4);
    led_mask = LED_GREEN;
#endif

    led_set(LED_GREEN);

  wait_dr:
    while (nrf905_is_dr() == 0)
    {
      if (nrf905_is_cd() == 0) goto wait_cd;
    }
    uart_write((uint8_t*)"dr\r\n", 4);

    reset_pattern();

    /* wait(); */
    nrf905_read_payload();

    if (check_pattern() == 0)
    {
      uart_write((uint8_t*)"ok\r\n", 4);
      led_set(LED_BLUE);
    }
    else led_set(LED_GREEN);

    goto wait_dr;
  }

  return 0;
}
Exemplo n.º 3
0
void ledmatrix_setup(void) {
	// Setup SPI - we divide the clock by 128.
	// (This speed guarantees the SPI buffer will never overflow.)
	spi_setup_master(128);
}
Exemplo n.º 4
0
Arquivo: main.c Projeto: 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;
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: 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;
}