2024-10-04 07:48 AM
We use STM32F103C8T6 as the main control chip, ST25DV64KC to do the slave and ST25R3911B NFC communication project process, we found that we are very confused about the initialization of ANT7-T-ST25DV64KC, we have been initializing failure in the process of configuring hardware I2C, and through the manual we learned that we need to initialize the FTM mailbox first, we are very confused about the steps to initialize the mailbox, Hopefully it will help us out, and we're using a standard library to write code. Every time I debug, I keep getting stuck in while (!) I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)); this line.
#include "stm32f10x.h" // Device header
#include "stm32f10x_i2c.h"
#include "delay.h"
#include "serial.h"
#include "stm32f10x_flash.h"
#define ANT7_T_ST25DV64KC_ADDRESS 0x53
void SystemClock_Config(void)
{
RCC_HSICmd(ENABLE);
while (RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
FLASH_SetLatency(FLASH_Latency_0);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
}
void ST25DV_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
NVIC_InitTypeDef NVIC_InitStruct;
SystemClock_Config();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_ClockSpeed = 100000;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_Init(I2C2, &I2C_InitStructure);
I2C_Cmd(I2C2, ENABLE);
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn | EXTI3_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void ANT7_T_ST25DV64KC_WriteReg(uint16_t RegAddress, uint8_t Data)
{
I2C_GenerateSTART(I2C2, ENABLE);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2C2, ANT7_T_ST25DV64KC_ADDRESS, I2C_Direction_Transmitter);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C2, (uint8_t)(RegAddress >> 8));
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTING));
I2C_SendData(I2C2, (uint8_t)(RegAddress & 0xFF));
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTING));
I2C_SendData(I2C2, Data);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTOP(I2C2, ENABLE);
}
uint8_t ANT7_T_ST25DV64KC_ReadReg(uint16_t RegAddress)
{
uint8_t Data;
I2C_GenerateSTART(I2C2, ENABLE);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2C2, ANT7_T_ST25DV64KC_ADDRESS, I2C_Direction_Transmitter);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C2, (uint8_t)(RegAddress >> 8));
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_SendData(I2C2, (uint8_t)(RegAddress & 0xFF));
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTART(I2C2, ENABLE);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2C2, ANT7_T_ST25DV64KC_ADDRESS, I2C_Direction_Receiver);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
I2C_AcknowledgeConfig(I2C2, DISABLE);
I2C_GenerateSTOP(I2C2, ENABLE);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED));
Data = I2C_ReceiveData(I2C2);
I2C_AcknowledgeConfig(I2C2, ENABLE);
return Data;
}
2024-10-22 07:44 AM
Hello Sjek,
Looking at your post, it seems your issue is not due to the mailbox nor to the FTM but to the way you configure and initialize the I2C.
I have some few questions and comments on your configuration.
Is the STM32F103C8T6 you are using mounted on your own PCB ? or are you using an ST board embedding this chip, if so could you please provide the reference of the board ?
Another point, many of the problems reported about the I2C are related to missing pull up resistors, could you please ensure the I2C pull ups have been soldered on your board ?
Concerning the SW part.
The ST CubeMx tool helps to configure and initialize the devices (GPIO, I2C, ...) connected to your chip, I warmly recommend you generate the code related to your initialization and configuration phase using this tool.
Moreover, I do not know the I2C API you are using, I recommend you are using the I2C API provided with the BSP used on your board.
Concerning the FTM itself,
In few words, the FTM is initialized with the following sequence:
1 - Present the password.
2 - Authorize FTM mailbox by writing the value 0x01 to register 0x000D.
3 - Enable FTM mode by writing register MB_CTRL_Dyn bit 0 (MB_EN) to 1 (address 0x2006).
4 - Write to the mailbox via I2C starting from address 0x2008.
5 - Disable FTM mode by writing 0x00 to register 0x000D.
some few threads have already addressed the way the FTM is enabled:
Solved: Re: STM32 ST25DV library - STMicroelectronics Community
Solved: ST25DV64KC FTM issue - STMicroelectronics Community
Solved: Re: Write on Mailbox via Android APP (ST25DV64KC) - STMicroelectronics Community
I warmly recommend you have a look to all these.
hoping this helps,
BR,
Cedric.