Exemplo n.º 1
0
/* Send function.
 * Write to send_buf[1] - send_buf[31] before calling this function.
 * command will be placed in send_buf[0].*/
void send(command_t command)
{
  uint8_t i;

  // Set operation mode to transmit.
  CE_LOW();
  hal_nrf_set_operation_mode(HAL_NRF_PTX);
  // Copy command to send buffer.
  send_buf[0] = command; 
  hal_nrf_write_tx_payload(send_buf, PAYLOAD_SIZE);
  // Activate sender
  CE_PULSE();
  send_success = false;

  // Wait for radio to transmit
  while (RFF != 1) ;
  RFF = 0;
  nrf_irq(); 
  // Clear send buffer.
  for (i = 0; i < PAYLOAD_SIZE; i++) {
    send_buf[i] = 0x00;
  }
  // Reset operation mode to receive.
  hal_nrf_set_operation_mode(HAL_NRF_PRX);
  CE_HIGH();
}
Exemplo n.º 2
0
/** Send the RF packet to designated destination.
 * Use this function to send RF packet.
 *
 * @param *in_dst_addr The destination address.
 * @param *in_tx_pload The pointer point to the packet to be sent.
 * @param in_length The packet length.
 */
void epl_rf_en_send_dst(unsigned char *in_dst_addr, unsigned char *in_tx_pload, unsigned char in_pload_length)
{
	hal_nrf_set_address(HAL_NRF_TX, in_dst_addr); // Address for PTX (The address of destination.)
	epl_rf_en_enter_tx_mode();
	hal_nrf_write_tx_payload(in_tx_pload, in_pload_length);
	CE_PULSE();
}
Exemplo n.º 3
0
void radio_send_packet(uint8_t *packet, uint8_t length)
{
  hal_nrf_write_tx_pload(packet, length);      // load message into radio
  
  CE_PULSE();                                 // send packet

  radio_set_status (RF_BUSY);                 // trans. in progress; RF_BUSY
}
Exemplo n.º 4
0
//Send a packed in no-ack mode
void NRF24L01_TxPacketNoAck(char *payload, char len)
{
  int i;

  //Send the packet in the TX buffer
  RADIO_EN_CS();
  SPI_SendByte(CMD_W_PAYLOAD_NO_ACK);
  for(i=0;i<len;i++)
    SPI_SendByte(payload[i]);
  RADIO_DIS_CS();
  
  //Pulse CE
  CE_PULSE();
  
  return;
}
Exemplo n.º 5
0
//Send a packed in no-ack mode
void radioTxPacketNoAck(__xdata char *payload, char len)
{
  int i;

  //Send the packet in the TX buffer
  RADIO_EN_CS();
  spiRadioSend(CMD_W_TX_PAYLOAD_NO_ACK);
  for(i=0;i<len;i++)
    spiRadioSend(payload[i]);
  RADIO_DIS_CS();
  
  //Pulse CE
  CE_PULSE();
  
  return;
}
Exemplo n.º 6
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;
	}
}
Exemplo n.º 7
0
void main()
{
  uint8_t is = 0;;
  acq_block = 0;
  P0DIR = ~( 1<<6);
  //P1DIR = ~((1<<6) | (1<<5) | (1<<3));
 // P0CON = 0x66;

  #ifdef MCU_NRF24LU1P
     USBSLP = 0x01;  // disable usb
    // P0DIR = (1<<3)|(1<<1)|(1<<0);
	// P0ALT = 0x0F;
	// P0EXP = 0x02; // Slave SPI for P0
	// SSCONF = 0x01; //Enable slave SPI
	 
	 // Enable radio SPI
	 RFCTL = 0x10;
//	  I3FR = 1;             // rising edge SPI ready detect
	  P0_0 = 0;
//	  INTEXP = 0x01; //Slave SPI Interrupt
  #else
//  	P0DIR =  ~((1<<4)|(1<<0));
 // 	SPISCON0 = 0x40;
//	I3FR = 1;             // rising edge SPI ready detect
//	P1_4 = 1;
  //	INTEXP = 0x01; //Slave SPI Interrupt

  #endif

 // SPI = 1; // Enable SPI Interrupt


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


 //  hal_digi_init();
//   hal_digi_write(0);


	prog_led(14);
  	prog_led(0);

	init_radio();
	init_adc(); 
	initTimer();
	cnt = MAXLENGTH;
	dataNeedsTx = 0;
	hal_adc_start();
	procPayload = false;

	for(;;)
	{	
		if(!isStimulating)
		{
	//		PWRDWN = 0x07;
		}

		if(dataNeedsTx)
		{
			P1_4 = 1;
			++pktCount;
			payload[((acq_block^(0x01))&(0x01))][MAXLENGTH] = (isStimulating) + (pktCount&(0x7F)); 
		//	hal_nrf_set_power_mode(HAL_NRF_PWR_UP);
			hal_nrf_write_tx_payload(payload[((acq_block^(0x01))&(0x01))],MAXLENGTH+1);
			P1_4 = 0;
			radio_busy = true;
			    // Toggle radio CE signal to start transmission 
		    CE_PULSE();
		
		    
		
		    // Wait for radio operation to finish
		    while(radio_busy);
			
	//		hal_nrf_set_power_mode(HAL_NRF_PWR_DOWN);
			if(procPayload)
			{
				procPayload = false;
				pAll = (progAll *)progPayload;
			
				if(pAll->pType == PROGSTIM)
				{
					pStim = pAll->pStim;
					
					// g_Amplitude = pStim.Amplitude;

					if(0 == pStim.Freq || 0 == pStim.Amplitude)
					{
					   ET2 = 0;	  // disable timer2 interrupt
					   isStimulating = 0;
					   prog_led(pStim.Amplitude);	
					}
					else
					{
						ET2 = 1;
						progTimer(&pStim);
					}
				} 
				if(pAll->pType == PROGALGO)
				{
					pAlgo = pAll->pAlgo;
					low_thresh = pAlgo.low;
					high_thresh = pAlgo.high;
					progSD(&pAlgo);
				}	
			}
			dataNeedsTx = 0;
		}
	}
}
Exemplo n.º 8
0
/** Send the RF packet with the unchanged destination address.
 * Use this function to send RF packet with the last destination
 * address.
 *
 * @param *in_tx_pload The pointer point to the packet to be sent.
 * @param in_length The packet length.
 */
void epl_rf_en_send(unsigned char *in_tx_pload, unsigned char in_pload_length)
{
	epl_rf_en_enter_tx_mode();
	hal_nrf_write_tx_payload(in_tx_pload, in_pload_length);
	CE_PULSE();
}