Kode Dot
NFC
Tarjetas y etiquetas NFC para leerlas, escribir en ellas o hacer de etiqueta con el Kode Dot.
Qué es
NFC es la radio de corto alcance con la que un móvil paga o lee una etiqueta. El Kode Dot lleva un chip NFC, el ST25R3916B, que trabaja a 13,56 MHz con las tarjetas y etiquetas que acercas a la mitad de arriba de su parte trasera, donde está la bobina.

Tu app puede hacer tres cosas con una tarjeta o una etiqueta. Para todas tiene que activar el NFC al compilar.
kode_nfc_read_id dice qué tarjeta tienes delante y kode_nfc_read saca el texto o el enlace de una etiqueta.kode_nfc_write guarda un texto o un enlace en una etiqueta.kode_nfc_add_profile y kode_nfc_emulate_start el Kode Dot se presenta como una etiqueta que lee un móvil, o con la identidad de una tarjeta tuya.Por dentro
El chip NFC, un ST25R3916B, va en la placa de antenas y tiene un bus SPI para él
solo. KodeOS lo controla y tu app lo usa con las llamadas kode_nfc_*. El P4 le
da las órdenes por el bus y el chip le avisa por GPIO29 cuando pasa algo, como
que ha llegado una tarjeta. El chip mueve la antena, que trabaja a 13,56 MHz.

La antena es una pista de cobre que da tres vueltas en la placa de antenas. Esa placa va justo debajo de la carcasa trasera y por eso la tarjeta se acerca por detrás.

El circuito completo está en el esquema de la placa de antenas.
Especificaciones
KODE_NFC_TAG_DATA_MAX) en una etiqueta NTAG (Type 2) o Type 4. Si no cabe, no escribe nada.KODE_NFC_PROFILES_MAX) es una tarjeta de la que hace el Kode Dot. Su nombre ocupa hasta 15 bytes.CONFIG_KODEOS_NFC=n, el lector y el SPI2 quedan libres para tu app.Las llamadas son kode_nfc_read_id, kode_nfc_read, kode_nfc_write,
kode_nfc_scan_start, kode_nfc_scan_stop, kode_nfc_add_profile,
kode_nfc_emulate_start y kode_nfc_emulate_stop, en kode.h. Cada etiqueta
leída llega también como evento nfc_tag.
Errores comunes
kode_nfc_scan_start busca sin parar. Llama a kode_nfc_scan_stop en cuanto tengas la etiqueta.kode_nfc_* no existen. Añade CONFIG_KODEOS_NFC=y a sdkconfig.defaults, borra el archivo sdkconfig y vuelve a compilar.kode_nfc_emulate_stop.Apps que lo usan
NFCRead, save, emulate and write 13.56 MHz NFC cards and tags with the Kode Dot's own NFC antenna. - Read: hold a card or a tag on the Dot. It shows its UID, its model and what it carries (a link or a text) and, for a Mifare Classic, its sectors as they are read. - Save up to 16 cards on the microSD, with a name the Dot proposes. - Emulate: the Dot answers a reader as the saved card. An NTAG is emulated whole, with its content; a Mifare Classic is emulated by its UID only, so readers that check what is inside the card will not accept it. - Write a link or a text onto an NTAG or Ultralight tag (NTAG213 and NTAG215 stickers and cards are cheap and work well). - Keys: once one sector of a Mifare Classic is open, the Dot works out the keys of the others, sector by sector, on cards with a weak random-number generator. - Create card: make an NTAG213 or NTAG215 with its UID and a link or text, or a Mifare Classic UID, ready to emulate. The field is only on while you read, look for keys, emulate or write. Use it with your own cards. You will need a microSD to save cards, and NTAG stickers if you want to write.
TapYour NFC business card: save your Instagram, X, GitHub or website and hold the Dot to a phone to share it.Código de ejemplo
Acerca una tarjeta o una etiqueta NFC-A, como una NTAG, una Mifare o una DESFire, cerca del borde de arriba de la parte trasera del
Kode Dot. El programa la espera hasta dos segundos y, cuando la encuentra,
imprime su identidad y su tipo. Si en diez segundos no encuentra ninguna, avisa de
que sigue buscando. Si falla por otra cosa, imprime el motivo. Antes de
compilar, añade CONFIG_KODEOS_NFC=y a sdkconfig.defaults.
/* SPDX-License-Identifier: GPL-3.0-or-later */
/**
* @file nfc_read.c
* @brief Reads the identity of a card or tag held to the back of the Kode Dot.
*
* Every ten seconds without a tag it says it is still looking, and any other
* failure prints its reason. Needs CONFIG_KODEOS_NFC=y in sdkconfig.defaults.
*
* from Kode with love
*/
#include <stdio.h>
#include <string.h>
#include "kode.h"
#define NFC_WAIT_MS 2000U /**< How long each read waits for a tag. */
#define NFC_EMPTY_READS 5U /**< Empty reads before it says it still looks. */
#define NFC_WHY_BYTES 96U /**< Room for the reason a read failed. */
#define NFC_NO_TAG "no NFC tag" /**< How kode_error() starts when none came. */
/** @brief Start the system, then look for a tag over and over. */
void app_main(void)
{
uint8_t empty = 0U;
kode_init();
kode_print("Running: hold a card or tag to the back");
while ( true )
{
kode_tag_t tag = kode_nfc_read_id(NFC_WAIT_MS);
char why[NFC_WHY_BYTES];
/* kode_print clears kode_error(), so keep the reason first. */
(void)snprintf(why, sizeof(why), "%s", kode_error());
if ( tag.ok )
{
kode_print("tag %s, %s", tag.id, tag.name);
empty = 0U;
}
else if ( 0 != strncmp(why, NFC_NO_TAG, strlen(NFC_NO_TAG)) )
{
kode_print("could not read: %s", why);
}
else
{
empty++;
if ( NFC_EMPTY_READS <= empty )
{
kode_print("still looking: hold it on the back, near the top edge");
empty = 0U;
}
}
}
}Si prefieres compilarlo tú, sigue los pasos comunes a todos los ejemplos.
En el SDK
kdrv/nfc: el driver del lector enkode-sdk, descrito en el driver del ST25R3916.kdrv/rfal: la pila RFAL de ST, copiada sin cambios.examples/nfc_read: un ejemplo del SDK con las mismas llamadas.
