cancel
Showing results for 
Search instead for 
Did you mean: 

ST25R3916B migration to NORDIC

massimoperdigo
Associate II

Good morning, everyone!

I'm new here at the ST forum, so please forgive me if I make any mistakes.

Currently, I'm working on migrating the ST25R3916B library for the X-NUCLEO 08A1 DK from ST to Nordic (specifically, nRF52840).

I've already replaced all the SPI functions from ST with the Nordic ones, and I've confirmed successful SPI communication using the SALEAE device. However, I'm encountering an issue with the MISO channel not receiving the correct parameters. As a result, the program initialization is failing in the line: 

massimoperdigo_0-1689611198770.png

Here i have my platfrom.h configuration:

 

#define platformProtectST25RComm()                do{ globalCommProtectCnt++;                  \
                                                          __DSB();nrf_drv_gpiote_in_event_enable(ST25R_INT_PIN, false); \
                                                          __DSB();                             \
                                                          __ISB();                             \
                                                        }while(0)                                   
#define platformUnprotectST25RComm()              do{ globalCommProtectCnt--;             \
                                                          if (globalCommProtectCnt == 0U) \
                                                          {                               \
                                                            nrf_drv_gpiote_in_event_enable(ST25R_INT_PIN, true);   \
                                                          }                               \
                                                        }while(0)                                   

                                                   
#define platformProtectST25RIrqStatus()           platformProtectST25RComm()                 
#define platformUnprotectST25RIrqStatus()         platformUnprotectST25RComm()              
#define platformProtectWorker()                                                                     
#define platformUnprotectWorker()                                                                   

#define platformIrqST25RSetCallback( cb )
#define platformIrqST25RPinInitialize()

#define platformLedsInitialize()                                                                    /*!< Initializes the pins used as LEDs to outputs*/

#define platformLedOff( pin )                        platformGpioClear( pin)                  /*!< Turns the given LED Off                     */
#define platformLedOn(  pin )                        platformGpioSet( pin)                    /*!< Turns the given LED On                      */
#define platformLedToogle( pin )                     platformGpioToogle( pin)                 

#define platformGpioSet(  pin )                      nrf_gpio_pin_write(pin, 1)                    
#define platformGpioClear(  pin )                    nrf_gpio_pin_write(pin, 0)                    
#define platformGpioToogle(  pin )                   nrf_gpio_pin_toggle(pin)                 
#define platformGpioIsHigh(  pin )                   (nrf_gpio_pin_read(pin)==1)                   
#define platformGpioIsLow(  pin )                    (!platformGpioIsHigh( pin))              

#define platformTimerCreate( t )                      timerCalculateTimer(t)                        
#define platformTimerIsExpired( timer )               timerIsExpired(timer)                         
#define platformTimerDestroy( timer )                                                               
#define platformDelay( t )                            nrf_delay_ms( t )                                

#define platformGetSysTick()                          BSP_GetTick()                                 

#define platformErrorHandle()                         _Error_Handler(__FILE__,__LINE__)             

//NORDIC FUNCTIONS
#define platformSpiTxRx( txBuf, rxBuf, len )          BSP_SPI1_SendRecv(txBuf, rxBuf, len)             
#define platformSpiSelect()                           nrf_gpio_pin_clear(SSCHIP)                            
#define platformSpiDeselect()                         nrf_gpio_pin_set(SSCHIP)                              
            

 

and here I have a interface file to link the st25r library to nordic:

 

//instancia SPI
#define SPI_INSTANCE 0

nrf_drv_spi_t hSpi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);

//handler SPI
void spi_event_handler(nrf_drv_spi_evt_t const * p_event, void * p_context)
{
}


//INIT SPI
void spi_init(void)
{
  nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;

  spi_config.miso_pin = 27; 
  spi_config.mosi_pin = 25;
  spi_config.sck_pin  = 24; 

  //CHIPSELECT IS CONFIGURED ALONE, TO AVOID END OF TRANSMISSION AFTER ONE TRANSMISION
  nrf_gpio_cfg_output(SSCHIP);
  APP_ERROR_CHECK(nrf_drv_spi_init(&hSpi, &spi_config,spi_event_handler,NULL));
}

//HANDLER INTERRUPTION
void input_pin_handle(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
  
}


//FUNCTION TO INIT THE INTERRUPTION
void gpiote_init()
{
  ret_code_t err_code;

  err_code = nrf_drv_gpiote_init();
  APP_ERROR_CHECK(err_code);

  nrf_drv_gpiote_in_config_t in_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
  in_config.pull = NRF_GPIO_PIN_PULLUP;

  err_code = nrf_drv_gpiote_in_init(ST25R_INT_PIN, &in_config, input_pin_handle);
  APP_ERROR_CHECK(err_code);

  nrf_drv_gpiote_in_event_enable(ST25R_INT_PIN, true);

}






/*************************************************

/*
*//////////////////////////////////////////////////////

//SEND TRANSMIT FUNCTIONS (NORDIC)

void BSP_SPI1_SendRecv(const uint8_t * const pTxData, uint8_t * const pRxData, uint16_t Length)
{
  ret_code_t err_code;
  if((pTxData != NULL) && (pRxData != NULL))
  {
   
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&hSpi,pTxData,Length,pRxData, Length));

  } 
  if ((pTxData != NULL) && (pRxData == NULL)) 
  {
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&hSpi,pTxData,Length,NULL, 0));

  } 
  else if ((pTxData == NULL) && (pRxData != NULL)) 
  {
    
    err_code = nrf_drv_spi_transfer(&hSpi,NULL,0,pRxData,Length);
    APP_ERROR_CHECK(err_code);

  }

}

 

I believe the issue lies within the SPI configuration. While I am able to send and receive data, there are instances where the received data does not match the expected values by the ST25R3916B.

As you can see, the interruption gets triggered.

massimoperdigo_1-1689611975885.png

in this image, i'm asking for the CHIPID, and I receive 0x18 (that's the same with the NUCLEO L053).

massimoperdigo_2-1689612032936.png

otherwise, here i should expect some data, and i do not get anything: 

massimoperdigo_3-1689612093442.png

In addition, it's worth noting that the Chip Select (CS) pin only changes at the beginning and end of each transmission. This behavior is intentional because the ST25R3916B needs to keep the CS pin low while performing a multivalue send option.

I appreciate any assistance or suggestions you can provide to help resolve this problem. if you need more information, do not hesitate to contact me.

 

thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

I would suggest to enable the ST25R_SELFTEST and ST25R_SELFTEST_TIMER switches during compilation. This provides communication tests and interrupt tests. Check then the return code of st25r3916Initialize

Also make sure to configure the Salea SPI decoder with CPOL=0 and CPHA=1 (if I am not wrong, IC identity register (3Fh) of the ST25R3916B contains 0x31 not 0x18 so the configuration is likely incorrect).

Make sure the nRF52840 SPI is properly configured as per ST25R3916B datasheet §4.3.3: 

"The ST25R39xxB have a standard serial peripheral interface with clock polarity of 0, a clock phase of 1, and an active low slave select signal. Communication starts with the MCU pulling BSS low. The MOSI pin is samples on the falling edge of SCLK, and the state of the MISO pin is updated on the rising edge of the SCLK signal. Data is transferred byte-wise, most significant bit first."

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Brian TIDAL
ST Employee

Hi,

I would suggest to enable the ST25R_SELFTEST and ST25R_SELFTEST_TIMER switches during compilation. This provides communication tests and interrupt tests. Check then the return code of st25r3916Initialize

Also make sure to configure the Salea SPI decoder with CPOL=0 and CPHA=1 (if I am not wrong, IC identity register (3Fh) of the ST25R3916B contains 0x31 not 0x18 so the configuration is likely incorrect).

Make sure the nRF52840 SPI is properly configured as per ST25R3916B datasheet §4.3.3: 

"The ST25R39xxB have a standard serial peripheral interface with clock polarity of 0, a clock phase of 1, and an active low slave select signal. Communication starts with the MCU pulling BSS low. The MOSI pin is samples on the falling edge of SCLK, and the state of the MISO pin is updated on the rising edge of the SCLK signal. Data is transferred byte-wise, most significant bit first."

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.