硬汉嵌入式论坛

 找回密码
 立即注册
查看: 67|回复: 1
收起左侧

[技术讨论] nRF54L15初始化SPI

[复制链接]

6

主题

8

回帖

26

积分

新手上路

积分
26
发表于 7 天前 | 显示全部楼层 |阅读模式
【NCS随笔】
NCS使用了Zyphyr操作系统,以及设备树的概念,所以有许多客户对于不了解,今天copy一个SPI初始化的例程,给读者看

一、Nordic官方课程

官方已经写了一个SPI的课程,写的挺详细的可以,也可以看这个课程
https://academy.nordicsemi.com/c ... opic/exercise-1-10/

二、 配置宏定义

在 prj.conf 使能SPI
`CONFIG_SPI=y`

三、添加overlay

新建一个nrf5l15dk_nrf54l15_cpuapp.overlay

添加需要的内容

```
&pinctrl {
        spi22_default_alt: spi22_default_alt {
                group1 {
                        psels = < NRF_PSEL(SPIM_SCK, 1, 12) >,
                                <  NRF_PSEL(SPIM_MISO, 1, 10) >,
                                <  NRF_PSEL(SPIM_MOSI, 1, 8) >;
                };
        };

        spi22_sleep_alt: spi22_sleep_alt {
                group1 {
                        psels = < NRF_PSEL(SPIM_SCK, 1, 12) >,
                        <  NRF_PSEL(SPIM_MISO, 1, 10) >,
                        <  NRF_PSEL(SPIM_MOSI, 1, 8) >;
                        low-power-enable;
                };
        };

};

&gpio2 {
        status = "okay";
};

&spi22 {
        status = "okay";
        pinctrl-0 = < &spi22_default_alt >;
        pinctrl-1 = < &spi22_sleep_alt >;
        pinctrl-names = "default", "sleep";
        overrun-character = < 0x00 >;
        cs-gpios = < &gpio1 14 GPIO_ACTIVE_LOW >;
        easydma-maxcnt-bits = < 0x400 >;
        dut_spi_dt: test-spi-dev@0 {
                compatible = "vnd,spi-device";
                reg = < 0 >;
                spi-max-frequency = < 8000000 >;
        };
};
```

四、main函数

```
/* SPI 描述结构体 */
#define SPI_OP        (SPI_WORD_SET(8)|SPI_TRANSFER_MSB)
#define SPIM_OP         (SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB |SPI_WORD_SET(8))
static struct spi_dt_spec spim = SPI_DT_SPEC_GET(DT_NODELABEL(dut_spi_dt), SPIM_OP, 0);





/**
* @brief st7735发送命令
*/
static void st7735_send_command(uint8_t command)
{
   // TFT_DC_COMMAND;
    struct spi_buf tx_spi_buf = { .buf = (void *)&command, .len = 1 };
    struct spi_buf_set tx_spi_buf_set = {.buffers = &tx_spi_buf, .count = 1 };
    int ret = spi_write_dt(&spim, &tx_spi_buf_set);
    if (ret < 0) {
        LOG_ERR("SPI write data failed: %d", ret);
    }
}

int main(void)
{
        printf("Hello World! %sn", CONFIG_BOARD_TARGET);

        /* 检查设备是否准备好 */
    if (!spi_is_ready_dt(&spim)) {
        LOG_ERR("spi is not ready");
        return false;
    }

        while (1)
        {
                st7735_send_command(0x55);
                k_sleep(K_MSEC(500));
                printf("mr_st7735_send_command:0x55n");
        }
       
        return 0;
}
```

五、逻辑分析仪显示数据没有问题



六、使用nRFX库

还有一个使用旧的nRF52_SDK库的办法,可以绕过zephyr的设备树和API,其实zephyr底层也是调用nRF库

七、宏配置

CONFIG_NRFX_SPIM22=y

```
&spi22 {
    status = "okay";
    compatible = "nordic,nrf-spim";
    pinctrl-0 = < &spi_dummy >;
};
```

最后一如既往的到了臭不要脸环节,作为一名精通Nordic硬件设计和软件开发的FAE,你的点赞、收藏和评论是对我最大的支持,有问题多多指教,如果有需要Nordic开发板、Nordic的芯片以及Nordic技术支持的可以在个人资料获取我的联系方式,感谢读者支持!

回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
116742
QQ
发表于 6 天前 | 显示全部楼层
谢谢分享。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-7-4 14:59 , Processed in 0.220284 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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