コード例 #1
0
ファイル: rfid.c プロジェクト: KhMassri/DTNWorkspace
void rfid_init(void)
{
	/* reset SSP peripheral */
	LPC_SYSCON->PRESETCTRL = 0x01;

	/* Enable SSP clock */
	LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);

	// Enable SSP peripheral
	LPC_IOCON->PIO0_8 = 0x01 | (0x01 << 3); /* MISO, Pulldown */
	LPC_IOCON->PIO0_9 = 0x01; /* MOSI */

	LPC_IOCON->SCKLOC = 0x00; /* route to PIO0_10 */
	LPC_IOCON->JTAG_TCK_PIO0_10 = 0x02; /* SCK */

	/* Set SSP clock to 4.5MHz */
	LPC_SYSCON->SSPCLKDIV = 0x01;
	LPC_SSP->CR0 = 0x0707;
	LPC_SSP->CR1 = 0x0002;
	LPC_SSP->CPSR = 0x02;

	/* Initialize chip select line */
	GPIOSetDir(PN532_CS_PORT, PN532_CS_PIN, 1);
	rfid_cs(1);

	/* Initialize RESET line */
	GPIOSetDir(PN532_RESET_PORT, PN532_RESET_PIN, 1);
	rfid_reset(0);

}
コード例 #2
0
ファイル: rfid.c プロジェクト: code-constructor/openbeacon
void rfid_init(void)
{
	/* reset SSP peripheral */
	LPC_SYSCON->PRESETCTRL = 0x01;

	/* Enable SSP clock */
	LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 11);

	// Enable SSP peripheral
	LPC_IOCON->PIO0_8 = 0x01 | (0x01 << 3); /* MISO, Pulldown */
	LPC_IOCON->PIO0_9 = 0x01; /* MOSI */

	LPC_IOCON->SCKLOC = 0x00; /* route to PIO0_10 */
	LPC_IOCON->JTAG_TCK_PIO0_10 = 0x02; /* SCK */

	/* Set SSP clock to 4.5MHz */
	LPC_SYSCON->SSPCLKDIV = 0x01;
	LPC_SSP->CR0 = 0x0707;
	LPC_SSP->CR1 = 0x0002;
	LPC_SSP->CPSR = 0x02;

	/* Initialize chip select line */
	rfid_cs(1);
	GPIOSetDir(PN532_CS_PORT, PN532_CS_PIN, 1);

	/* Initialize RESET line */
	rfid_reset(0);
	GPIOSetDir(PN532_RESET_PORT, PN532_RESET_PIN, 1);

	/* Create PN532 task */
	xTaskCreate(rfid_task, (const signed char*) "RFID", TASK_RFID_STACK_SIZE,
			NULL, TASK_RFID_PRIORITY, NULL);
}
コード例 #3
0
ファイル: rfid.c プロジェクト: code-constructor/openbeacon
static
void rfid_task(void *pvParameters)
{
	int i;
	static unsigned char data[80];

	/* touch unused Parameter */
	(void) pvParameters;

	/* release reset line after 400ms */
	vTaskDelay( 400 / portTICK_RATE_MS);
	rfid_reset(1);
	/* wait for PN532 to boot */
	vTaskDelay( 100 / portTICK_RATE_MS);

	/* read firmware revision */
	debug_printf("\nreading firmware version...\n");
	data[0] = PN532_CMD_GetFirmwareVersion;
	rfid_execute(&data, 1, sizeof(data));

	/* enable debug output */
	debug_printf("\nenabling debug output...\n");
	WriteRegister(0x6328, 0xFC);
	// select test bus signal
	WriteRegister(0x6321, 6);
	// select test bus type
	WriteRegister(0x6322, 0x07);

	while (1)
	{
		/* wait 100ms */
		vTaskDelay( 100 / portTICK_RATE_MS);

		/* detect cards in field */
		GPIOSetValue(LED_PORT, LED_BIT, LED_ON);
		debug_printf("\nchecking for cards...\n");
		data[0] = PN532_CMD_InListPassiveTarget;
		data[1] = 0x01; /* MaxTg - maximum cards    */
		data[2] = 0x00; /* BrTy - 106 kbps type A   */
		if (((i = rfid_execute(&data, 3, sizeof(data))) >= 11) && (data[1]
				== 0x01) && (data[2] == 0x01))
		{
			debug_printf("card id: ");
			rfid_hexdump(&data[7], data[6]);
		}
		else
			debug_printf("unknown response of %i bytes\n", i);
		GPIOSetValue(LED_PORT, LED_BIT, LED_OFF);

		/* turning field off */
		debug_printf("\nturning field off again...\n");
		data[0] = PN532_CMD_RFConfiguration;
		data[1] = 0x01; /* CfgItem = 0x01           */
		data[2] = 0x00; /* RF Field = off           */
		rfid_execute(&data, 3, sizeof(data));
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: KhMassri/DTNWorkspace
static void
loop_rfid (void)
{
  int res;
  static unsigned char data[80];

  /* release reset line after 400ms */
  pmu_wait_ms (400);
  rfid_reset (1);
  /* wait for PN532 to boot */
  pmu_wait_ms (100);

  /* fully initialized */
  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);

  /* read firmware revision */
  debug_printf ("\nreading firmware version...\n");
  data[0] = PN532_CMD_GetFirmwareVersion;
  while ((res = rfid_execute (&data, 1, sizeof (data))) < 0)
  {
    debug_printf ("Reading Firmware Version Error [%i]\n", res);
    pmu_wait_ms (450);
    GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
    pmu_wait_ms (10);
    GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);
  }

  debug_printf ("PN532 Firmware Version: ");
  if (data[1] != 0x32)
    rfid_hexdump (&data[1], data[0]);
  else
    debug_printf ("v%i.%i\n", data[2], data[3]);

  /* enable debug output */
  debug_printf ("\nenabling debug output...\n");
  rfid_write_register (0x6328, 0xFC);
  // select test bus signal
  rfid_write_register (0x6321, 6);
  // select test bus type
  rfid_write_register (0x6322, 0x07);

  /* enable debug output */
  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
  while (1)
    {
      /* wait 10ms */
      pmu_wait_ms (10);

      /* detect cards in field */
      data[0] = PN532_CMD_InListPassiveTarget;
      data[1] = 0x01;		/* MaxTg - maximum cards    */
      data[2] = 0x00;		/* BrTy - 106 kbps type A   */
      if (((res = rfid_execute (&data, 3, sizeof (data))) >= 11) && (data[1]
								     == 0x01)
	  && (data[2] == 0x01))
	{
	  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	  pmu_wait_ms (50);
	  GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);

	  debug_printf ("card id: ");
	  rfid_hexdump (&data[7], data[6]);
	}
      else
	{
	  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	  if (res != -8)
	    debug_printf ("PN532 error res=%i\n", res);
	}

      /* turning field off */
      data[0] = PN532_CMD_RFConfiguration;
      data[1] = 0x01;		/* CfgItem = 0x01           */
      data[2] = 0x00;		/* RF Field = off           */
      rfid_execute (&data, 3, sizeof (data));
    }
}