コード例 #1
0
ファイル: main.c プロジェクト: lordhippo/ImmortalsSender
void demo()
{
	uint8_t cc[TX_PAYLOAD_SIZE+1] = {0};
	unsigned char address[5]={110,110,8,110,110};
	
	cc[0] = 25;
	cc[1] = 1;
	
				 address[2] = cc[0];
				 nrf24l01_set_tx_addr(address , 5);
				 
				 nrf24l01_write_tx_payload(cc + 1 , TX_PAYLOAD_SIZE , true);
				 while(!nrf24l01_irq_pin_active());
				 nrf24l01_irq_clear_all();
				 
				 nrf24l01_write_tx_payload(cc + 1 , 10 , true);
				 while(!nrf24l01_irq_pin_active());
				 nrf24l01_irq_clear_all();
				 
				  if(checkFirstoo<2)
						checkFirstoo++;
					
		
	
}
コード例 #2
0
//main routine
int main(void) 
{ 
   unsigned char data; //register to hold letter received and sent 
    
   Initialize(); //initialize PLL, IO, SPI, set up nRF24L01 as RX 

   //main program loop 
   while(1) 
   { 
		//wait until a packet has been received 
		while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active())); 
       
		nrf24l01_read_rx_payload(&data, 1); //read the packet into data 
		nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01 
		PORTC = data;
//		DelayUS(130); //wait for the other 24L01 to come from standby to RX 

		_delay_us(35);
		_delay_us(35);
		_delay_us(35);
		_delay_us(25);

		nrf24l01_set_as_tx(); //change the device to a TX to send back from the other 24L01 
		nrf24l01_write_tx_payload(&data, 1, true); //transmit received char over RF 
       
		//wait until the packet has been sent

		while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_tx_ds_active())); 

		nrf24l01_irq_clear_all(); //clear interrupts again 
		nrf24l01_set_as_rx(true); //resume normal operation as an RX 

//      ToggleLED(); //toggle the on-board LED as visual indication that the loop has completed 
	}
} 
コード例 #3
0
ファイル: radio_rx.c プロジェクト: qqkstar/ECE4760-Lazer-Duel
void MainLoop()
{
    width = 1;
    char data[width]; //register to hold letter sent and received
    int i = 0;

    while (1)
    {
        PORTD;
        while (!(nrf24l01_irq_pin_active()));
        while (!nrf24l01_irq_rx_dr_active());

        LED2 = ~LED2;
        nrf24l01_read_rx_payload(data, width); //get the payload into data
        nrf24l01_irq_clear_all(); //clear interrupts again

        for (i = 0; i < width; i++)
        {
            sprintf(RS232_Out_Buffer, "%c", data[i]);
            putsUART1(RS232_Out_Buffer);
        }
        putsUART1("\r\n");

        Delayus(130); //wait for receiver to come from standby to RX

        LED3 = ~LED3;

    }
}
コード例 #4
0
ファイル: Transceiver.c プロジェクト: yguo89/CodeBrain
/******** Transceiver_Receive **********************************************
// Hardware trigger on IRQ occurred, change the state for transceiver state
//   machine in order to read message into microcontroller
// Input: none 
// Output: none
// ------------------------------------------------------------------------*/
void Transceiver_Receive ( void )
{
	portBASE_TYPE xHigherPriorityTaskWoken;
	unsigned char rx[TRANSCEIVER_MAX_PAYLOAD];

	if ( !( nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active() ) )
	{
		// ERROR: we got interupt but the interupt is not packet received 
		Debug_Printf ( "Transceiver_Receive: Error 0x%x\n", nrf24l01_get_status()&nrf24l01_STATUS_INTERRUPT );
		goto exit; 
	}

	//get the payload into data
	nrf24l01_read_rx_payload ( rx, TRANSCEIVER_MAX_PAYLOAD );
	Debug_NetworkTransceiver_PrintPayload(rx);

	if ( pdTRUE != xQueueSendFromISR(Transceiver_RX_Queue, rx, &xHigherPriorityTaskWoken) )
	{
		// ERROR: Queue is full
		Debug_Printf ("Transceiver_Receive: Error 0x%x\n", ERROR_QUEUE_FULL);
		if ( FullQueueCallBack != NULL )
			xTaskCreate( Transceiver_FullQueueCallBack, ( signed portCHAR * ) "Transceiver_FullQueueCallBack", 
				 DEFAULT_STACK_SIZE, NULL, DEFAULT_PRIORITY, NULL );
		goto exit;
	}

exit:	
	nrf24l01_irq_clear_all();
	Delay_US(130); 
}
コード例 #5
0
ファイル: Transceiver.c プロジェクト: yguo89/CodeBrain
/******** Transceiver_SendMessage *******************************************
// unpack transceiver packet and send out
// Input:
//    pkt - transceiver packet to be sent 
// Output: status
// ------------------------------------------------------------------------*/
unsigned char Transceiver_SendMessage ( TransceiverPacket pkt )
{
	unsigned char tx[TRANSCEIVER_MAX_PAYLOAD];
	unsigned char index, length;
	unsigned char status = SUCCESS;

	// validate packet
	Debug_NetworkTransceiver_PrintPacket(&pkt);

	if ( MAX_DATA_SIZE < pkt.dataSize )
	{
		status = ERROR_INVALID_PAKCET;
		Debug_Printf ("Transceiver_SendMessage: Error 0x%x\n", status);
		goto exit;
	}

	// unpack transceiver packet
	tx[SOURCE_ID_INDEX] = pkt.srcID;
	tx[DEST_ID_INDEX] = pkt.destID;
	tx[MSG_ID_INDEX] = pkt.msgID;
	tx[DATA_SIZE_INDEX] = pkt.dataSize;
	length = DATA_INDEX;
	for ( index = 0; index < pkt.dataSize; index++,length++ )
	{
		tx[length] = pkt.data[index];
	}

	Debug_NetworkTransceiver_PrintPayload(tx);

	// lock transceiver
	while ( xSemaphoreTake(Transceiver_Mutex, portMAX_DELAY) != pdTRUE );
	GPIOPinIntDisable ( nrf24l01_IRQ_IOREGISTER, nrf24l01_IRQ_PIN );

	nrf24l01_set_as_tx();
	nrf24l01_write_tx_payload ( tx, TRANSCEIVER_MAX_PAYLOAD, true );

	//wait until the packet has been sent or the maximum number of retries has been active
	while( !( nrf24l01_irq_pin_active() && (nrf24l01_irq_tx_ds_active()||nrf24l01_irq_max_rt_active()) ) );
	if ( nrf24l01_irq_max_rt_active() )	
	{
		// hit maximum number of retries
		nrf24l01_flush_tx();
		status = ERROR_MAX_RETRIES;
		Debug_Printf ("Transceiver_SendMessage: Error 0x%x\n", status);
	}

	// reset transceiver
	nrf24l01_irq_clear_all();
	nrf24l01_set_as_rx(true);
	Delay_US(130);

	//unlock transceiver
	GPIOPinIntEnable ( nrf24l01_IRQ_IOREGISTER, nrf24l01_IRQ_PIN );
	while ( xSemaphoreGive(Transceiver_Mutex) != pdTRUE );

exit:
	return status;
}
コード例 #6
0
//flush both fifos and clear interrupts
void nrf24l01_clear_flush()
{
	nrf24l01_flush_rx();
	nrf24l01_flush_tx();
	nrf24l01_irq_clear_all();
}
コード例 #7
0
//main routine
int	main() 
{	
	unsigned char data; //register to hold letter sent and received
	unsigned int count; //counter for for loop
	
	Initialize(); //initialize PLL, IO, UART, SPI, set up nRF24L01 as TX

	stdout = &my_stream;
	stdin = &my_stream;

	printf_P(PSTR(" type character to send \n"));

	//main program loop
	while(1)
	{	
		//check UART status register to see if data has been received.  if so, process
		while(usart0_rx_data_ready())
		{
//			data = usart0_get_rx_data(); //get data from UART
			data = getchar(); //get data from UART

			PORTC = data;

			nrf24l01_write_tx_payload(&data, 1, true); //transmit received char over RF

			//wait until the packet has been sent or the maximum number of retries has been active
			while(!(nrf24l01_irq_pin_active() && (nrf24l01_irq_tx_ds_active() || nrf24l01_irq_max_rt_active())));

			//check to see if the maximum number of retries has been hit.  if not, wait for the RX device
			// to send the char back.  if so, assume the packet is lost and send "*" back to UART
			if(!nrf24l01_irq_max_rt_active())
			{
				nrf24l01_irq_clear_all(); //clear all interrupts in the 24L01
				nrf24l01_set_as_rx(true); //change the device to an RX to get the character back from the other 24L01

				//wait a while to see if we get the data back (change the loop maximum and the lower if
				//  argument (should be loop maximum - 1) to lengthen or shorten this time frame
				for(count = 0; count < 25000; count++)
				{
					//check to see if the data has been received.  if so, get the data and exit the loop.
					//  if the loop is at its last count, assume the packet has been lost and set the data
					//  to go to the UART to "?".  If neither of these is true, keep looping.
					if((nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()))
					{
						nrf24l01_read_rx_payload(&data, 1); //get the payload into data
						break;
					}
					
					//if loop is on its last iteration, assume packet has been lost.
					if(count == 24999)
						data = '?';
				}
				
				nrf24l01_irq_clear_all(); //clear interrupts again
				printf("%c", data); //print the received data (or ? if none) to the screen
			
//				DelayUS(130); //wait for receiver to come from standby to RX
				_delay_us(35);
				_delay_us(35);
				_delay_us(35);
				_delay_us(25);

				nrf24l01_set_as_tx(); //resume normal operation as a TX
			}
			else
			{
				nrf24l01_flush_tx(); //get the unsent character out of the TX FIFO
				nrf24l01_irq_clear_all(); //clear all interrupts
				printf("*"); //print "*" to the screen to show that the receiver did not receive the packet
			}
									
//			ToggleLED(); //toggle the on-board LED as visual indication that the loop has completed
		}
	}
}
コード例 #8
0
ファイル: main.c プロジェクト: fwgrange/BotanicalBuddy
int main (void)
{
  setvbuf(stdin, NULL, _IONBF, 0);
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stderr, NULL, _IONBF, 0);

  //Driver initialization
  ds_systick_init();
  ds_delay_init();
  ds_uart_init();
  ds_rtc_init();
  ds_i2c1_init();
  ds_nordic_init();
  ds_therm_init();

  if (SysTick_Config(SystemCoreClock / 1000))
    while (1);

  //Initialize the nordic library
  nrf24l01_initialize_debug(false, 32, true);

  //Clear queues and interrupts
  //Need to fill txdata[] with our data
  nrf24l01_clear_flush();
  char rxdata[32];
  char txdata[32];
  // txdata[0] = 'h';
  // txdata[1] = ' ';
  // txdata[2] = 't';
  // txdata[3] = 'i';
  // txdata[4] = 'm';

  float temp = 0;

  int i;
  // for (i = 5; i < 30; i++) {
  //   txdata[i] = '!';
  // }

  // txdata[30] = '\n';
  // txdata[31] = '\0';
  
  
  while (1) {
    for (i = 0; i < 5000; i++) {
      ds_delay_uS(1000);  
    }
    temp = ds_therm_read_degC(ds_read_therm());
  sprintf(txdata, "%f\n", temp);
  nrf24l01_write_tx_float(&temp, 32, true);
  
  
  while(!(nrf24l01_irq_pin_active() && (nrf24l01_irq_tx_ds_active() || nrf24l01_irq_max_rt_active()))); 


  //Confirms acknowledge
  //if (!nrf24l01_irq_max_rt_active()) {
  //  nrf24l01_irq_clear_all();
  //  nrf24l01_set_as_rx(true);
  //}
  //else {
  //  nrf24l01_flush_tx(); //get the unsent character out of the TX FIFO
  //  nrf24l01_irq_clear_all(); //clear all interrupts
  //  printf("Node: Failed to send %c\n",txdata);
  //} 
  

  //Waits for data and reads it
  //while(!(nrf24l01_irq_pin_active() && nrf24l01_irq_rx_dr_active()));
  //nrf24l01_read_rx_payload(rxdata, 32);
  nrf24l01_irq_clear_all();
  

  //printf(rxdata);
  }
  
  //puts into transmit mode - not needed for base station
  ds_delay_uS(130);
  nrf24l01_set_as_tx();
}