我正在尝试通过spidev访问NAND闪存。 我想发送两个字节的数据,即要求设备ID的0x9F 0x00。 尽管我可以看到0x9f,但在示波器上却看不到第二个字节0x00。 此外,示波器仅触发8个时钟脉冲
似乎无法发送多个字节,这可能是什么问题?
这是我的简码:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(int argc, char **argv)
{
char *name;
int fd;
struct spi_ioc_transfer xfer;
unsigned char buf_tx[32], buf_rx[32], *bp;
int len, status;
name = argv[1];
fd = open(name, O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
//memset(&xfer, 0, sizeof(struct spi_ioc_transfer));
memset(buf_tx, 0, sizeof buf_tx);
memset(buf_rx, 0, sizeof buf_rx);
len = sizeof buf_rx;
printf("DBG#: 4\n");
/*
* Send a GetID command
*/
buf_tx[0] = 0x9f;
buf_tx[1] = 0x00;
xfer.tx_buf = (unsigned long)buf_tx;
xfer.len = 2;
xfer.rx_buf = (unsigned long)buf_rx;
xfer.speed_hz = 100000000;
status = ioctl(fd, SPI_IOC_MESSAGE(1), xfer);
if (status < 0) {
perror("SPI_IOC_MESSAGE");
return -1;
}
printf("response(%d): ", status);
for (bp = buf_rx; len; len--)
printf("%02x ", *bp++);
printf("\n");
return 0;
}
输出:
response(2): ff ff 00 00 00 00 00 00 00 00 00... (32 times total)