cancel
Showing results for 
Search instead for 
Did you mean: 

How to initialize a mailbox

sjek
Associate

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;
}

 

0 REPLIES 0