特别是len是以什么为单位?然后tr[1]的变量speed_hz,bits_per_word又变成了0,到tr[2]又变了回来,最后ret是什么含义,好像linux下的spi的软件应用没有一个比较详细的说明。还有linux下spi是不是可以使用中断或者DMA?谢谢!
void ETA105::ETA105_ReadAD( )
{
int ret,i1;
uint8_t tx[] ={ 0x80,0x00 };
uint8_t rx[4],rx2[4];
uint16_t buffer[2];
for(i1=0;i1<8;i1++) //读取八个通道的值
{
buffer[0]=0x0000;
tx[0] = tx[0]+0x08;
if(tx[0] > 0x3c)
tx[0] = 0x04;
//printf("tx=0x%.4x\n",tx[0]);
tr[0].tx_buf = (unsigned long)tx;
tr[0].rx_buf = NULL;
tr[0].len = 2;
tr[0].delay_usecs = 0;
tr[0].speed_hz = Speed;
tr[0].bits_per_word = Bits;
tr[1].tx_buf = NULL;
tr[1].rx_buf = (unsigned long)rx;
tr[1].len = 2;
tr[1].delay_usecs = 0;
tr[1].speed_hz = 0;
tr[1].bits_per_word = 0;
/*
tr[2].tx_buf = NULL;
tr[2].rx_buf = (unsigned long)rx2;
tr[2].len = 2;
tr[2].delay_usecs = 0;
tr[2].speed_hz = Speed;
tr[2].bits_per_word = Bits;*/
ret = ioctl(m_fd, SPI_IOC_MESSAGE(2), tr );
//ret = ioctl(m_fd, SPI_IOC_MESSAGE(1), tr );
if (ret < 2 )
pabort("can't send spi message");
/*write(m_fd, tx, 2);
read(m_fd, rx, 2);*/
buffer[0] = rx[0];
buffer[0] = buffer[0]<<8;
buffer[0] |= rx[1];
/* buffer[1] = rx2[0];
buffer[1] = buffer[1]<<8;
buffer[1] |= rx2[1];*/
//sleep(1);
printf("CH[%d]=%.3f\n", i1+1, buffer[0]/1000.000 );
//printf("0x%.4X\n",buffer[0] );
//printf("0x%.4X\n",buffer[1] );
//sleep(1);
}
/*for( i1=0; i1<2; i1++ )
printf("0x%.2X\n", rx[i1] );*/
}