希望能把I2C的频率调低到10kHZ左右,有人知道应该怎么配置吗
官方库里的I2C波特率初始化代码,主要是根据结构体stc_i2c_init_t的三个参数【u32ClockDiv】【u32Baudrate】【u32SclTime】三个参数进行配置static int32_t Master_Initialize(void)
{
int32_t i32Ret;
stc_i2c_init_t stcI2cInit;
float32_t fErr;
I2C_DeInit(I2C_UNIT);
(void)I2C_StructInit(&stcI2cInit);
stcI2cInit.u32ClockDiv = I2C_CLK_DIV128;
stcI2cInit.u32Baudrate = I2C_BAUDRATE;
stcI2cInit.u32SclTime = 1UL;
i32Ret = I2C_Init(I2C_UNIT, &stcI2cInit, &fErr);
I2C_BusWaitCmd(I2C_UNIT, ENABLE);
return i32Ret;
}
在配置函数的注释里有说这几个参数的关系和计算方法,但还是看不太懂
下面是I2C_BaudrateConfig函数的注释,说要先计算DIV,计算方法是div = (I2cSrcClk/Baudrate/(Imme+2*Dnfsum+SclTime)
这里面的SCLTIME =(SCL rising time + SCL falling time)/period of i2c clock ,后面的这个I2C clock period是什么,指的是I2C Source Clock【PCLK3】的周期吗?还是说指的是其他?
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Set the baudrate for I2C peripheral.
* @param [in] I2Cx Pointer to I2C instance register base.
* This parameter can be a value of the following:
* [url=home.php?mod=space&uid=2817080]@ARG[/url] CM_I2C or CM_I2Cx: I2C instance register base.
* @param [in] pstcI2cInit Pointer to I2C config structure [url=home.php?mod=space&uid=144993]@ref[/url] stc_i2c_init_t
* @arg pstcI2cInit->u32ClockDiv: Division of i2c source clock, reference as:
* step1: calculate div = (I2cSrcClk/Baudrate/(Imme+2*Dnfsum+SclTime)
* I2cSrcClk -- I2c source clock
* Baudrate -- baudrate of i2c
* SclTime -- =(SCL rising time + SCL falling time)/period of i2c clock
* according to i2c bus hardware parameter.
* Dnfsum -- 0 if digital filter off;
* Filter capacity if digital filter on(1 ~ 4)
* Imme -- An Immediate data, 68
* step2: chose a division item which is similar and bigger than div from @ref I2C_Clock_Division.
* @arg pstcI2cInit->u32Baudrate : Baudrate configuration
* @arg pstcI2cInit->u32SclTime : Indicate SCL pin rising and falling
* time, should be number of T(i2c clock period time)
* @param [out] pf32Error Baudrate error
* @retval int32_t
* - LL_OK: Success
* - LL_ERR_TIMEOUT: Failed
* - LL_ERR_INVD_PARAM: Parameter error
*/
|