这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » NXP-MCXA153开发之三——移植硬件i2c驱动

共4条 1/1 1 跳转至

NXP-MCXA153开发之三——移植硬件i2c驱动

助工
2024-06-14 21:18:41     打赏

【目的】

移植NXP-MCXA153。目前官方提供的rtt-bsp驱动只提供了Pin与uart,其他的驱动还没有更新。我这次是移植基于i2c的硬件i2c驱动。

【源码下载】

下载****:https://gitee.com/rtthread/rt-thread

【移植过程】

1、编写drv_i2c驱动,驱动的主要源代码是复制mcxn下的drv_i2c.c

image.png

2、根据原官方的sdk,需要修改驱动中的baud、clock_attach_id、clock_div_name

struct lpc_i2c_bus lpc_obj[] =
{
#ifdef BSP_USING_I2C0
        {
            .I2C = LPI2C0,
            .baud = 1000000U,   //总线速度
            .clock_attach_id = kFRO12M_to_LPI2C0,  /*!< Attach FRO12M to LPI2C0.     */
            .clock_div_name = kCLOCK_DivLPI2C0,    /*!< LPI2C0     clock divider */
            .clock_src = kCLOCK_Fro12M,
            .name = "i2c0",
        },
#endif
};

3、在pin_mux.c中添加复位i2c0的代码:

		/* LPI2C0 peripheral is released from reset */
    RESET_ReleasePeripheralReset(kLPI2C0_RST_SHIFT_RSTn);

根据原理图,i2c0的SCL与SDA的引脚为P3_27,P3_28,添加io的配置代码:

		const port_pin_config_t port3_27_pin34_config = {/* Internal pull-up resistor is enabled */
                                                     kPORT_PullUp,
                                                     /* Low internal pull resistor value is selected. */
                                                     kPORT_LowPullResistor,
                                                     /* Fast slew rate is configured */
                                                     kPORT_FastSlewRate,
                                                     /* Passive input filter is disabled */
                                                     kPORT_PassiveFilterDisable,
                                                     /* Open drain output is enabled */
                                                     kPORT_OpenDrainEnable,
                                                     /* Low drive strength is configured */
                                                     kPORT_LowDriveStrength,
                                                     /* Normal drive strength is configured */
                                                     kPORT_NormalDriveStrength,
                                                     /* Pin is configured as LPI2C0_SCL */
                                                     kPORT_MuxAlt2,
                                                     /* Digital input enabled */
                                                     kPORT_InputBufferEnable,
                                                     /* Digital input is not inverted */
                                                     kPORT_InputNormal,
                                                     /* Pin Control Register fields [15:0] are not locked */
                                                     kPORT_UnlockRegister};
    /* PORT3_27 (pin 34) is configured as LPI2C0_SCL */
    PORT_SetPinConfig(PORT3, 27U, &port3_27_pin34_config);

    const port_pin_config_t port3_28_pin33_config = {/* Internal pull-up resistor is enabled */
                                                     kPORT_PullUp,
                                                     /* Low internal pull resistor value is selected. */
                                                     kPORT_LowPullResistor,
                                                     /* Fast slew rate is configured */
                                                     kPORT_FastSlewRate,
                                                     /* Passive input filter is disabled */
                                                     kPORT_PassiveFilterDisable,
                                                     /* Open drain output is enabled */
                                                     kPORT_OpenDrainEnable,
                                                     /* Low drive strength is configured */
                                                     kPORT_LowDriveStrength,
                                                     /* Normal drive strength is configured */
                                                     kPORT_NormalDriveStrength,
                                                     /* Pin is configured as LPI2C0_SDA */
                                                     kPORT_MuxAlt2,
                                                     /* Digital input enabled */
                                                     kPORT_InputBufferEnable,
                                                     /* Digital input is not inverted */
                                                     kPORT_InputNormal,
                                                     /* Pin Control Register fields [15:0] are not locked */
                                                     kPORT_UnlockRegister};
    /* PORT3_28 (pin 33) is configured as LPI2C0_SDA */
    PORT_SetPinConfig(PORT3, 28U, &port3_28_pin33_config);		

编译后顺利通过。

4、打开env图形配置工具,打开i2c0

image.png

5、使用 scons --target=mdk5生成工程。

6、编译下载到开发板,使用list device可以看到初始化好了i2c0

image.png

致此i2c0移植成功




关键词: 刘工爱评测之NXP      MCXA153     RT-thr    

专家
2024-06-14 22:22:38     打赏
2楼

感谢分享


专家
2024-06-15 09:56:24     打赏
3楼

谢谢分享!


专家
2024-06-15 19:37:21     打赏
4楼

感谢分享


共4条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]