cancel
Showing results for 
Search instead for 
Did you mean: 

How to switch to I2C mode on STEVAL 25R3916B board?

LeoWu
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Rene

After reintergate EXTI1_15, it can work normally through I2C interface.

 

Thanks for your help

Leo

View solution in original post

21 REPLIES 21
Brian TIDAL
ST Employee

Hi,

for I2C support, some HW modification on the STEVAL 25R3916B are needed:

  • I2C_EN: open J201 and close J200
  • SCL: open J205 and close J203
  • SDA: open J204, close J202

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:

  • RFAL_USE_I2C compilation switch has to be defined (project properties / C-C++ build /MCU GCC Compiler / Preprocessor / Define symbols (-D))
  • replace the spi.c by the i2c.c file in the project
  • replace the spiInit(&hspi1); in the main by i2cInit(&hi2c2);
  • Initialize the I2C2 

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.

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

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

 

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.

 

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.

LeoWu_1-1764319148305.png

Thanks,

Leo

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.

 
 

 

 

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?

LeoWu_0-1764566574772.png

LeoWu_1-1764566588873.png

LeoWu_2-1764566605008.png

Thanks,

Leo

 

 

 

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).

             ReneLenerve_0-1764587119774.png 

- USB micro cable connected -> JP14 must link V_RF to VUSB_MCU (3, 2).

            ReneLenerve_1-1764591559551.png

 

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.

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

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.