With AD7490, We are getting 0 in channel 1 to 8 and changing board by board when load connected and open load.
Similarly more 0x0FFF value on channel 9 to 16.
1) Initialization portion
CSensorSpiCtrl.Bits.PeriphChipSelect = 0;
CSensorSpiCtrl.Bits.PeriphType = SPI_FIXED_PERIPHERAL; // Fixed peripheral
CSensorSpiCtrl.Bits.DataOrder = MSB;
CSensorSpiCtrl.Bits.Mode = 1; // SPI mode 3
CSensorSpiCtrl.Bits.SPIrxTxIntr = RX_TX_INTR_DIS; // no interrupts
CSensorSpiCtrl.Bits.CSAAT = LOW;
CSensorSpiCtrl.Bits.Dbits = 8; //0= 8-bit SPI operation., 4 - 12 bit , 8 - 16 bit
//CSensorSpiCtrl.Bits.Mode = 0; // Mode 0
//SPI_set_CSAAT_pin(currentSpi, HIGH);
//GPIO_write_pin(currentChipSelectGPIO,HIGH); //No chip select
//usleep(5);
currentSpi = spiNo;
SPI_init(currentSpi);
SPI_config(currentSpi, CSensorSpiCtrl); // modifing spi control register.
SPI_set_baud(currentSpi, SPI_BAUD_CFD_256); // setting spi baud rate. 100/4 == SPI_BAUD_CFD_16
// Disable interrupts
SPI_set_intr(MDP_SPI_0, TXINTR_DIS, RXINTR_DIS);
if(LDsense)
{
if((LDsense & 0x01) == 1 )
{
for ( int indx =0; indx < 2; indx ++ )
{
//SPI_receive(currentSpi);
GPIO_write_pin(SPI_CS1,LOW); //chip select
usleep(100);
///SPI_set_CSAAT_pin(currentSpi, LOW); //usleep(1000);
SPI_transmit(currentSpi, 0xFFFF);
SPI_receive(currentSpi);
usleep(50);
GPIO_write_pin(SPI_CS1,HIGH); //No chip select
usleep(100);
}
GPIO_write_pin(SPI_CS1,LOW); //chip select
usleep(100);
SPI_transmit(currentSpi, 0x8310);
SPI_receive(currentSpi);
usleep(50);
GPIO_write_pin(SPI_CS1,HIGH); //No chip select
usleep(100);
2) Read portion
unsigned short Cmd_Channel[16] = { 0x8310, 0x8710, 0x8B10, 0x8F10, 0x9310, 0x9710, 0x9B10, 0x9F10,
0xA310, 0xA710, 0xAB10, 0xAF10, 0xB310, 0xB710, 0xBB10, 0xBF10 };
unsigned short Read_ADC7490_CurrentVal (unsigned short ADC_Channel) //, unsigned char spi_slave )
{
// GPIO0 [0] SPI_CS0, 1- CS1, 2- CS2, 3- CS3
unsigned short ADCCHVAL = 0;
for ( int repet = 0; repet <10; repet ++ )
{
float value;
unsigned char readBuf[2], Read_length = 2, timeout_spi =0;
//Cmd_Channel[ADC_Channel] = ( 0x8330 | (ADC_Channel<< 10) );
ADCCHVAL = 0;
SPI_wait_if_busy(currentSpi); // Check if SPI controller is busy.
GPIO_write_pin(SPI_CS1,LOW);
usleep(7); //75 3
SPI_transmit(currentSpi, Cmd_Channel[ADC_Channel] ); // ( 0x8310 | (ADC_Channel<< 10) ));
//usleep(75); //75 50
//printf("\n\r Cmd_Channel %x", Cmd_Channel[ADC_Channel]);
ADCCHVAL = (SPI_receive(currentSpi)) & 0x0FFF; //data
//usleep(5);
/*if ( ADCCHVAL == 4095 )
{
ADCCHVAL = 0;
}*/
tmp_ADCCHVAL[repet] = ADCCHVAL;
//printf(":: %d-",ADCCHVAL); //printf(":val1:- %d -Tx %x-",ADCCHVAL, Cmd_Channel[ADC_Channel]);
GPIO_write_pin(SPI_CS1,HIGH); //GPIO_write_pin(currentChipSelectGPIO,HIGH);
usleep(50); //100 50
}
return (ADCCHVAL);
}