Ejemplo n.º 1
0
/*---------------------------------------------------------------------------*/
void check_bootloader_message(uint8_t timeout)
{
    uint8_t getDataCounter = 0;

    /* listen to any bootloader messages! */
    nrf24_powerUpRx();    
    while(getDataCounter++ < timeout)
    {
        _delay_ms(1);        
        if(nrf24_dataReady())
        {    
            nrf24_getData(data_array);        
            if((data_array[0] == 0) && (data_array[1] == 0xAA))
            {        
                /* prepare */
                cli();
                PORTA = 0x00;
                PORTB = 0x00;
                DDRA = 0x00;
                DDRB = 0x00;
                sleep_disable();

                /* jump to bootloader! */
                /* bootloader is located at: 0x1800 */
                asm volatile("lds r31, 0x18"); // R31 = ZH
                asm volatile("lds r30, 0x00"); // R30 = ZL
                asm volatile("icall"); // Jump to the Z register value
            }            
        }                            
    }        
Ejemplo n.º 2
0
/* Send data using the nRF radio */
void radioTask(void *pvParameters)
{
	(void) pvParameters;
	uint8_t rfData[NRF24_PAYLOAD_LEN];
	uint8_t rcvData[NRF24_PAYLOAD_LEN];
	uint8_t pktCounter = 0;
	uint8_t blinkCounter = 0;
	const portTickType blinkDelay = 250 / portTICK_RATE_MS;
	const portTickType sendDelay = 5000 / portTICK_RATE_MS;

	rfData[0] = 0xB1;
	rfData[1] = 0x3A;
	rfData[2] = 0x23;
	while(1)
	{
		if(nrf24_dataReady())
		{
			nrf24_getData(rcvData);
			// Format message for debugging
			char debugRcvString[3*6] = {0};
			for (uint8_t i=0; i < NRF24_PAYLOAD_LEN; i++)
			{
				sprintf(debugRcvString+(3*i), "%02X ", rcvData[i]);
			}
			printf("Received: %s\n", debugRcvString);
		}


		rfData[3] = pktCounter++;
		nrf24_send(rfData);
		while(nrf24_isSending());
		char debugSendString[3*6] = {0};
		for (uint8_t i = 0; i < NRF24_PAYLOAD_LEN; i++)
		{
			sprintf(debugSendString+(3*i), "%02X ", rfData[i]);
		}
		printf("Sent: %s\n", debugSendString);

		if(nrf24_lastMessageStatus())
		{
			//there was a send problem
		}else{
			//transmission was ok
		}
		for(blinkCounter = 1 + nrf24_retransmissionCount(); blinkCounter > 0; --blinkCounter)
		{
			PORTC |= _BV(PORTC3);
			vTaskDelay(blinkDelay);
			PORTC &= ~_BV(PORTC3);
			vTaskDelay(blinkDelay);

		}

		nrf24_powerUpRx();
		vTaskDelay(sendDelay);

	}
}
Ejemplo n.º 3
0
/* configure the module */
void nrf24_config(uint8_t channel, uint8_t pay_length)
{
    /* Use static payload length ... */
    payload_len = pay_length;

    // Set RF channel
    nrf24_configRegister(RF_CH, channel);

    // Set length of incoming payload
    nrf24_configRegister(RX_PW_P0, 0x00); // Auto-ACK pipe ...
    nrf24_configRegister(RX_PW_P1, payload_len); // Data payload pipe
    nrf24_configRegister(RX_PW_P2, 0x00); // Pipe not used
    nrf24_configRegister(RX_PW_P3, 0x00); // Pipe not used
    nrf24_configRegister(RX_PW_P4, 0x00); // Pipe not used
    nrf24_configRegister(RX_PW_P5, 0x00); // Pipe not used

    // 1 Mbps, TX gain: 0dbm
    nrf24_configRegister(RF_SETUP, (0<<RF_DR)|((0x03)<<RF_PWR)); //0x6

    // CRC enable, 1 byte CRC length
    nrf24_configRegister(CONFIG,nrf24_CONFIG);

    // Auto Acknowledgment
    nrf24_configRegister(EN_AA,(1<<ENAA_P0)|(1<<ENAA_P1)|(0<<ENAA_P2)|(0<<ENAA_P3)|(0<<ENAA_P4)|(0<<ENAA_P5));

    // Enable RX addresses
    nrf24_configRegister(EN_RXADDR,(1<<ERX_P0)|(1<<ERX_P1)|(0<<ERX_P2)|(0<<ERX_P3)|(0<<ERX_P4)|(0<<ERX_P5));

    // Auto retransmit delay: 1000 us and Up to 15 retransmit trials
    nrf24_configRegister(SETUP_RETR,(0x04<<ARD)|(0x0F<<ARC));

    // Dynamic length configurations: No dynamic length
    nrf24_configRegister(DYNPD,(0<<DPL_P0)|(0<<DPL_P1)|(0<<DPL_P2)|(0<<DPL_P3)|(0<<DPL_P4)|(0<<DPL_P5));

    // Start listening
    nrf24_powerUpRx();

}
Ejemplo n.º 4
0
/* ------------------------------------------------------------------------- */
int main()
{
    /* init the software uart */
    uart_init();

    /* init the xprintf library */
    xdev_out(uart_put_char);

    /* simple greeting message */
    xprintf("\r\n> TX device ready\r\n");
    
    /* init hardware pins */
    nrf24_init();
    
    /* Channel #2 , payload length: 4 */
    nrf24_config(2,4);

    /* Set the device addresses */
    nrf24_tx_address(tx_address);
    nrf24_rx_address(rx_address);    

    while(1)
    {                
        /* Fill the data buffer */
        data_array[0] = 0x00;
        data_array[1] = 0xAA;
        data_array[2] = 0x55;
        data_array[3] = q++;                                    

        /* Automatically goes to TX mode */
        nrf24_send(data_array);        
        
        /* Wait for transmission to end */
        while(nrf24_isSending());

        /* Make analysis on last tranmission attempt */
        temp = nrf24_lastMessageStatus();

        if(temp == NRF24_TRANSMISSON_OK)
        {                    
            xprintf("> Tranmission went OK\r\n");
        }
        else if(temp == NRF24_MESSAGE_LOST)
        {                    
            xprintf("> Message is lost ...\r\n");    
        }
        
		/* Retranmission count indicates the tranmission quality */
		temp = nrf24_retransmissionCount();
		xprintf("> Retranmission count: %d\r\n",temp);

		/* Optionally, go back to RX mode ... */
		nrf24_powerUpRx();

		/* Or you might want to power down after TX */
		// nrf24_powerDown();            

		/* Wait a little ... */
		_delay_ms(10);
    }
}
Ejemplo n.º 5
0
int main(void)
{
  /* Initialise the GPIO block */
  gpioInit();

  /* Initialise the UART0 block for printf output */
  //uart0Init(115200);
  uart0Init(9600);
  /* Configure the multi-rate timer for 1ms ticks */
  mrtInit(__SYSTEM_CLOCK/1000);

  /* Configure the switch matrix (setup pins for UART0 and GPIO) */
  //configurePins();
  spiInit(LPC_SPI0, 6, 0);
  SwitchMatrix_Init(); //uart & spi
  LPC_GPIO_PORT->DIR0 |= (1 << CSN);
  LPC_GPIO_PORT->DIR0 |= (1 << CE);
  uint8_t temp = 0;

  nrf24_init();




  /* Set the LED pin to output (1 = output, 0 = input) */
  #if !defined(USE_SWD)
    LPC_GPIO_PORT->DIR0 |= (1 << LED_LOCATION);
  #endif

    //printf("write");
    mrtDelay(500);

    nrf24_config(2,16);

	#if TX_NODE
    	nrf24_tx_address(tx_address);
    	nrf24_rx_address(rx_address);
	#else
    	nrf24_tx_address(rx_address); //backwards looking but is fine
    	nrf24_rx_address(tx_address);
	#endif

    uint8_t i = 0;
  while(1)
  {

      /* Turn LED On by setting the GPIO pin high */
      LPC_GPIO_PORT->SET0 = 1 << LED_LOCATION;
      mrtDelay(500);

      /* Turn LED Off by setting the GPIO pin low */
      LPC_GPIO_PORT->CLR0 = 1 << LED_LOCATION;
      mrtDelay(500);

	  /*
      printf("Send\r\n");
      for(i=0; i<16; i++){
    	  printf("%d: %d\n\r", i, tx_data_array[i]);
      }
	   */
      nrf24_send(tx_data_array);
      while(nrf24_isSending());
      nrf24_powerUpRx();
      //done transmitting, set back to rx mode

      for(i=0; i<16; i++){
    	  tx_data_array[i]++;
      }

/*
      if(nrf24_dataReady()){
    	  printf("\n\rGot data\n\r");

          nrf24_getData(rx_data_array);
          for(i=0; i<16; i++){
          printf("%d: %d\n\r", i, rx_data_array[i]);
          }
      }
*/
  }
}