Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Need an example to read rfid card from MFRC522 rfid scanner using spi protocol and correct reply this time

Hi,

I am also facing same issue i am able to read the version register correctly and able to perform self test successfully

I am using 17.1.0n RF5  SDK

 I am using SPI Master Example 

https://devzone.nordicsemi.com/f/nordic-q-a/55860/need-mfrc522-c-library-for-nrf52833   

Here is the link to same devzone ticket i am getting the same issue in that ticket and cannot able to solve the same please provide me some example to detect and read rfid cards that i am not able to do.

ticket no -241550,

    I am not sure that it has done caning because that is the issue it is giving me communication error not bale to solve by me.Please check and do the needful 

I am   developing NRF52832 DK. in Linux ubuntu OS and my board is PC10040

I'm building library C SPI mfrc522 for NRF52832.
I'm implement PCD_Read and write PCD_register look OK, But i call function PICC_IsNewCardPresent()  in main loop not detected NFC tag, in debug terminal it is coming Timeoout in communication" error

my main file

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "nrf_drv_spi.h"
#include "app_util_platform.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "boards.h"
#include "app_error.h"
#include <string.h>
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "mfrc522.h"
#define SPI_INSTANCE 0 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
static volatile bool spi_xfer_done; /**< Flag used to indicate that SPI instance completed the transfer. */
#define TEST_STRING "Nordic"
static uint8_t m_tx_buf[2];// /**< TX buffer. */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

my output when i debug in debug terminal :---(error)

Fullscreen
1
2
3
4
5
6
7
8
9
<info> app: SPI example started.
<info> app: version:F
<info> app: TModeReg:80
<info> app: TPrescalerReg:A9
<info> app: TPrescalerReg:A9
<info> app: STATUS_TIMEOUT2
<info> app: result:3
<info> app: STATUS_TIMEOUT2
<info> app: result:3
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

i have used the above attched library please check on mfrc522.c and mfrc522.h files for any quries

I am getting "Timeoout in communication" error even though i have placed the rfid id card continously on the scanner                                                                                                     #define STATUS_OK (0x00)// Success
#define STATUS_ERROR (0x01)// Error in communication
#define STATUS_COLLISION (0x02)// Collission detected
#define STATUS_TIMEOUT (0x03)// Timeout in communication.  ---i am getting this status as per my .h file   in my library.

PLEASE anyone help me out i  have been working on the same from past two weeks i have checked the hardware functionalities of the MFRC522 it is in working condition and i am having 2 rfid scanners in both also same issue please help me out..

If possible share the complete code to just read the cards iit will be helpful.

These are the libraries which i am using .h and .c files  

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "mfrc522.h"
#define debug_info(...) NRF_LOG_INFO(__VA_ARGS__)
#define SPI_INSTANCE 0 /**< SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE); /**< SPI instance. */
static volatile bool spi_xfer_done; /**< Flag used to indicate that SPI instance completed the transfer. */
static uint8_t m_tx_buf[2];// = TEST_STRING; /**< TX buffer. */
static uint8_t m_rx_buf[1]; /**< RX buffer. */
static uint8_t m_write_buf[1]; /**< RX buffer. */
static const uint8_t m_length = 1; /**< Transfer length. */
static const uint8_t m_tx_length = 2; /**< Transfer length. */
/**
* @brief SPI user event handler.
* @param event
*/
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
void * p_context)
{
spi_xfer_done = true;
// NRF_LOG_INFO("Transfer completed.");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

mfrc522.c

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "nrf_drv_spi.h"
#include "app_error.h"
#include <string.h>
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
typedef uint8_t byte;
typedef uint8_t PCD_Register;
typedef uint8_t PCD_Command;
typedef uint8_t PCD_RxGain;
typedef uint8_t PICC_Command;
typedef uint8_t PICC_Type;
typedef uint8_t StatusCode;
typedef uint8_t MIFARE_Misc;
// Page 0: Command and status
// 0x00 // reserved for future use
#define CommandReg (0x01 << 1)// starts and stops command execution
#define ComIEnReg (0x02 << 1)// enable and disable interrupt request control bits
#define DivIEnReg (0x03 << 1)// enable and disable interrupt request control bits
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

mfrc522.h file i am using.