|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2023-5-19 11:15:27
|
显示全部楼层
本帖最后由 hpdell 于 2023-5-19 11:36 编辑
i2c1 外设有上啦电阻 4.7k, 使能了 i2c1, i2c 总时钟启用了
i2c1 的 sda 管脚我配置为普通的 io 口模式,仅输出高低电平测试时,这个 sda 管脚的电平也是保持高电平不变的??
而 scl 管脚配置为 普通 io 口模式测试输出 高低电平 是可以正常 变化的,
/*
* TEXT BELOW IS USED AS SETTING FOR TOOLS *************************************
BOARD_InitPins:
- options: {callFromInitBoot: 'true', coreID: cm7, enableClock: 'true'}
- pin_list:
- {pin_num: M15, peripheral: LPUART1, signal: RXD, pin_signal: GPIO_AD_25, software_input_on: Disable, pull_up_down_config: Pull_Down, pull_keeper_select: Keeper,
open_drain: Disable, drive_strength: High, slew_rate: Slow}
- {pin_num: L13, peripheral: LPUART1, signal: TXD, pin_signal: GPIO_AD_24, software_input_on: Disable, pull_up_down_config: Pull_Down, pull_keeper_select: Keeper,
open_drain: Disable, drive_strength: High, slew_rate: Slow}
- {pin_num: R15, peripheral: LPI2C1, signal: SCL, pin_signal: GPIO_AD_08, software_input_on: Enable, pull_up_down_config: Pull_Down, pull_keeper_select: Keeper,
open_drain: Enable, drive_strength: Normal, slew_rate: Slow}
- {pin_num: R16, peripheral: LPI2C1, signal: SDA, pin_signal: GPIO_AD_09, software_input_on: Enable, pull_up_down_config: Pull_Down, pull_keeper_select: Keeper,
open_drain: Enable, drive_strength: Normal, slew_rate: Slow}
* BE CAREFUL MODIFYING THIS COMMENT - IT IS YAML SETTINGS FOR TOOLS ***********
*/
/* FUNCTION ************************************************************************************************************
*
* Function Name : BOARD_InitPins, assigned for the Cortex-M7F core.
* Description : Configures pin routing and optionally pin electrical features.
*
* END ****************************************************************************************************************/
void BOARD_InitPins(void) {
CLOCK_EnableClock(kCLOCK_Iomuxc); /* LPCG on: LPCG is ON. */
IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_08_LPI2C1_SCL, /* GPIO_AD_08 is configured as LPI2C1_SCL */
1U); /* Software Input On Field: Force input path of pad GPIO_AD_08 */
IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_09_LPI2C1_SDA, /* GPIO_AD_09 is configured as LPI2C1_SDA */
1U); /* Software Input On Field: Force input path of pad GPIO_AD_09 */
IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_24_LPUART1_TXD, /* GPIO_AD_24 is configured as LPUART1_TXD */
0U); /* Software Input On Field: Input Path is determined by functionality */
IOMUXC_SetPinMux(
IOMUXC_GPIO_AD_25_LPUART1_RXD, /* GPIO_AD_25 is configured as LPUART1_RXD */
0U); /* Software Input On Field: Input Path is determined by functionality */
IOMUXC_SetPinConfig(
IOMUXC_GPIO_AD_08_LPI2C1_SCL, /* GPIO_AD_08 PAD functional properties : */
0x10U); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: normal drive strength
Pull / Keep Select Field: Pull Disable, Highz
Pull Up / Down Config. Field: Weak pull down
Open Drain Field: Enabled
Domain write protection: Both cores are allowed
Domain write protection lock: Neither of DWP bits is locked */
IOMUXC_SetPinConfig(
IOMUXC_GPIO_AD_09_LPI2C1_SDA, /* GPIO_AD_09 PAD functional properties : */
0x10U); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: normal drive strength
Pull / Keep Select Field: Pull Disable, Highz
Pull Up / Down Config. Field: Weak pull down
Open Drain Field: Enabled
Domain write protection: Both cores are allowed
Domain write protection lock: Neither of DWP bits is locked */
IOMUXC_SetPinConfig(
IOMUXC_GPIO_AD_24_LPUART1_TXD, /* GPIO_AD_24 PAD functional properties : */
0x02U); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: high drive strength
Pull / Keep Select Field: Pull Disable, Highz
Pull Up / Down Config. Field: Weak pull down
Open Drain Field: Disabled
Domain write protection: Both cores are allowed
Domain write protection lock: Neither of DWP bits is locked */
IOMUXC_SetPinConfig(
IOMUXC_GPIO_AD_25_LPUART1_RXD, /* GPIO_AD_25 PAD functional properties : */
0x02U); /* Slew Rate Field: Slow Slew Rate
Drive Strength Field: high drive strength
Pull / Keep Select Field: Pull Disable, Highz
Pull Up / Down Config. Field: Weak pull down
Open Drain Field: Disabled
Domain write protection: Both cores are allowed
Domain write protection lock: Neither of DWP bits is locked */
}
/****************************************************************************************************
****************************************************************************************************/
#define LPI2C_CLOCK_FREQUENCY (CLOCK_GetRootClockFreq(kCLOCK_Root_Lpi2c1))
#define LPI2C_BAUDRATE (uint32_t)(400 * 1000U) // 400KHz
void bsp_init_bus_i2c1(void)
{
CLOCK_EnableClock(kCLOCK_Iomuxc); /* LPCG on: LPCG is ON. */
uint32_t clockHz = LPI2C_CLOCK_FREQUENCY;
lpi2c_master_config_t masterConfig;
// clock_root_config_t rootCfg = {0};
// rootCfg.mux = kCLOCK_LPI2C1_ClockRoot_MuxOsc24MOut;
// rootCfg.div = 1;
// CLOCK_SetRootClock(kCLOCK_Root_Lpi2c1, &rootCfg);
BOARD_InitPinsI2C1();
/*
* masterConfig.debugEnable = false;
* masterConfig.ignoreAck = false;
* masterConfig.pinConfig = kLPI2C_2PinOpenDrain;
* masterConfig.baudRate_Hz = 100000U;
* masterConfig.busIdleTimeout_ns = 0;
* masterConfig.pinLowTimeout_ns = 0;
* masterConfig.sdaGlitchFilterWidth_ns = 0;
* masterConfig.sclGlitchFilterWidth_ns = 0;
*/
LPI2C_MasterGetDefaultConfig(&masterConfig);
/* Change the default baudrate configuration */
masterConfig.baudRate_Hz = LPI2C_BAUDRATE;
/* Initialize the LPI2C master peripheral */
LPI2C_MasterInit(iic_index[IIC_1], &masterConfig, LPI2C_CLOCK_FREQUENCY); // 第一次初始化便于打开时钟
EEPROM_INFO("bsp_init_bus_i2c1 clockHz = %d\r\n", clockHz);
}
|
|