unsigned char bits = 8;
unsigned int speed = 50000;
unsigned short delay;
static void spi_transfer_data(unsigned char *cmd, int len, unsigned char *data)
{
int ret;
struct spi_ioc_transfer spi_rtx = {
.tx_buf = (unsigned long)cmd,
.rx_buf = (unsigned long)data,
.len = len,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
};
ret = ioctl(spi,SPI_IOC_MESSAGE(1),&spi_rtx);
if (1 == ret)
perror("It can not do spi well\n");
}
以上代码为spi在收发(全双工)时刻的操作,该接口的问题在于slen是cmd和data的长度。
P.S. 可以了解到.len = len 是先把len长度tx数据放在SPI总线上,再获取len长度数据塞到rx数组。
[后续加入全双工的独立长度读取SPI数据的接口和测试结果]
手机扫一扫
移动阅读更方便
你可能感兴趣的文章