/**
* [url=home.php?mod=space&uid=555622]@prototype[/url] I2C_InitHardwr(void)
*
* @param[in] void
* @return void
*
* [url=home.php?mod=space&uid=247401]@brief[/url] Initalize I2C module.
* 初始化I2C模块.
*/
void I2C_InitHardwr(void)
{
I2C_ConfigType i2cConfig = {0};
GPIO_SetFunc(I2C1_SDA_PIN, GPIO_FUNC_1);
GPIO_SetFunc(I2C1_SCL_PIN, GPIO_FUNC_1);
i2cConfig.setting.master = ENABLE;
i2cConfig.setting.intEn = ENABLE;
i2cConfig.setting.i2cEn = ENABLE;
i2cConfig.setting.syncEn = ENABLE;
i2cConfig.setting.nackIntEn = ENABLE;
i2cConfig.setting.dmaRxEn = ENABLE;
i2cConfig.setting.dmaTxEn = ENABLE;
i2cConfig.addr1 = I2C_SLAVE_ADDR;
#if (I2C_STAND_MODE)//100K波特率
i2cConfig.sampleCNT = 11;//speed = APBclk/((sampleCnt+1)*(stepCNT+1)*2)
i2cConfig.stepCNT = 19;
#else //400K波特率
i2cConfig.sampleCNT = 11;//speed = APBclk/((sampleCnt+1)*(stepCNT+1)*2)
i2cConfig.stepCNT = 4;
#endif
I2C_SetEventCallback(I2C1, I2C_DMACallback);
I2C_Initialize(I2C1, &i2cConfig);
}
之前一直使用IO模拟的
看例程有专门的硬件配置
感觉不错,
大家品评下
|