查看: 1604|回复: 0

[原创] 【NXP共享】LPC54110+测试SPI外设接口

[复制链接]
  • TA的每日心情
    开心
    昨天 09:37
  • 签到天数: 1147 天

    连续签到: 41 天

    [LV.10]以坛为家III

    28

    主题

    4361

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    5974
    最后登录
    2025-9-12
    发表于 2024-7-8 21:39:31 | 显示全部楼层 |阅读模式
    本帖最后由 suncat0504 于 2024-7-8 23:12 编辑

    为了后面能正常SPI接口,本次实验测试LPC54114开发板的SPI外设。先看下这块开发板的电路图和元件布局图:

    图片1.png
    原理图:
    图片2.png
    图片3.png

    有热心伙伴提供了资料,也从论坛里找到很多相关的资料。但看了资料后,总感觉有写出入,不完全匹配。不管怎么说,先根据PCB板子上的印字提示,测测看吧。


    在CN6上提供的排针接口中,按照印制板上的注释,有如下配置:

    PIO0.11 - SCLK
    PIO0.13 - MISO
    PIO0.12 - MOSI
    PIO0.14 - SS

    为了验证接口与单片机的实际输出是否一致,先以模拟方式,使用流水灯模式依次翻转输出。使用之前连接了TF显示屏的例程,在那个例程基础上进行改造。

    初始化部分的代码:
    1. void BOARD_InitPins(void) {
    2.     /* Enables the clock for the IOCON block. 0 = Disable; 1 = Enable.: 0x01u */
    3.     CLOCK_EnableClock(kCLOCK_Iocon);
    4.     /* Enables the clock for the GPIO1 module */
    5.     CLOCK_EnableClock(kCLOCK_Gpio1);          // 允许Port1时钟
    6.     CLOCK_EnableClock(kCLOCK_Gpio0);          // 允许Port0时钟

    7.     gpio_pin_config_t LED_GREEN_config = {
    8.         .pinDirection = kGPIO_DigitalOutput,
    9.         .outputLogic = 0U
    10.     };
    11.     /* Initialize GPIO functionality on pin PIO1_10 (pin 30)  */
    12.     //GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_PORT, BOARD_LED_GREEN_PIN, &LED_GREEN_config);
    13.     //GPIO_PinInit(BOARD_LED_GREEN_GPIO, PORT01, PIN01_0 | PIN01_1 | PIN01_2 | PIN01_3 | PIN01_4, &LED_GREEN_config);
    14.    
    15.     GPIO_PinInit(GPIO, PORT01, PIN01_0, &LED_GREEN_config);
    16.     GPIO_PinInit(GPIO, PORT01, PIN01_1, &LED_GREEN_config);
    17.     GPIO_PinInit(GPIO, PORT01, PIN01_2, &LED_GREEN_config);
    18.     GPIO_PinInit(GPIO, PORT01, PIN01_3, &LED_GREEN_config);
    19.     GPIO_PinInit(GPIO, PORT01, PIN01_4, &LED_GREEN_config);
    20.     GPIO_PinInit(GPIO, PORT01, PIN01_5, &LED_GREEN_config);

    21.     IOCON->PIO[0][15] = ((IOCON->PIO[0][15] &
    22.                           /* Mask bits to zero which are setting */
    23.                           (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_MODE_MASK | IOCON_PIO_DIGIMODE_MASK)))

    24.                          /* Selects pin function.
    25.                           * : PORT015 (pin 50) is configured as SWO. */
    26.                          | IOCON_PIO_FUNC(PIO015_FUNC_ALT2)

    27.                          /* Selects function mode (on-chip pull-up/pull-down resistor control).
    28.                           * : Inactive.
    29.                           * Inactive (no pull-down/pull-up resistor enabled). */
    30.                          | IOCON_PIO_MODE(PIO015_MODE_INACTIVE)

    31.                          /* Select Analog/Digital mode.
    32.                           * : Digital mode. */
    33.                          | IOCON_PIO_DIGIMODE(PIO015_DIGIMODE_DIGITAL));

    34.     const uint32_t LED_GREEN = (/* Pin is configured as PIO1_10 */
    35.                                 IOCON_PIO_FUNC0 |
    36.                                 /* Selects pull-up function */
    37.                                 IOCON_PIO_MODE_PULLUP |
    38.                                 /* Input function is not inverted */
    39.                                 IOCON_PIO_INV_DI |
    40.                                 /* Enables digital function */
    41.                                 IOCON_PIO_DIGITAL_EN |
    42.                                 /* Input filter disabled */
    43.                                 IOCON_PIO_INPFILT_OFF |
    44.                                 /* Standard mode, output slew rate control is enabled */
    45.                                 IOCON_PIO_SLEW_STANDARD |
    46.                                 /* Open drain is disabled */
    47.                                 IOCON_PIO_OPENDRAIN_DI);
    48.    
    49.     /* PORT1 PIN10 (coords: 30) is configured as PIO1_10 */
    50.     IOCON_PinMuxSet(IOCON, BOARD_LED_GREEN_PORT, BOARD_LED_GREEN_PIN, LED_GREEN);


    51.     // CN6的SPI输出口
    52.     GPIO_PinInit(GPIO, PORT00, PIN00_11, &LED_GREEN_config);     // SCLK
    53.     GPIO_PinInit(GPIO, PORT00, PIN00_12, &LED_GREEN_config);     // MOSI
    54.     GPIO_PinInit(GPIO, PORT00, PIN00_13, &LED_GREEN_config);     // MISO
    55.     GPIO_PinInit(GPIO, PORT00, PIN00_14, &LED_GREEN_config);     // SS
    56. }
    复制代码
    主程序部分:
    1. <blockquote>uint32_t pins[] = {PIN00_11, PIN00_12, PIN00_13, PIN00_14};
    复制代码


    编译程序,下载运行:
    test - 副本.gif

    是由视频转的,因为图像尺寸的缘故,转化的图片比较小。但可以看到4个LED依次点亮和灭掉。说明PCB上标记的端口没问题。


    哎...今天够累的,签到来了~
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-9-13 04:08 , Processed in 0.086565 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表