Example #1
0
void initRadio(void){
	nrf24_init();
	nrf24_config(NRF24_CHANNEL_MHZ, NRF24_PAYLOAD_LEN);//channel 15, 16 byte payload
	nrf24_tx_address(ptxAddr);
	nrf24_rx_address(prxAddr);

}
Example #2
0
uint8_t nrf24_initialize()
{
    nrf24_setupPins();
    nrf24_ce_digitalWrite(LOW);
    nrf24_csn_digitalWrite(HIGH);
    nrf24_config(0, 32);

    return NRF24_OK;
}
Example #3
0
void copy_paste()
{

	int temp;
	nrf24_config(2, 4);
	nrf24_tx_address(tx_address11);
	nrf24_rx_address(rx_address11);
	while (1) {
		//LED0 = LED_ON;

		//LED1 = LED_ON;
		//LED2 = LED_ON;
		//LED3 = LED_ON;
		//delay_loop1();
		//LED0 = LED_OFF;
		//LED1 = LED_OFF;
		//LED2 = LED_OFF;
		//LED3 = LED_OFF;
		//delay_loop1();
		//nrf24_tx_address((uint8_t*) (uartBuffer + 1));
		data_array[0] = 0x00;
		data_array[1] = 0xAA;
		data_array[2] = 0x55;
		data_array[3] = 0x22;
		/* Automatically goes to TX mode */
		nrf24_send(data_array,4);
		/* Wait for transmission to end */
		while (nrf24_isSending());
		/* Make analysis on last tranmission attempt */
		temp = nrf24_lastMessageStatus();
		if (temp == NRF24_TRANSMISSON_OK)
		{
			//Do something
		}
		else if (temp == NRF24_MESSAGE_LOST)
		{
			//Do something else
		}
		/* Retranmission count indicates the tranmission quality */
		/* 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);

	}


}
Example #4
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(nrf24_thread(struct pt *pt))
{
    PT_BEGIN(pt);

    /* init hardware pins */
    nrf24_init();
    
    /* Channel #2 , payload length: 8 */
    nrf24_config(2,8);    

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

    uint32_t counter;
    uint16_t temp;
    int16_t realval;    

    while(1)
    {
        PT_WAIT_UNTIL(pt,nrf24_dataReady());

        dbg(PSTR("> -------------------------------------\r\n"));        
        
        nrf24_getData(data_array);

        temp = (data_array[0]<<8)+data_array[1];

        realval  = temp * 10;
        realval /= 11;             
        realval -= 500;

        dbg(PSTR("> RAW Temp: %u\r\n"),temp);
        dbg(PSTR("> Temp: %u\r\n"),realval);

        temp = (data_array[2]<<8)+data_array[3];

        dbg(PSTR("> Batt: %u\r\n"),temp);

        counter = (data_array[4]<<24)+(data_array[5]<<16)+(data_array[6]<<8)+data_array[7]; 

        dbg(PSTR("> Counter: %u\r\n"),counter);

    }

    PT_END(pt);
}
Example #5
0
int main(int argc, char **argv){

 uint8_t data_array[4];
 uint8_t tx_address[5] = { 0xE7, 0xE7, 0xE7, 0xE7, 0xE7 };
 uint8_t rx_address[5] = { 0xD7, 0xD7, 0xD7, 0xD7, 0xD7 };

 if (!bcm2835_init())
  return 1;

 mysql_connect();

 /* 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);

 printf("Configured\n");

 while (1){
  if (nrf24_dataReady()) {
   nrf24_getData(data_array);
   printf("> %d %d %d %d \n",
    data_array[0],
    data_array[1],
    data_array[2],
    data_array[3]);
  if (argc>1) {
   if (argv[1][0]=='1') {
    writeCpm(
     data_array[0],
     data_array[1],
     data_array[2],
     data_array[3]);
    }
   }
  }
 }
 mysql_disconnect();
 bcm2835_close();
 return 0;
}
Example #6
0
int main(void) {
    // LCD Screen
    lcd_init();
    terminal_init();

    // Input
    input_init();

    // Set power LED
    DDRB |= (1 << PINB6);
    clear_bit(PORTB, PINB6);

    // Radio
    uint8_t local_addr[] = { 0x1B, 0x1B, 0x1B, 0x1B, 0x1B };
    uint8_t robot_addr[] = { 0x0A, 0x0A, 0x0A, 0x0A, 0x0A };
    spi_init();
    nrf24_init();
    nrf24_config(47, sizeof(RemoteCommand)); // Channel 7
    nrf24_set_rx_addr(local_addr);
    nrf24_set_tx_addr(robot_addr);

    // Ready to go!
    sei();

    RemoteMode mode = MODE_MANUAL;

    while (1)
    {
        input_update(&input_state);

        switch (mode) {
        case MODE_MANUAL:
            UpdateManualMode(&input_state);
            break;
        case MODE_AUTO:
            asm("nop"::);
            break;
        case MODE_MENU:
            asm("nop"::);
            break;
        }
    }
}
Example #7
0
/* init the hardware pins */
void nrf24_init() 
{
    nrf24_setupPins();
    nrf24_ce_digitalWrite(LOW);
    nrf24_csn_digitalWrite(HIGH);
    nrf24_ce_digitalWrite(HIGH);
    nrf24_config(2,32);
    //nrf24_readRegister(CONFIG,&tx1,1);
    //tx1=0;
    //nrf24_configRegister(RF_CH,2);
    //nrf24_readRegister(EN_AA,&tx1,1);
    //tx1=0;
    nrf24_configRegister(RF_CH,2);
    nrf24_readRegister(RF_CH,&tx1,1);
    tx1=0;
    nrf24_readRegister(CONFIG,&tx1,1);
    tx1=0;
    nrf24_readRegister(RX_ADDR_P0,&readData,5);
    tx1=0;
    nrf24_readRegister(RF_SETUP,&tx1,1);
    tx1=0;
    nrf24_readRegister(TX_ADDR,&readData,5);
    tx1=0;
    nrf24_configRegister(SETUP_AW,2);
    //nrf24_readRegister(SETUP_AW,&tx1,1);
    //nrf24_configRegister(DYNPD,0x00);
    //nrf24_configRegister(FEATURE,0x00);
    //nrf24_tx_address(&tx_address11);
    //copy_paste();

//	nrf_cmd(0x20, 0x12);	//on, no crc, int on RX/TX done
//	nrf_cmd(0x21, 0x00);	//no auto-acknowledge
//	nrf_cmd(0x22, 0x00);	//no RX
//	nrf_cmd(0x23, 0x02);	//5-byte address
//	nrf_cmd(0x24, 0x00);	//no auto-retransmit
//	nrf_cmd(0x26, 0x06);	//1MBps at 0dBm
//	nrf_cmd(0x27, 0x3E);	//clear various flags
//	nrf_cmd(0x3C, 0x00);	//no dynamic payloads
//	nrf_cmd(0x3D, 0x00);	//no features
//	nrf_cmd(0x31, 32);	//always RX 32 bytes
//	nrf_cmd(0x22, 0x01);	//RX on pipe 0

}
Example #8
0
/*---------------------------------------------------------------------------*/
void init_hardware()
{
    /* init interrupt pin */
    pinMode(B,2,INPUT);

    /* init led ... */
    led0_init();
    led0_low();

    /* init hardware pins */
    nrf24_init();
    
    /* disable the analog comparator */
    ACSR = (1<<ACD); 

    /* channel #2 , payload length: 4 */
    nrf24_config(2,32);

    /* get the rx address from EEPROM */
    rx_address[0] = eeprom_read_byte((uint8_t*)10);
    rx_address[1] = eeprom_read_byte((uint8_t*)11);
    rx_address[2] = eeprom_read_byte((uint8_t*)12);
    rx_address[3] = eeprom_read_byte((uint8_t*)13);
    rx_address[4] = eeprom_read_byte((uint8_t*)14);

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

    /* initial power-down */
    nrf24_powerDown();

    /* disable digital buffer at the adc pin */
    cbi(DIDR0,ADC1D);

    PRR = (1<<PRTIM1)|(1<<PRTIM0)|(0<<PRADC)|(0<<PRUSI);
}
Example #9
0
int main() {
 DDRB |= 1<<PORTB3;
 PORTB |= 1<<PORTB3;

 ledPort |= _BV(ledPin);

 /* 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);

 pwm_init();   // initialize timer in PWM mode
 interupt_init();  //initalize Interrupt 0

 /* Fill the data buffer */
 data_array[0] = deviceID;
 data_array[1] = 0xAA;

 while(1) {
  data_array[3] = events;
  data_array[2] = events >> 8;
  nrf24_send(data_array);

  /* Wait for transmission to end */
  while(nrf24_isSending()) {
  }

  ledPort ^= _BV(ledPin);
  _delay_ms(80000);
 }
}
Example #10
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);
    }
}
   void main()
    {
   int   ldr1,ldr2,ldr1_p,ldr2_p, v, t,count ;
        char tx[7], a,b;
    int i;
int temp1;
char test[32];

CE_DIR=0;
CSN_DIR=0;
CSK_DIR=0;
MOSI_DIR=0;
MISO_DIR=1;

nrf24_config();
CSN=1;
CE=1;
//////////////////////////////////////////////

       lcd_init();
       //trisc=0;
        trisd=0;
        portd=0;
        count=0;
                   while(1)
          {
           //////////////////////////////////////////////////////////
           temp1=read_add(0x07);
if(((temp1&0b01000000)>>6)==1)
{
CE=0;
delay_ms(50);
//lcd_out(1,1,"data");
read_buff(0x61,test,32);
lcd_out(1,1,test);
delay_ms(2000);
reset();
CE=1;

}
else
lcd_out(1,1,"no  ");
          
          
          
          
          
          
          
          
          
          
          
          
         ///////////////////////////////////////////////////////////////
         /*ldr1=adc_read(1);
          ldr2=adc_read(2);
           v=adc_read(0);
              t=0.4887*v;
              if(t>=28)
                {portd=0b00110000;}
              else
                {portd=0;}

               a  =t/10;
               b =t%10;
               lcd_out(1,1,"temp=");
               lcd_chr(1,7,a+48);
               lcd_chr(1,8,b+48);
               if(ldr1>=900&&ldr1_p<800)
               {
             count++;
               }
               ldr1_p=ldr1;
                if(ldr2>=400&&ldr2_p<350)
               {
                count--;
                if(count<0)
                count=0;
               }
               ldr2_p=ldr2;
               a  =count/10;
               b =count%10;
               lcd_out(2,1,"count=");
               lcd_chr(2,8,a+48);
               lcd_chr(2,9,b+48);*/




}
Example #12
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  static u8 status;
  bool flag_display_retrans_cnt;
  disableInterrupts();
  Config();
  Errors_Init();
  enableInterrupts();
  Goto_HALT();
  
  while (1)
  {
    if((btn_pressed != BUTTON1) && (btn_pressed != BUTTON2))
    {
      DELAY_STOP;
      goto sleep;
    }
    
    PWR_PVDCmd(ENABLE);                    /* Power voltage detector and brownout Reset unit supply current 2,6uA */
    PWR_PVDLevelConfig(PWR_PVDLevel_2V26); /* Set Programmable voltage detector threshold to 2,26V */
    if(DELAY_EXPIRED)
      flag_display_retrans_cnt = TRUE;
    else 
      flag_display_retrans_cnt = FALSE;
    while(!DELAY_EXPIRED);           /* wait for power-up delay to expire (199.68ms) - needed for nRF24L01+ power up */
    DELAY_STOP;
    
    CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE);
    nrf24_init();                          /* init hardware pins */
    nrf24_config(0, 6);                    /* Channel #0 , payload length: 6 */
    nrf24_tx_address(tx_address);          /* Set the device addresses */
    nrf24_rx_address(rx_address);
    
    /* Check NRF24 Init error */
    if(Errors_CheckError(ERROR_NRF24_INIT))
    {
      LED_Red_Blink(2);
      goto sleep;
    }    

    TXmsg.M.status = 0;                    /* Reset status byte */
    
    /* Check Programmable voltage detector (PVD) output flag, if battery low send this information */
    /* Internal reference voltage should be stable at this point */
    if(PWR->CSR1 & PWR_FLAG_PVDOF)
    {
      /* VDD/VDDA is below the VPVD threshold (2,26V) */
      TXmsg.M.status |= STATUS_LOWBATT;
    }
    PWR_PVDCmd(DISABLE);
    
    if(btn_pressed == BUTTON1)
    {
      TXmsg.M.ownID = (u32)ownID_btn1;
      TXmsg.M.txcnt = tx_cnt++;
      nrf24_send((u8*)&TXmsg.B.b[0]);
    }
    else if(btn_pressed = BUTTON2)
    {
      TXmsg.M.ownID = (u32)ownID_btn2;
      TXmsg.M.txcnt = tx_cnt++;
      nrf24_send((u8*)&TXmsg.B.b[0]);
    }
    btn_pressed = 0;

    do
    {
      status = nrf24_getStatus();
    }
    while(!(status & ((1 << TX_DS)  | (1 << MAX_RT))));

    if(status & (1 << TX_DS))  /* send successful */
    {
      if(flag_display_retrans_cnt)
      {
        u8 i;
        u8 retrans_cnt = nrf24_retransmissionCount();
        LED_Green_Blink(retrans_cnt);
      }
      else
      {
        LED_Green_Blink(1);
      }
    }
    else if(status & (1 << MAX_RT))  /* send failed, max retries exceeded */
    {
      LED_Red_Blink(1);
    }
    
    sleep:
    Goto_HALT();
  }
}
Example #13
0
static void nrf24_test(void) {
	uint8_t rx_address[5] = {0xA7,0x95,0xF1,0x36,0x07};
	uint8_t tx_address[5] = {0xA7,0x95,0xF1,0x36,0x06};
	//uint8_t tx_address[5] = {0x17,0x97,0xA7,0xA7,0xD7};
	uint8_t addr[10] = {0x1};
	uint8_t val = 0x17;
	uint8_t reg;
	uint8_t data_array[6];
	uint32_t counter = 0;

	spi_delay(1000000);
	/* init hardware pins */
	nrf24_init();

	if (spi_init() < 0) {
		printf("ERRRRROR SPI!\n");
	}

	/* Returned value is not correct on the first read, who knows why... */
	nrf24_readRegister(CONFIG, &reg, 1);

	nrf24_readRegister(CONFIG, &reg, 1);
	printf("CONFIG (before configured) = %x\n", reg);
	nrf24_readRegister(EN_AA, &reg, 1);
	printf("EN_AA = %x\n", reg);
	nrf24_readRegister(RF_SETUP, &reg, 1);
	printf("RF_SETUP = %x\n", reg);
	nrf24_readRegister(SETUP_AW, &reg, 1);
	printf("SETUP_AW = %x\n", reg);
	nrf24_readRegister(SETUP_RETR, &reg, 1);
	printf("SETUP_RETR = %x\n", reg);
	nrf24_readRegister(FIFO_STATUS, &reg, 1);
	printf("FIFO_STATUS = %x\n", reg);

	nrf24_readRegister(RF_CH, &reg, 1);
	printf("RF_CH = %x\n", reg);
	nrf24_writeRegister(RF_CH, &val, 1);
	nrf24_readRegister(RF_CH, &reg, 1);
	printf("RF_CH = %x\n", reg);
	val = 2;
	nrf24_writeRegister(RF_CH, &val, 1);
	nrf24_readRegister(RF_CH, &reg, 1);
	printf("RF_CH = %x\n", reg);

#if 1
	nrf24_readRegister(RX_ADDR_P0, addr, 5);
	printf("RX_ADDR_P0: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
	nrf24_writeRegister(RX_ADDR_P0, tx_address,5);
	spi_delay(1000000);
	nrf24_readRegister(RX_ADDR_P0, addr, 5);
	printf("RX_ADDR_P0: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
	
	spi_delay(1000000);
	nrf24_readRegister(RF_CH, &reg, 1);

	nrf24_readRegister(TX_ADDR, addr, 5);
	printf("TX_ADDR: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
	nrf24_writeRegister(TX_ADDR, tx_address,5);
	nrf24_readRegister(TX_ADDR, addr, 5);
	printf("TX_ADDR: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);

	spi_delay(1000000);

	nrf24_readRegister(RX_ADDR_P1, addr, 5);
	printf("RX_ADDR_P1: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
	nrf24_writeRegister(RX_ADDR_P1, rx_address,5);
	nrf24_readRegister(RX_ADDR_P1, addr, 5);
	printf("RX_ADDR_P1: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
#endif

	/* Channel #2 , payload length: 4 */
	nrf24_config(16,6);

    nrf24_readRegister(FIFO_STATUS,&reg,1);
	printf("!> 1 FIFO_STATUS = %2X\n", reg);

	spi_delay(1000000);

	nrf24_readRegister(CONFIG, &reg, 1);
	nrf24_readRegister(CONFIG, &reg, 1);
	printf("CONFIG (after configured) = %x\n", reg);
	nrf24_readRegister(EN_AA, &reg, 1);
	printf("EN_AA = %x\n", reg);
	nrf24_readRegister(RF_SETUP, &reg, 1);
	printf("RF_SETUP = %x\n", reg);

	nrf24_readRegister(TX_ADDR, addr, 5);
	printf("TX addr is: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
	//spi_delay(1000000);
	nrf24_readRegister(RX_ADDR_P0, addr, 5);
	printf("RX addr is: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
	//spi_delay(1000000);
	nrf24_readRegister(RX_ADDR_P1, addr, 5);
	printf("RX_ADDR_P1 addr is: %x %x %x %x %x\n", addr[0], addr[1], addr[2], addr[3], addr[4]);
    
	nrf24_readRegister(FIFO_STATUS,&reg,1);
	printf("!!!!!!> 2 FIFO_STATUS = %2X\n", reg);

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

	//nrf24_ce_digitalWrite(HIGH);

	//reg = nrf24_getStatus();
	//printf("STATUS = %2X\n", reg);

	nrf24_readRegister(FIFO_STATUS,&reg,1);
	printf("!!!!!!> 3 FIFO_STATUS = %2X\n", reg);

	while(1) {
		if(nrf24_dataReady())
		{
			counter = 0;
			//reg = nrf24_getStatus();
			//printf("STATUS = %x\n", reg);
			nrf24_getData(data_array);
			printf("> ");
			printf("%2X ",data_array[0]);
			printf("%2X ",data_array[1]);
			printf("%2X ",data_array[2]);
			printf("%2X ",data_array[3]);
			printf("%2X ",data_array[4]);
			printf("%2X\r\n",data_array[5]);
			//spi_delay(1000);
		} else if (counter > 100000) {
			reg = nrf24_getStatus();
			printf("(counter > 100000) STATUS = %2X\n", reg);
			nrf24_readRegister(FIFO_STATUS,&reg,1);
			printf("(counter > 100000) FIFO_STATUS = %2X\n", reg);
		}
		counter++;
	}
}
Example #14
0
File: main.c Project: ksrm/redox
int main() {

    uint8_t i, change;
    uint8_t hand;
    uint32_t timeout = 0;

    uart_init();
    xdev_out(uart_putchar);

    // Determine which hand this is from PE2
    // Left is hand 0, right is hand 1
    PORTE = (1 << 2);
    DDRE = 0;
    hand = (PINE & 0x04) ? 0 : 1;
    xprintf("\r\nHand %d\r\n", hand);
    
    // Initialise NRF24
    // Set the last byte of the address to the hand ID
    rx_address[4] = hand;
    nrf24_init();
    nrf24_config(CHANNEL, sizeof msg);
    nrf24_tx_address(tx_address);
    nrf24_rx_address(rx_address);

    matrix_init();

    msg[0] = hand & 0x01;
    msg[1] = 0;
    msg[2] = 0;

    // Set up LED and flash it briefly
    DDRE |= 1<<6;
    PORTE = 1<<6;
    _delay_ms(500);
    PORTE = 0;

    get_voltage();
    check_voltage();

    // Scan the matrix and detect any changes.
    // Modified rows are sent to the receiver.
    while (1) {  
        timeout++;
        matrix_scan();

        for (i=0; i<ROWS; i++) {
            change = matrix_prev[i] ^ matrix[i];

            // If this row has changed, send the row number and its current state
            if (change) {
                if (DEBUG) xprintf("%d %08b -> %08b   %ld\r\n", i, matrix_prev[i], matrix[i], timeout);
                msg[1] = i;
                msg[2] = matrix[i];

                nrf24_send(msg);
                while (nrf24_isSending());
                timeout = 0;
            }

            matrix_prev[i] = matrix[i];
        }

        // Sleep if there has been no activity for a while
        if (timeout > SLEEP_TIMEOUT) {
            timeout = 0;
            enter_sleep_mode();
        }
    }

}
void main() {
int i;
int temp1;
char test[32];
uart1_init(2400);
CE_DIR=0;
CSN_DIR=0;
CSK_DIR=0;
MOSI_DIR=0;
MISO_DIR=1;
delay_ms(500);
nrf24_config();
CSN=1;
CE=1;




lcd_init();
Lcd_Cmd(_LCD_CURSOR_OFF);
//lcd_out(2,1,"welcome");

trisb.f0=0;
rb0_bit=0;
trisd.f0=0;
for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(400);
rd0_bit=0;
delay_us(19600);

}
uart1_write_text("TEST");
uart1_write(13);

//lcd_out(1,1,"S");
while(1)
{
  temp1=read_add(0x07);
if(((temp1&0b01000000)>>6)==1)
{
CE=0;
delay_ms(50);
//lcd_out(1,1,"data");
read_buff(0x61,test,32);
uart1_write_text(test);
lcd_out(1,1,test);
reset();
CE=1;

}


















 if(uart1_data_ready())
 {
  rfid[idx]=uart1_read();

   ///////////////////////////////////////////////////////////03002e2838
  if(rfid[idx]=='0'&&valid2<10)
  {
   valid2++;
  }
   else if(rfid[idx]=='3'&&valid2<10)
  {
   valid2++;
  }
   else if(rfid[idx]=='2'&&valid2<10)
  {
   valid2++;
  }
  else if(rfid[idx]=='E'&&valid2==5)
  {
   valid2++;
  }
  else if(rfid[idx]=='8'&&valid2<10)
  {
   valid2++;
   }
  else
  {
  valid2=0;
  }



   if(rfid[idx]=='0'&&valid1<10) //03002e90b0
  {
   valid1++;
  }
   else if(rfid[idx]=='3'&&valid1==1)
  {
   valid1++;
  }
   else if(rfid[idx]=='2'&&valid1==4)
  {
   valid1++;
  }
  else if(rfid[idx]=='E'&&valid1==5)
  {
   valid1++;
  }
  else if(rfid[idx]=='9'&&valid1==6)
  {
   valid1++;
  }
    else if(rfid[idx]=='B'&&valid1==8)
  {
   valid1++;
  }
  else
  {
  valid1=0;
  }








  if(valid2>=10)
  {
  lcd_out(2,1,"User2 : 03002E2838");
  delay_ms(1000);
   lcd_cmd(_lcd_clear);
   lcd_out(2,1,"UnValid");
   valid2=0;
   for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(400);
rd0_bit=0;
delay_us(19600);

}
   delay_ms(1000);
   lcd_cmd(_lcd_clear);
  }



 if(valid1>=10)
  {
  lcd_out(2,1,"User1 : 03002E90B0");
     delay_ms(1000);
   lcd_cmd(_lcd_clear);
   lcd_out(2,1,"Valid");
   valid1=0;
   for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(1500);
rd0_bit=0;
delay_us(18500);

}
   delay_ms(1000);
    for(i=0;i<30;i++)
{
rd0_bit=1;
delay_us(400);
rd0_bit=0;
delay_us(19600);

}
   
   
   
   lcd_cmd(_lcd_clear);
  }

 }



}






}
Example #16
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]);
          }
      }
*/
  }
}