AnsweredAssumed Answered

Re: IMX6 SPI read/write

Question asked by wenjing wang on Oct 10, 2014
Latest reply on Oct 14, 2014 by jimmychan
Branched from an earlier discussion

the SPI clk issue has been fixed now, and i define the spi read/write function, but i'm not sure if it is right:

static int vk32xx_read_reg(struct spi_device *spi,uint8_t port,uint8_t reg,uint8_t *dat)

{

        struct spi_message msg;

        uint8_t buf_wdat[2];

        uint8_t buf_rdat[2];

        int status = 0;

        buf_wdat[0] = 0x7f&(((port-1)<<5)|(reg<<1));

        buf_wdat[1] = 0x0;

        buf_rdat[0] = 0x0;

        buf_rdat[1] = 0x0;

        status = spi_write_then_read(spi, buf_wdat, 2, buf_rdat, 2);

        if(status)

                printk("WWJ====vk32xx_read_reg failed status = %d\n", status);

        printk("buf_rdat[0] = 0x%x, buf_rdat[1] = 0x%x\n", buf_rdat[0], buf_rdat[1]);

        *dat = buf_wdat[1];

 

 

    return 0;

}

 

static int vk32xx_write_reg(struct spi_device *spi,uint8_t port,uint8_t reg,uint8_t dat)

{

        struct spi_message msg;

        uint8_t buf_reg[2];

        int status = 0;

 

 

        struct spi_transfer index_xfer = {

                .len            = 2,

        };

        //spi_message_init(&msg);

        /* register index */

        buf_reg[0] = 0x80|((port-1)<<5)|(reg<<1);

        buf_reg[1] = dat;

  

        status = spi_write(spi, buf_reg, 2);

        if(status)

                printk("WWJ======vk32xx_write_reg failed status = %d\n", status);

 

 

        return status;

}

Outcomes