【国民技术N32G457评测】RT_Thread Studuio SPI发送数据失败
本帖最后由 lugl4313820 于 2022-2-6 23:14 编辑<p><a href="https://bbs.eeworld.com.cn/thread-1193300-1-1.html">【国民技术N32G457评测】SPI收发评测 - 国产芯片交流 - 电子工程世界-论坛 (eeworld.com.cn)</a></p>
<p>用MDK测试SPI收发通过,晚上用RT_Thread Studio 来创建SPI发送数据。</p>
<p>挂载spi10设备成功后,用rt_spi_send发送数据,用逻辑分析仪采集数据,发现在NSS没有作用。时钟如下:</p>
<p> </p>
<p> 查看设备是有的:</p>
<p> 测试的代码为:</p>
<pre>
<code>#include "rtthread.h"
#include "drv_gpio.h"
#include <rtdevice.h>
#include "n32g45x_rcc.h"
#include "n32g45x.h"
#define SPI1_BUS_NAME "spi1"
#define SPI1__DEVICE_NAME "spi10"
#define SPI1_NCS_PIN 29
/*
N32G45XV SPI1 default GPIOs
PA4------SPI0NSS
PA5------SPI0SCK
PA6------SPI0MISO
PA7------SPI0MOSI
*/
struct n32_hw_spi_cs
{
rt_uint32_t pin;
};
int rt_hw_spi_config(void)
{
static struct rt_spi_device spi_dev_1;
static struct n32_hw_spi_csspi_cs1;
rt_err_t res;
spi_cs1.pin = SPI1_NCS_PIN;
rt_pin_mode(spi_cs1.pin, PIN_MODE_OUTPUT);
rt_pin_write(SPI1_NCS_PIN, PIN_HIGH);
res = rt_spi_bus_attach_device(&spi_dev_1, SPI1__DEVICE_NAME, SPI1_BUS_NAME, (void*)&spi_cs1);
if (res != RT_EOK)
{
rt_kprintf("rt_spi_bus_attach_device!\r\n");
return res;
}
spi_dev_1.bus->owner = &spi_dev_1;
{
struct rt_spi_configuration cfg;
cfg.data_width = 8;
cfg.mode =RT_SPI_MODE_MASK | RT_SPI_MODE_1 | RT_SPI_MSB ;
cfg.max_hz = 1*1000 *1000; /* 40M,SPI max 42MHz, 3-wire spi */
if(spi_dev_1.bus->owner==RT_NULL)
{
rt_kprintf("RT_OK\r\n");
}
rt_kprintf("owner= %d\r\n",*spi_dev_1.bus->owner);
res = rt_spi_configure(&spi_dev_1, &(cfg));
if(res != RT_EOK)
{
rt_kprintf("configure spi1 ERR!\r\n");
}
}
return RT_EOK;
}
INIT_DEVICE_EXPORT(rt_hw_spi_config);
void spi1_test(void)
{
struct rt_spi_device *spi_dev_master;
rt_uint8_t tx = {1,2,3,4,5};
rt_uint8_t rx = {0};
rt_size_trx_recv;
spi_dev_master = (struct rt_spi_device *)rt_device_find(SPI1__DEVICE_NAME);
if(!&spi_dev_master)
{
rt_kprintf("spi1 test run failed! can't find %s device!\n", SPI1__DEVICE_NAME);
}
rt_pin_write(SPI1_NCS_PIN,PIN_LOW);
rx_recv = rt_spi_send(spi_dev_master, &tx, 5);
rt_pin_write(SPI1_NCS_PIN,PIN_HIGH);
}</code></pre>
<p>我看了时序,NSS没有拉低,于是手工拉低NSS:</p>
<p>然后时钟也有了:</p>
<p> 显然MOSI的数据不对。</p>
<p>感初始化SPI还是有问题的。希望厂家技术支持一下,整这RT_Thread 还是挺费脑的。</p>
<p>用MDK写的程序截图应该是这样的:</p>
<p> </p>
<p>初始化SPI有问题,时钟设置的不对么</p>
<p>手工拉低NSS为什么会有,比较蹊跷</p>
Jacktang 发表于 2022-2-6 23:28
初始化SPI有问题,时钟设置的不对么
手工拉低NSS为什么会有,比较蹊跷
<p>我也是按照RT_Thread的示例来设置,还没有深入他的驱动看看问题出在哪里。更加期待厂家跟、RT_Thread来提供帮助。</p>
<p>有可能的话,看看相关的底层驱动文件有没有问题。</p>
<p>上次也是用nations家的一款SOC,一个很简单的外部中断调了几天。</p>
<p>后来发现,SDK外设库里面GPIO初始化函数没写完......没写完......没写完......</p>
<p>真是离了个大谱。</p>
ljj3166 发表于 2022-2-10 21:09
有可能的话,看看相关的底层驱动文件有没有问题。
上次也是用nations家的一款SOC,一个很简单的外部中断 ...
<p>真心体会,没有stm这么维护得好。作用新入门的人,会有很多坑,这也就是所说的生态!</p>
页:
[1]