2015-07-06 05:39 AM
I want chage stm32f0 source to stm32f4.
All parameter and function was changed.
But stm32f4_i2c.h doesn't have TransferHandling function.
The TransferHandling function.
How do I change the TransferHandling function in stm32f4?
Below is the source switched to stm32f4.
(MYAHRS is gyro sensor by i2c)
//I2C initialize function
void I2C2_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE );
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2);
// GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2);
//PB10 : SCL //PB11 : SDA
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2);
// I2C_DeInit(I2C2);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //Open Drain
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinLockConfig(GPIOC, GPIO_Pin_0);
GPIO_SetBits(GPIOC, GPIO_Pin_0);
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_OwnAddress1 = 0x22;
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStruct.I2C_ClockSpeed = 100000;//0x10420f13;//I2C_Timing
I2C_Init(I2C2, &I2C_InitStruct);
I2C_Cmd(I2C2, ENABLE );
}
//I2C Receive funtion
void MyAHRS_receive(uint8_t address, uint8_t n, uint8_t* msg)
{
if(n == 0)
{
ServerProtocol_errMsg(''MyAHRS Message Length Error\n'');
} else
{
while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
// write register address
//I2C_TransferHandling(I2C2, (MYAHRS_I2C_ADDRESS<<1), 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
I2C_GenerateSTART(I2C2, ENABLE);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2C2, (MYAHRS_I2C_ADDRESS<<1), I2C_Direction_Transmitter);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C2, address);
///while(!I2C_GetFlagStatus(I2C2, I2C_FLAG_BTF));
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED));
// read data
//I2C_TransferHandling(I2C2, (MYAHRS_I2C_ADDRESS<<1)+1, n, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
I2C_GenerateSTART(I2C2, ENABLE);
I2C_Send7bitAddress(I2C2, (MYAHRS_I2C_ADDRESS<<1)+1, I2C_Direction_Receiver);
//I2C_GenerateSTOP(I2C2, ENABLE);
for(int i = 0; i<n ; i++)
{
while(I2C_GetFlagStatus(I2C2,I2C_FLAG_RXNE) == RESET);
msg[i] = I2C_ReceiveData(I2C2);
}
}
}
#discovery #stm32f4 #i2c
2015-07-06 06:38 AM
Could you review the function source and port that?