Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
bug
SPI
睿擎工业开发平台
睿擎工业开发平台--SPI使用和测四
发布于 2025-06-17 16:56:44 浏览:91
订阅该版
[tocm] # spi外设配置与使用 **测试时间2025-6-17** `本次测试是在我的认知范围内测试,如有不对,还请海涵,也希望官方早日修复` ## 1.配置PinMux  ## 2.编译烧录dtb > list device  ## 3.查看设备 命令行 ```c msh />spi Usage: spi
[options] available commands: list spi list [-v] init spi init -b
-d
-c
config spi config -d
-s
-m
-l
-b
trans spi trans -d
-v
-l
``` 挂载设备 >spi init -b spi0 -d flash -c 24 在设备列表中多了一个`flash`设备 ``` msh /> msh />spi init -b spi0 -d flash -c 11 msh />list device device type ref count -------------------------------- -------------------- ---------- flash SPI Device 0 rtc RTC 0 wdt1 WDT Device 0 wdt0 WDT Device 0 spi0 SPI Bus 0 otp Character Device 0 e1 Network Interface 1 e0 Network Interface 1 userdata MTD Device 1 rootfs MTD Device 0 app MTD Device 0 ``` 配置设备 > spi config -d flash -s 1000000 -m 2 -l lsb -b 8 ``` msh /> msh />spi config -d flash -s 1000000 -m 0 -l lsb -b 8 [spi] flash config success ``` 收发测试 >spi trans -d flash -v 12345678 -l 4 ```c msh /> msh /> msh /> msh />spi trans -d flash -v 12345678 -l 4 trans:4,[4E 4E 4E 4E] recv:4,[00 00 00 00] msh /> ```  ## 代码测试 1. 首先挂载spi设备 2. 配置设备参数 ```c /** * RT-Thread RuiChing * * COPYRIGHT (C) 2024-2025 Shanghai Real-Thread Electronic Technology Co., Ltd. * All rights reserved. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution. */ #include
#include
#include
#include
#define W25Q_SPI_DEVICE_NAME "flash" int main(void) { rt_kprintf("Hello, RT-Thread app\n"); rt_kprintf("cJson %s\n",cJSON_Version()); LOG_D("debug"); LOG_I("infomation"); LOG_W("waring"); LOG_E("error"); struct rt_spi_device *spi_dev_w25q; spi_dev_w25q = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device)); if (RT_EOK != rt_spi_bus_attach_device_cspin(spi_dev_w25q, W25Q_SPI_DEVICE_NAME, "spi0",25, RT_NULL)) { LOG_E("Failed to attach the spi device."); return -RT_ERROR; } struct rt_spi_configuration cfg; cfg.data_width = 8; cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_2 | RT_SPI_MSB; cfg.max_hz = 20 *1000; /* 20M */ if (RT_EOK !=rt_spi_configure(spi_dev_w25q, &cfg)) { LOG_E("rt_spi_configure error"); // return -RT_ERROR; } return 0; } /* * 程序清单:这是一个 SPI 设备使用例程 * 例程导出了 spi_w25q_sample 命令到控制终端 * 命令调用格式:spi_w25q_sample spi10 * 命令解释:命令第二个参数是要使用的SPI设备名称,为空则使用默认的SPI设备 * 程序功能:通过SPI设备读取 w25q 的 ID 数据 */ #include
static void spi_w25q_sample(int argc, char *argv[]) { struct rt_spi_device *spi_dev_w25q; char name[RT_NAME_MAX]; rt_uint8_t w25x_read_id = 0x90; rt_uint8_t id[5] = {0}; /* 查找 spi 设备获取设备句柄 */ spi_dev_w25q = (struct rt_spi_device *)rt_device_find(W25Q_SPI_DEVICE_NAME); if (!spi_dev_w25q) { rt_kprintf("spi sample run failed! can't find %s device!\n", name); } else { /* 方式1:使用 rt_spi_send_then_recv()发送命令读取ID */ // rt_spi_send_then_recv(spi_dev_w25q, &w25x_read_id, 1, id, 5); // rt_kprintf("use rt_spi_send_then_recv() read w25q ID is:%x%x\n", id[3], id[4]); /* 方式2:使用 rt_spi_transfer_message()发送命令读取ID */ struct rt_spi_message msg1, msg2; uint8_t send_buff[5]={1,2,3,4,5}; msg1.send_buf = &send_buff; msg1.recv_buf = RT_NULL; msg1.length = 5; msg1.cs_take = 1; msg1.cs_release = 0; msg1.next = &msg2; uint8_t send_buff2[5]={0xff,0xff,0xff,0xff,0xff}; msg2.send_buf = RT_NULL; // msg2.send_buf = send_buff2; msg2.recv_buf = id; msg2.length = 5; msg2.cs_take = 0; msg2.cs_release = 1; msg2.next = RT_NULL; rt_spi_transfer_message(spi_dev_w25q, &msg1); LOG_HEX("spi recv",16,id,5); // rt_kprintf("use rt_spi_transfer_message() read w25q ID is:%x%x\n", id[3], id[4]); } } /* 导出到 msh 命令列表中 */ MSH_CMD_EXPORT(spi_w25q_sample, spi w25q sample); ``` ## 测试发现的问题 1. `rt_spi_configure`API的返回值不对 2. spi 读取数据异常-当send_buff=RT_NULL时发现spi_clk没有发出波形 ### `rt_spi_configure`API的返回值不对  ### spi 读取数据异常 测试send_buff=RT_NULL  #### 当send_buff 不为空时spi_clk发出了波形  
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
chejia12
这家伙很懒,什么也没写!
文章
12
回答
1
被采纳
0
关注TA
发私信
相关文章
1
BBB的SPI驱动
2
求个SPI上挂两个或多个设备的使用例子
3
SPI设备有个bug
4
spi flash 的fatfs使用一段时间后读写文件出现故障
5
SPI驱动
6
请教rt_spi_configure函数理解
7
SPI FLASH挂载的问题
8
SPI-FLASH 文件系统 SPIFFS
9
求助一个完整的 spi flash 驱动
10
关于同时使用文件系统与SPI FLASH的问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
6
五分钟玩转RT-Thread新社区
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
Bootloader
AT
Hardfault
CAN总线
ART-Pi
FinSH
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
FAL
RTC
rt-smart
I2C_IIC
UART
cubemx
BSP
ESP8266
ota在线升级
WIZnet_W5500
PWM
packages_软件包
flash
freemodbus
GD32
潘多拉开发板_Pandora
ADC
keil_MDK
编译报错
定时器
flashDB
ulog
socket
rt_mq_消息队列_msg_queue
msh
中断
Debug
SFUD
C++_cpp
MicroPython
本月问答贡献
踩姑娘的小蘑菇
5
个答案
3
次被采纳
加缪
9
个答案
1
次被采纳
RTT_逍遥
5
个答案
1
次被采纳
用户名由3_15位
5
个答案
1
次被采纳
Ryan_CW
3
个答案
1
次被采纳
本月文章贡献
出出啊
1
篇文章
2
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
2
次点赞
crystal266
2
篇文章
1
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部