20 关于IMX. RT 1052系列BSP 的spi驱动

发布于 2020-08-27 14:31:06

有哪位老铁使用了imx.rt1052的spi驱动?自己测了一下,最终spi时序有错。
测试如下:
1、使用MCUXpresso 配置了spi4的相关引脚:
image.png
2、配置使能
image.png
3、挂载spi设备

#define ADS1220_SPI_DEVICE_NAME     "spi40"
#define ADS1220_SPI_BUS_NAME        "spi4"
static  struct rt_spi_device* spi_dev_ads1220; /* SPI设备ads1220对象 */

static int ads1220_spi_init(void)
{
    rt_err_t ret;
    struct rt_spi_configuration cfg;

    ret = rt_hw_spi_device_attach(ADS1220_SPI_BUS_NAME,ADS1220_SPI_DEVICE_NAME,GET_PIN(2,20));

    if(ret != RT_EOK)
    {
        LOG_E("ads1220 spi attach spi4 failed!");
        return -RT_ERROR;
    }
    
    cfg.data_width = 8;
    cfg.mode = RT_SPI_MASTER|RT_SPI_MODE_1|RT_SPI_MSB ;
    cfg.max_hz = 500*1000;

    spi_dev_ads1220 = (struct rt_spi_device*) rt_device_find(ADS1220_SPI_DEVICE_NAME);
    ret = rt_spi_configure(spi_dev_ads1220,&cfg);
    if(ret != RT_EOK)
    {
        LOG_E("ads1220 spi configure failed!");
        return -RT_ERROR;
    }
    return RT_EOK;
}
/* 导出到自动初始化 */
INIT_COMPONENT_EXPORT(ads1220_spi_init);

查看设备,注册成功。
image.png
4、测试发一个数据

static void spi_ads1220_sample(void)
{
    uint8_t reg_data = 0;
    rt_err_t ret = RT_EOK;
    rt_size_t size;
     rt_uint8_t cmd = 0x20;
    spi_dev_ads1220 =(struct rt_spi_device*)     
    rt_device_find(ADS1220_SPI_DEVICE_NAME);
    if(!spi_dev_ads1220)
    {
         rt_kprintf("can't find %s device!\n",         
                     ADS1220_SPI_DEVICE_NAME);
    }
    else
    {
        while(1)
        {
            size = rt_spi_send(spi_dev_ads1220,&cmd,1);
            if(size != 0)
            {
                LOG_D("ads1220发送信息成功!");
            }
            else
            {
                LOG_E("ads1220发送信息失败!");  
            }    
            rt_thread_mdelay(500);
        }
    } 
}

最终逻辑分析仪抓取波形,cs电平有问题。
image.png

查看更多

关注者
0
被浏览
134
JQRR_7669
JQRR_7669 认证专家 2020-08-28

试试不使用dma怎么样

2 个回答
ccxzjz
ccxzjz 2020-08-28

恩,不用DMA倒正常了,看一下DMA驱动

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友