#include <device.h>uint32 Readvalue[4];uint8 dummyvar;uint8 i;void main(){/* Place your initialization/startup code here (e.g. MyInst_Start()) */
CyGlobalIntEnable;/* Uncomment this line to enable global interrupts. */
SPIM_Start();
SPIM_ClearTxBuffer();
SPIM_ClearRxBuffer();// LCD_Char_1_Start();
SS_Write(0);//digitalWrite(ADCCS, LOW);
SPIM_WriteTxData(0x60);//SPI.transfer(B01100000); //address
SPIM_WriteTxData(0x34);//SPI.transfer(command1); command1 = B00110100while(!(SPIM_ReadTxStatus()& SPIM_STS_SPI_DONE));
SS_Write(1);//digitalWrite(ADCCS, HIGH);// For reading 3 bytes of data and sending a command byte.
SS_Write(0);//digitalWrite(ADCCS, LOW);
CyDelayUs(1);//Maximum time needed for the Output pin to get enabled is 20nsec, giving a delay of 1usec. //if (digitalRead(MISO) == LOW) { // ADC Converter ready ?
SPIM_WriteTxData(0xF0);//SPI.transfer(B11110000);while(!(SPIM_ReadTxStatus()& SPIM_STS_SPI_DONE));
SPIM_ClearRxBuffer();//Read buffer will have two + one bytes of data, so clear the RX FIFO before reading 24 bits of data as you need.for(i=0;i<4;i++)// Three 8 bit Write/Reads clears memory registers{
SPIM_WriteTxData(0x00);//b0=SPI.transfer(0);
SPIM_WriteTxData(0x00);//b0=SPI.transfer(0);
SPIM_WriteTxData(0x00);//b0=SPI.transfer(0); (24 dummy/ zero bits to be sent)while(!(SPIM_ReadTxStatus()& SPIM_STS_SPI_DONE));// Wait till the three bytes are sent. Or check the RXStatus if some data has been received, but that doesn't tell if all 3 bytes have been received. Thus check when the Tx FIFO is sent completly.
dummyvar = SPIM_ReadRxData();
Readvalue[i]|=dummyvar;
Readvalue[i]<<=8;
dummyvar = SPIM_ReadRxData();
Readvalue[i]|=dummyvar;
Readvalue[i]<<=8;
dummyvar = SPIM_ReadRxData();
Readvalue[i]|=dummyvar;// LCD_Char_1_Position(0,0) ;// LCD_Char_1_PrintString(i); ? // if i = 0 // {// LCD_Char// } // May need UNION statement?}
CyDelayUs(10000);
SS_Write(1);
CyDelayUs(1);for(;;){}}/* [] END OF FILE */// Will use RS232 for com. Then RS232 to USB converter? Check Labview