//setup mode register
/***********************************************************/
//Enable write to CR, next operation is to write and select mode register
SPI_Write_Byte(0x08);//0000 1000
//Mode select: Single Conversion Mode
//Clock select: Internal 64KHz Clock, not available at the CLK pin.
//Filter update rate select: fadc=16.7Hz,Rejection 65dB
SPI_Write_2Bytes(0x200a);//H8:0010 0000 L8:0000 1010
/***********************************************************/
//delay_nms(1);
Uart0_SendStr("Wait until MISO goes low. ");
//delay_nus(2);
//wait while RDY is HIGH
while(GET_SPI_MISO()==HIGH)
{
SPI_Send_CLK(1);
}
Uart0_SendStr(" MISO goes low now. ");
//SPI_MOSI_HIGH();
//delay_nus(5);
//select data register
SPI_Write_Byte(0x58);//0101 1000
//read 3 times to get data
for(i=0;i<3;i++)
{
data=SPI_Read_Byte();
}
//SPI_SS_HIGH();
//caculate temperature value
tempCode|=((ulong)data[0])<<16;
tempCode|=((ulong)data[1])<<8;
tempCode|=(ulong)data[2];
//code=(2^23)*[(AIN*Gain/Vref)+1]
//2^23=8388608
//Ain=((tempCode/8388608)-1)*Vref/Gain;//get the voltage of AIN1
//convert the number to temperature
//do something here
//
SPI_SS_HIGH();
delay_nus(5);