My analog board and Pi2 are inside a well ventilated metal enclosure. The MCP3008 is not getting warm to the touch. There is a fan pushing air though the enclosure.
All signals look clean on the scope.
Vcc, and Vref are 3.3v. All samples are within 0-3.3v.
I have tried all different SPI clocks form 500Khz to 3Mhz.
An identical board sitting on my desk has been working fine for 45 min. Three different PI and MCP3008 inside the metal enclosure will work for about 5 min after a power cycle then the readings go nuts, before all eight channels revert to zero.
I will leave the working board running all night. The AC cuts off here at about now. So the temp in this office will go up over night to about 30c (Singapore) so I guess I will know if the temperature affects it.
Here is my "transfer" code:
//==================================================================
//Private main read/write
//==================================================================
int CMCP3008::spiWriteRead( unsigned char *data, int length)
{
struct spi_ioc_transfer spi[length];
int i = 0;
int result=-1;
//One spi transfer for each byte
for(i=0;i<length;i++)
{
memset(&spi[i],0,sizeof(spi[i])); //Flush
spi[i].tx_buf = (unsigned long)(data+i); //Transmit from "data"
spi[i].rx_buf = (unsigned long)(data+i); //Receive into "data"
spi[i].len = sizeof(*(data+i));
spi[i].delay_usecs = 0;
spi[i].speed_hz = this->speed;
spi[i].bits_per_word = this->bitsPerWord;
spi[i].cs_change = 0;
}
result=ioctl (this->spifd,SPI_IOC_MESSAGE(length),&spi) ;
if(result<0) { printf("spiWR==[%i]\n",result); return -1; }
return 0; //Success
}
Please help