各位大虾们好,我写了个应用程序操作spi设备,波特率,字节位数,模式都都设置好了,然后就测试读写,每次读一百个以上的字节就会出现如下错误:
------------[ cut here ]------------ WARNING: CPU: 0 PID: 165 at drivers/spi/spi-atmel.c:1281 0xc042c090 Modules linked in: CPU: 0 PID: 165 Comm: spidev Tainted: G W 4.9.52-linux4sam_5.7 #16 Hardware name: Atmel SAMA5 Function entered at [<c010ce64>] from [<c010a6c4>] Function entered at [<c010a6c4>] from [<c0116744>] Function entered at [<c0116744>] from [<c011680c>] Function entered at [<c011680c>] from [<c042c090>] Function entered at [<c042c090>] from [<c0429c30>] Function entered at [<c0429c30>] from [<c0429fa8>] Function entered at [<c0429fa8>] from [<c0429fdc>] Function entered at [<c0429fdc>] from [<c042a73c>] Function entered at [<c042a73c>] from [<c042a914>] Function entered at [<c042a914>] from [<c01b7ab0>] Function entered at [<c01b7ab0>] from [<c01b8814>] Function entered at [<c01b8814>] from [<c01b9600>] Function entered at [<c01b9600>] from [<c01073a0>] ---[ end trace 4cda773338d3f6ad ]--- spidev spi32765.0: spi transfer tim 然后读10字节没问题,读完十字节后又读一百多个字节竟然没问题了,然后掉电重启,再直接读一百多字节还是这种错误,读完10字节又好了,这是为什么啊? 我的应用程序如下:代码不长求大神们看下: fd = open("/dev/spidev32765.0", O_RDWR);
if(fd < 0) { printf("spi open failed\n");
return -1; }
mode = mode | SPI_MODE_0;
//SPI 模式 ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if(ret == -1) { printf("spi WR MODE ioctl failed\n");
return -1; }
ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if(ret == -1)
{
printf("spi RD MODE ioctl failed\n");
return -1;
}
//每个字节多少位
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if(ret == -1)
{
printf("spi WR BITS ioctl failed\n");
return -1;
}
ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if(ret == -1)
{
printf("spi WR BITS ioctl failed\n");
return -1;
}
//设置速率
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if(ret == -1)
{
printf("set spi speed failed\n");
return -1;
}
wd = read(fd, buffer, 200);
if(wd == -1)
{
printf("spi read error\n");
return -1;
}
else
{
for(i = 0; i < 200; i++)
{
printf("bytes number:%d = %d\n", i+1, buffer);
}
}
// sleep(1);
close(fd);
|