Skip to main content
Explorer
May 5, 2023
Solved

I want to send the ST25R3916B nfc tag readings to CAN bus.

  • May 5, 2023
  • 12 replies
  • 5420 views

I have program for CAN bus and NFC08a1 but when i combine i get several errors. All i want to do is get the reading from the nfc reader and send them on can. does anyone know how to do that?

    This topic has been closed for replies.
    Best answer by Brian TIDAL

    Issue solved.

    To ensure that the compiled driver meets the user intended device, it is required to add a pre-processor instruction defining the targeted ST25R device (e.g. ST25R3916B).

    This needs to be globally defined as a compiler define (i.e. the RFAL source code should ***not**** be modified to add this define at source file level).

    BT

    12 replies

    Technical Moderator
    May 11, 2023

    Hi,

    can you elaborate on your issue:

    • which MCU or MCU board do you use?
    • do you use any expansion boards in addition to X-NUCLEO-NFC08A1 ?
    • which kind of error do you face ?

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 11, 2023

    I am using l476rg board. I have nfc08a1 working and can bus work separately when i combine the code nothing works. I dont know why. The nfc08a1 wont work at all. I made sure the clock configuration is all good. I am using mcp2551 transceiver for can bus but nothing else. I am not getting any error the code compiles and everything.

    Technical Moderator
    May 11, 2023

    Hi,

    do you use ST X-CUBE-NFC6 FW package? if yes, can you recompile with ST25R_SELFTEST being defined and check the return code of st25r3916Initialize function?

    Also can you connect a logic analyzer on SPI (CLK/MOSI/MISO/CS) + IRQ_3916 and provide a trace?

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 11, 2023

    Yes indeed that is the library package i have been using. Where in the program do you want me to define selftest? in the main function? Yes i can connect the logic analyzer on the spi and interrupt pins.

    Technical Moderator
    May 11, 2023

    Hi,

    just add ST25R_SELFTEST in the list of preprocessor defines in the compiler configuration of your IDE

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 11, 2023

    I did it. Still no difference. I have no errors like i expected but nothing on the nfc08a1.

    Technical Moderator
    May 11, 2023

    Hi,

    you mean: st25r3916Initialize returns ERR_NONE?

    Can you elaborate on your code using the RFAL:

    • is your code based on the demo_polling.c provided in the X-CUBE-NFC06A1 package or do you have your own polling loop ?
    • if using your own polling loop, do you use RFAL High Layer API from rfal_nfc.c or directly technology API from rfal_nfca.c/rfal_nfcb.c/rfal_nfcf.c/rfal_nfcv.c?

    Can you set a breakpoint in rfalFieldOnAndStartGT and check the return code?

    Using an oscilloscope, can you probe the RF field?  (just connect the GND of the probe to the tip of the probe and put the probe on the antenna and you should be able to capture the field)

    Can you provide a logic analyzer trace (SPI+IRQ)?

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 11, 2023

    Hey Brian, YEs the code is based on pollingdetectndef.. I put the logic analyzer on spi and irq no data at all. It acts like as though Spi is not initialized even i did. I can send you my entire code. do you have an email address? I am super new to cubeide and this is my very first project.

    Technical Moderator
    May 12, 2023

    Hi,

    if the SPI is not initialized, it is unlikely that st25r3916Initialize() returns ERR_NONE (as st25r3916Initialize is supposed to read the IC Identity over SPI...). I would suggest to check the logic analyzer connection to the X-NUCLEO-NFC08A1 (e.g. GND pin...).

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 12, 2023

    I did put the analyzer and nothing on it. Only enable disable for spi.

    int main(void)
    {
     /* USER CODE BEGIN 1 */
    //	char uart_buf[50];
    //	int uart_buf_len;
    //	char spi_buf[20];
     /* USER CODE END 1 */
     
     /* MCU Configuration--------------------------------------------------------*/
     
     /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
     HAL_Init();
     
     /* USER CODE BEGIN Init */
     
     /* USER CODE END Init */
     
     /* Configure the system clock */
     SystemClock_Config();
     
     /* USER CODE BEGIN SysInit */
     
     /* USER CODE END SysInit */
     
     /* Initialize all configured peripherals */
     MX_GPIO_Init();
     MX_DMA_Init();
    // MX_I2C1_Init();
     MX_SPI1_Init();
     /* USER CODE BEGIN 2 */
     NFC08A1_LED_Init();
     BSP_PB_Init(BUTTON_USER, BUTTON_MODE_GPIO);
     MX_SPI1_Init();
     MX_USART2_UART_Init();
     
     
     /* USER CODE END 2 */
     
     /* Infinite loop */
     /* USER CODE BEGIN WHILE */
     while (1)
     {
     
     
    	 demoCycle();
     
     }
    }

    Technical Moderator
    May 14, 2023

    Hi,

    obviously, demoIni in missing in your main.c in  /* USER CODE BEGIN 2 */, as well as logUsartInit. MX_SPI1_Init() is called twice.

    As it seems you have regenerated the project from STM32CubeMX, I would suggest you follow the tutorial from https://community.st.com/s/question/0D53W00001Px5sKSAR/how-to-create-a-project-with-x-cube-nfc06, in particular make sure to add  st25r3916Isr() in EXTI0_IRQHandler

    Once demoIni has been added, put a breakpoint in st25r3916Initialize and check the return code.

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 15, 2023

    I followed everything on the link but now i am getting these errors.

    In file included from ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.h:28,

             from ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:25:

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c: In function 'st25r3916Initialize':

    ../Core/Inc/platform.h:131:54: warning: statement with no effect [-Wunused-value]

     131 | #define platformErrorHandle()            Error_Handler      /*!< Global error handler or trap        */

       |                           ^~~~~~~~~~~~~

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:140:9: note: in expansion of macro 'platformErrorHandle'

     140 |     platformErrorHandle();

       |     ^~~~~~~~~~~~~~~~~~~

    ../Core/Inc/platform.h:131:54: warning: statement with no effect [-Wunused-value]

     131 | #define platformErrorHandle()            Error_Handler      /*!< Global error handler or trap        */

       |                           ^~~~~~~~~~~~~

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:200:9: note: in expansion of macro 'platformErrorHandle'

     200 |     platformErrorHandle();

       |     ^~~~~~~~~~~~~~~~~~~

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:207:42: error: 'ST25R3916_CMD_RC_CAL' undeclared (first use in this function); did you mean 'ST25R3916_CMD_STOP'?

     207 |   st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_RC_CAL, ST25R3916_REG_AWS_RC_CAL, ST25R3916_TOUT_CALIBRATE_AWS_RC, NULL );

       |                     ^~~~~~~~~~~~~~~~~~~~

       |                     ST25R3916_CMD_STOP

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:207:42: note: each undeclared identifier is reported only once for each function it appears in

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:207:65: error: 'ST25R3916_REG_AWS_RC_CAL' undeclared (first use in this function); did you mean 'ST25R3916_REG_P2P_RX_CONF'?

     207 |   st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_RC_CAL, ST25R3916_REG_AWS_RC_CAL, ST25R3916_TOUT_CALIBRATE_AWS_RC, NULL );

       |                                 ^~~~~~~~~~~~~~~~~~~~~~~~

       |                                 ST25R3916_REG_P2P_RX_CONF

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c: In function 'st25r3916GetRegsDump':

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:709:28: error: 'ST25R3916_REG_AWS_CONF1' undeclared (first use in this function); did you mean 'ST25R3916_REG_IO_CONF1'?

     709 |   st25r3916ReadRegister( ST25R3916_REG_AWS_CONF1, &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_IO_CONF1

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:710:28: error: 'ST25R3916_REG_AWS_CONF2' undeclared (first use in this function); did you mean 'ST25R3916_REG_RX_CONF2'?

     710 |   st25r3916ReadRegister( ST25R3916_REG_AWS_CONF2, &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_RX_CONF2

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:719:28: error: 'ST25R3916_REG_AWS_TIME1' undeclared (first use in this function); did you mean 'ST25R3916_REG_AUX_MOD'?

     719 |   st25r3916ReadRegister( ST25R3916_REG_AWS_TIME1,  &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_AUX_MOD

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:720:28: error: 'ST25R3916_REG_AWS_TIME2' undeclared (first use in this function); did you mean 'ST25R3916_REG_AUX_MOD'?

     720 |   st25r3916ReadRegister( ST25R3916_REG_AWS_TIME2,  &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_AUX_MOD

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:721:28: error: 'ST25R3916_REG_AWS_TIME3' undeclared (first use in this function); did you mean 'ST25R3916_REG_AUX_MOD'?

     721 |   st25r3916ReadRegister( ST25R3916_REG_AWS_TIME3,  &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_AUX_MOD

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:722:28: error: 'ST25R3916_REG_AWS_TIME4' undeclared (first use in this function); did you mean 'ST25R3916_REG_AUX_MOD'?

     722 |   st25r3916ReadRegister( ST25R3916_REG_AWS_TIME4,  &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_AUX_MOD

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:723:28: error: 'ST25R3916_REG_AWS_TIME5' undeclared (first use in this function); did you mean 'ST25R3916_REG_AUX_MOD'?

     723 |   st25r3916ReadRegister( ST25R3916_REG_AWS_TIME5,  &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_AUX_MOD

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:724:28: error: 'ST25R3916_REG_AWS_RC_CAL' undeclared (first use in this function); did you mean 'ST25R3916_REG_P2P_RX_CONF'?

     724 |   st25r3916ReadRegister( ST25R3916_REG_AWS_RC_CAL, &regDump->RsB[regIt++] );

       |              ^~~~~~~~~~~~~~~~~~~~~~~~

       |              ST25R3916_REG_P2P_RX_CONF

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c: In function 'st25r3916IsCmdValid':

    ../Drivers/library files/BSP/Components/ST25R3916/st25r3916.c:740:17: error: 'ST25R3916_CMD_RC_CAL' undeclared (first use in this function); did you mean 'ST25R3916_CMD_STOP'?

     740 |     (cmd != ST25R3916_CMD_RC_CAL)                                      &&

       |         ^~~~~~~~~~~~~~~~~~~~

       |         ST25R3916_CMD_STOP

    make: *** [Drivers/library files/BSP/Components/ST25R3916/subdir.mk:39: Drivers/library files/BSP/Components/ST25R3916/st25r3916.o] Error 1

    "make -j20 all" terminated with exit code 2. Build might be incomplete

    Technical Moderator
    May 15, 2023

    Hi,

    you have probably mixed up some packages. Make sure to use the proper st25r3916_com.h with the proper definition of ST25R3916B registers (i.e. with #ifdef ST25R3916B to define the registers specific to ST25R3616B in another words: use the .c/.h files from the latest X-CUBE-NFC6 package).

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 15, 2023

    okay. I will report in few. Thank you so much for helping me i really appreciate it.

    Technical Moderator
    May 15, 2023

    Hi,

    make sure to keep platformErrorHandle aligned with the error handler function defined in the main.c (i.e. Error_Handler).

    The SPI settings are incorrect vs the ST26R3916B Datasheet .:

    •  hspi1.Init.DataSize = SPI_DATASIZE_8BIT; <<<<< 8 bits, not 4 bits
    •  hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; <<<< a clock polarity of 0, a clock phase of 1, 
    • SPI_BAUDRATEPRESCALER_2 looks strange to me. Make sure to not exceed 6Mbps when configuring from STM32CubeMx (likely SPI_BAUDRATEPRESCALER_16 for a system clock `@80MHz)

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 15, 2023

    ok i get it.

    Technical Moderator
    May 15, 2023

    hi,

    can you now provide the logic analyzer trace?

    rgds

    BT

    NAkku.1Author
    Explorer
    May 15, 2023

    yes ofcourse.

    Technical Moderator
    May 15, 2023

    Hi,

    can you add the IRQ_3916B signal and send to me the salae file so that I can analyze it (I can do nothing with a screen shot).

    Thanks

    Rgds

    BT

    NAkku.1Author
    Explorer
    May 15, 2023

    it wont let me send sal file here.