Skip to main content
Visitor II
March 2, 2021
Solved

SPI interface for STM32L476VG

  • March 2, 2021
  • 185 replies
  • 63548 views

STM32L476VG is the MCU we are interfacing with ST25R3911B using SPI.

what we have understood from some search is that we need RFAL (abstraction layer) to interface with RF HAL.

Then once we integrate RFAL and RF HAL in our system workbench(ac6) project we need to build the integration then use SPI calls to read the register from RFID reader ST25R3911B

we wanted to use ISO-14443A standard to be configured and read the values.

where do we get the basic RFAL work space or code flow so that we shall use in our current project?

Kindly guide us and let us know are we in right path?

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

    Hi,

    X-CUBE-NFC5 package provides an NFC polling demo using the RFAL and running on NUCLEO-L476RG (MCU board) + X-NUCLEO-NFC05A1 (ST25R3911B expansion board). It can be a good starting point for a project based on SYM32L476VG.

    Rgds

    BT

    185 replies

    RShiv.1Author
    Visitor II
    March 4, 2021

    Hi BT,

    I added uint8_t globalCommProtectCnt = 0U; in main.c and the compiling went well.I will make sure to read back register..and also on initialization.

    But why do we require demo.c and demo.h in our custom environment because we do not want to do ant platformledoff, and platformGpioIsLow..

    If I add demo.c and demo.h I see lot of places where certain define are not defined..we are seeing these errors

    #define PLATFORM_LED_A_PIN      LED_A_Pin       /*!< GPIO pin used for LED A  */

    #define PLATFORM_LED_A_PORT     LED_A_GPIO_Port    /*!< GPIO port used for LED A  */

    #define PLATFORM_LED_B_PIN      LED_B_Pin       /*!< GPIO pin used for LED B  */

    #define PLATFORM_LED_B_PORT     LED_B_GPIO_Port    /*!< GPIO port used for LED B  */

    #define PLATFORM_LED_F_PIN      LED_F_Pin       /*!< GPIO pin used for LED F  */

    #define PLATFORM_LED_F_PORT     LED_F_GPIO_Port    /*!< GPIO port used for LED F  */

    #define PLATFORM_LED_V_PIN      LED_V_Pin       /*!< GPIO pin used for LED V  */

    #define PLATFORM_LED_V_PORT     LED_V_GPIO_Port    /*!< GPIO port used for LED V  */

    #define PLATFORM_LED_AP2P_PIN    LED_AP2P_Pin     /*!< GPIO pin used for LED AP2P */

    #define PLATFORM_LED_AP2P_PORT    LED_AP2P_GPIO_Port  /*!< GPIO port used for LED AP2P*/

    LED_A_PIN not declared..likewise...

    so is demo.c really required??

    Kindly let us know

    regards

    Ravi

    Technical Moderator
    March 4, 2021

    Hi Ravi

    as explained in previous post,  for the LED pin you can define fake pin if not used on your custom board (i.e. just assign to an unused GPIO).

    demo.c provides the basic steps to communicate with a tag in respect with NFC protocol. This is usually used as a basis for customer applications i.e. this is used as a skeleton where one adds its specific application.

    Feel free to share more information about your application that we can support you accordingly.

    Rgds

    BT

    RShiv.1Author
    Visitor II
    March 5, 2021

    Hi BT,

    Thanks for your response.Our current application need is ST25R3911 which would be connected to antenna where we want to read RFID cards and ST25R will generate interuppt to STM32L476VG so that we shall read the value through SPI.I was able to compile with demo.c along with the project.

    I have also attached main.c where I have made changes in SPI..now can I do a dummy SPI write and SPI read to check whether SPI is working fine.kindly Let me know

    regards

    Ravi

    Technical Moderator
    March 5, 2021

    Hi Ravi,

    yes you can do a dummy SPI read write to check the SPI communication with the ST25R3911.

    For the next step, make sure to

    • align IRQ_3911_Pin  and IRQ_3911_GPIO to your actual interrupt pin (that seems to be PA3)
    • have st25r3911Isr(); being called in the EXTIxxxxx_IRQHandler interrupt call back
    • check that platformProtectST25RComm and platformUnprotectST25RComm properly disable/enable the right interrupt (it should be using IRQ_3911_EXTI_IRQn macro generated by STM32CubeMX)

    Then I recommend again to call demoIni as part of /* USER CODE BEGIN 2 */ and to add demoCycle in the while (1) loop (/* USER CODE BEGIN WHILE */) to run the various steps of the NFC protocol.

    Rgds

    BT

    RShiv.1Author
    Visitor II
    March 8, 2021

    HI BT,

    I have include demoIni() and democycle as part of main.c but I am getting following errors

    undefined reference to `rfalNfcGetDevicesFound

    undefined reference to `rfalNfcSelect' ..I have include demo.c and in that rfal_nfc.h as #include "..\..\Middlewares\ST\rfal\Inc\rfal_nfc.h" as this is the structure of my project...still did not understand why I got this error.

    also once this is integrated can I use  st25r3911WriteRegister( ST25R3911_REG_BIT_RATE, ST25R3911_TEST_REG_PATTERN ); so that I can do dummy SPI read and write

    is this correct? ..or any other code snippet...this is withour IRQ interrupt pin.Kindly suggest us.

    regards

    Ravi

    Technical Moderator
    March 8, 2021

    Hi Ravi

    I would suggest that you copy into your project the include paths from the reference project.

    Then, also make sure to add the following include in your main.c:

    /* USER CODE BEGIN Includes */
    #include "demo.h"
    #include "platform.h"
    #include "spi.h"
    #include "usart.h"
    #include "logger.h"
    #include "st_errno.h"
    #include "rfal_nfc.h"
    /* USER CODE END Includes */

    Rgds

    BT

    RShiv.1Author
    Visitor II
    March 8, 2021

    Hi BT,

    Its the demo.c that is throwing the problem

    C:\Users\RAVI\Documents\STM\UART_STM32_test\Debug/../Core/Src/demo.c:160: undefined reference to `rfalNfcGetDevicesFound'

    not the main.c ..even though the call is from main.c.I have attached demo.c code.

    regards

    Ravi

    Technical Moderator
    March 8, 2021

    Hi,

    as explained in my previous post, I suggest that you update the include paths of your project from the demo project.

    Rgds

    BT

    RShiv.1Author
    Visitor II
    March 8, 2021

    Hi BT,

    I have compiled main.c with demoini and also democycle now..can you now let me know how I can test SPI read or write without IRQ pin just to test the code

    It would be helpful if you give me snippet code if you have...kindly let me know.

    regards

    Ravi chandran

    Technical Moderator
    March 8, 2021

    Hi Ravi

    for testing the SPI, just add the following code in main.c line 127 before the call to demoIni()

     st25r3911WriteRegister( ST25R3911_REG_BIT_RATE, ST25R3911_TEST_REG_PATTERN );
     if( !st25r3911CheckReg( ST25R3911_REG_BIT_RATE, (ST25R3911_REG_BIT_RATE_mask_rxrate | ST25R3911_REG_BIT_RATE_mask_txrate), ST25R3911_TEST_REG_PATTERN ) )
    {
     platformLog("SPI test failed...\r\n");
     while (1);
    }
    platformLog("SPI communication OK...\r\n");

    make sure to remove st25r3911WriteRegister( ST25R3911_REG_BIT_RATE, ST25R3911_TEST_REG_PATTERN ); in line 196 (after demoCycle)

    Connect a serial terminal on virtual com port and check the output log.

    Once the SPI communication is OK, make sure to st25r3911Isr(); being called in the EXTIxxxxx_IRQHandler interrupt call back as explained in one of the previous posts.

    Rgds

    BT