cancel
Showing results for 
Search instead for 
Did you mean: 

How to Initialize the ANT7-T-ST25DV64KC Using the Standard Library

sjek
Associate II

我目前正在从事一个需要使用 STM32F103C8T6 微控制器和标准库进行代码编写的项目。在此过程中,我遇到了 ANT7-T-ST25DV64KC 芯片初始化的问题,一直卡在“while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));在此步骤中,我还对读取 I2C_SS0_Dyn 数据感到困惑。读出的数据永远是我在 read 函数中写的 slave 地址,有时读出的数据会增加 1。

这是我的代码

 

无效 ST25DV_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
NVIC_InitTypeDef NVIC_InitStruct;
 
SystemClock_Config();
 
 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,启用);
 
 
 
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,启用);
 
I2C_InitStructure.I2C_模式 = I2C_Mode_I2C;
I2C_InitStructure.I2C_ClockSpeed = 100000;
I2C_InitStructure.I2C_占空比 = 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, 启用);
 
 
 
 
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn |EXTI3_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = 启用;
NVIC_Init(&NVIC_InitStruct);
}
 
 
void ANT7_T_ST25DV64KC_WriteReg(uint16_t RegAddress, uint8_t Data)
{
I2C_GenerateSTART(I2C2, 启用);
    
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,数据);
    
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
    
I2C_GenerateSTOP(I2C2, 启用);
}
 
uint8_t ANT7_T_ST25DV64KC_ReadReg(uint16_t RegAddress)
{
uint8_t 数据;
 
I2C_GenerateSTART(I2C2, 启用);
    
    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;
}
This discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION

Accepted Solutions
Cedric Dalban
ST Employee

Hello Sjek,

this thread seems similar to the following thread:

How to initialize a mailbox - STMicroelectronics Community

please see this other thread.

thanks and regards,

Cedric.

View solution in original post

4 REPLIES 4
sjek
Associate II

I'm currently working on a project that requires code writing using STM32F103C8T6 microcontrollers and standard libraries.

During this process, I ran into an issue with ANT7-T-ST25DV64KC chip initialization and kept getting stuck in "while (!"). I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)); In this step, I was also confused about reading I2C_SS0_Dyn data. The read data is always the slave address I wrote in the read function, and sometimes the read data will increase by 1.

Here's my code

 

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

 

Please see the Posting Tips for how to properly post source code:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

I've edited the post for you.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

ty

Cedric Dalban
ST Employee

Hello Sjek,

this thread seems similar to the following thread:

How to initialize a mailbox - STMicroelectronics Community

please see this other thread.

thanks and regards,

Cedric.