2025-11-24 11:13 PM
Hi
I am evaluating NFC function on your STEVAL 25R3916B board, but I would like to see how it works with the I2C interface. Currently, the default configuration is SPI.
I have downloaded STM32CubeIDE and STEVAL-25R3916B_V2.1.0 project code, but am not sure where should I put this definition "RFAL_USE_I2C", could you help me check where this macro needs to be placed?
Thanks
Leo
Solved! Go to Solution.
2025-12-11 11:41 PM
Hi Rene
After reintergate EXTI1_15, it can work normally through I2C interface.
Thanks for your help
Leo
2025-11-25 8:10 AM - edited 2025-11-26 5:24 AM
Hi,
for I2C support, some HW modification on the STEVAL 25R3916B are needed:
I2C pullup resistors are present on both the daugther board and the mother board. It might be needed to remove some of them.
On firmware side:
Rgds
BT
2025-11-25 11:35 PM
Hi BT
Thanks for your reply, in terms of FW, there are some errror occured after added the changes you suggested.
In your FW, hi2c2 only can be used in st25_discovery.c, and USE_NFCTAG needs to be defined for enabling hi2c2 related code.
could you help to check? or the FW I am using is not the latest one?
Thanks
Leo
2025-11-26 5:36 AM
Hi Leo,
there was a typo in my previous answer: replace the spiInit(&hspi1); in the main by i2cInit(&hi2c2);
The I2C2 has to be initialized. This can be achieved by adding the proper MX_I2C2_Init() function inside the main.c file or by calling the BSP in the st25_discovery.c with the relevant define (in that case add i2cInit(&hi2c2); before returning from STM32_I2C2_Init).
Also, make sure to enable the I2C2 even and I2C2 error interrupts.
Rgds
BT
2025-11-28 12:41 AM
Hi Brian,
I also need to define "USE_NFCTAG" for enabling STM32_I2C2_Init and I2C2 related functions, but some errors occured after I defined USE_NFCTAG in define symbols.
Could you help to run at your PC? I don't know if I am lacking some source files or not.
Thanks,
Leo
2025-11-28 3:29 AM - edited 2025-11-28 3:32 AM
Hi @LeoWu ,
This STEVAL motherboard can be connected to various daughter boards, and the I²C2 BSP driver is more intended for NFC Tags. It's possible to use this GPIO and I²C initializations with some adaptation, but I think it will be easier to define yours.
Let's try the following:
Remove the USE_NFCTAG define.
Add in stm32l4xx_hal_msp.c :
/**
* @brief I2C MSP Initialization
* This function configures the hardware resources used in this example:
* - Peripheral's clock enable
* - Peripheral's GPIO Configuration
* - DMA configuration for transmission request by peripheral
* - NVIC configuration for DMA interrupt request enable
* @param None
* @return None
*/
void HAL_I2C_MspInit( I2C_HandleTypeDef* hi2c )
{
GPIO_InitTypeDef gpio_initstruct;
/* Enable I2Cx clock */
__HAL_RCC_I2C2_CLK_ENABLE( );
/* Reset I2Cx */
__HAL_RCC_I2C2_FORCE_RESET( );
__HAL_RCC_I2C2_RELEASE_RESET( );
/* Enable GPIO clock */
__HAL_RCC_GPIOB_CLK_ENABLE( );
/* I2C SCL/SDA GPIO pin configuration */
gpio_initstruct.Pin = GPIO_PIN_10 | GPIO_PIN_11;
gpio_initstruct.Mode = GPIO_MODE_AF_OD;
gpio_initstruct.Pull = GPIO_NOPULL;
gpio_initstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio_initstruct.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init( GPIOB, &gpio_initstruct );
HAL_NVIC_SetPriority(I2C2_EV_IRQn, 5, 5);
HAL_NVIC_EnableIRQ(I2C2_EV_IRQn);
}
/**
* @brief I2C MSP DeInitialization
* @param None
* @return None
*/
void HAL_I2C_MspDeInit( I2C_HandleTypeDef* hi2c )
{
HAL_NVIC_DisableIRQ(I2C2_EV_IRQn);
HAL_GPIO_DeInit( GPIOB, GPIO_PIN_10 );
HAL_GPIO_DeInit( GPIOB, GPIO_PIN_11 );
/* Disable I2Cx clock */
__HAL_RCC_I2C2_CLK_DISABLE( );
}add in main.c :
#include "i2c.h"
...
I2C_HandleTypeDef hi2c2;
static void MX_I2C2_Init( void );
...
int main( void )
{
...
MX_I2C2_Init();//this replaces the spi init call
i2cInit(&hi2c2);
...
}
...
static void SystemClock_Config_st25r3916(void)
{
...
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C2;
PeriphClkInit.I2c2ClockSelection = RCC_I2C2CLKSOURCE_SYSCLK;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
while(1);
}
...
}
...
/**
* @brief Configures I2C interface.
* @param None
* @retval HAL status
*/
static void MX_I2C2_Init( void )
{
HAL_StatusTypeDef ret_val = HAL_OK;
if( HAL_I2C_GetState(&hi2c2) == HAL_I2C_STATE_RESET )
{
/* I2C2 peripheral configuration */
hi2c2.Instance = I2C2;
hi2c2.Init.Timing = 0x00F12981;
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
/* Init the I2C */
ret_val = HAL_I2C_Init( &hi2c2 );
}
}I hope this can help you.
Kind Regards.
2025-11-30 9:25 PM
Hi Rene
Thanks for help, now FW can be compiled and programmed to the board sucessfully.
but now the program is stuck at "InitializeRFAL"function.
I checked I2C waveform, it looks like SCL pin will latch sometime, as below, do you have any idea?
Thanks,
Leo
2025-12-01 4:21 AM
Hi @LeoWu,
One thing you can check first is the V_RF configuration, it needs to be aligned with the S100 switch position on the daughter board and the USB connector.
S100 set to 5V position:
- USB mini cable connected -> JP14 must link V_RF to VUSB_ST_LINK (4, 2).
- USB micro cable connected -> JP14 must link V_RF to VUSB_MCU (3, 2).
S100 set to position 3V:
- USB mini cable connected -> JP14 must link V_RF to VUSB_MCU (3, 2).
- USB micro cable connected -> JP14 must link V_RF to VUSB_ST_LINK (4, 2).
Let us know if that change something in your side.
Kind Regards.
2025-12-01 6:26 PM
Hi Rene
I have tried all of V_RF configuration, the result still remain the same, SCL latched during InitializeRFAL.
I will contuine to check where is the issue, but I also need your help to fix this issue as well.
Thanls,
Leo
2025-12-03 1:53 AM
Hi @LeoWu,
Is it possible for you to connect only the necessary signals to the daughter board. This would reduce it to I²C bus and power supply, avoiding any conflicts with other pins. On my side, I have tested the STEVAL board with I²C and it works correctly.
Kind regards.