Tool/software: TI C/C++ Compiler
Hi,
I am having issue while reading from an external ADC(part no. LTC2442) using SPI communication. I interface my tm4c123 board with external ADC LTC2442 using SPI. The ADC value what I am getting at the controller output is not matching with the input value at the ADC. I am using the 4 channels of the ADC.
The below attached is the code I used for ADC read.
#include "main.h" #include "LTC2442_ADC.h" uint32_t ulDataRx[NUM_SSI_DATA] = {0x00,0x00}; // An array of 4 data bytes to be Rx unsigned long ulindex; unsigned long ch0[NUM_SSI_DATA] ={0xB000,0x0000}; // B- 31-28 bit make dummy bit low/ 0 indicate 0000 channel 0 / '0'- 24-bit conversion result MSB first/Bits 4-0 are sub LSBs ignore this sublsb unsigned long ch1[NUM_SSI_DATA] = {0xB100,0x0000}; //1 indicate 0001 channel 1 refer LTC2442 datasheet pages-11,12,13 unsigned long ch2[NUM_SSI_DATA] = {0xB800,0x0000}; //8 indicate 1000 channel 2 unsigned long ch3[NUM_SSI_DATA] = {0xB900,0x0000}; //9 indicate 1001 channel 3 unsigned int Raw_Value1 ; unsigned int Raw_Value2; unsigned long temp, temp1; void LTC2442_SPI_config(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); while(!SysCtlPeripheralReady(SYSCTL_PERIPH_SSI0)); /*The SSI0eperipheral is on Port A and pins 2,3,4 and 5.*/ ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); /*configure the port pins for clock,chipselect,receiver,transmitter*/ ROM_GPIOPinConfigure(LTC2442_SPI_CLK); ROM_GPIOPinConfigure(LTC2442_SPI_CS); ROM_GPIOPinConfigure(LTC2442_SPI_RX); ROM_GPIOPinConfigure(LTC2442_SPI_TX); /* Configure the pin for SSI*/ ROM_GPIOPinTypeSSI(GPIO_PORTA_BASE, LTC2442_SPI_TX_PIN | LTC2442_SPI_RX_PIN | LTC2442_SPI_CS_PIN | LTC2442_SPI_CLK_PIN); /* Clock setting for SSI*/ ROM_SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_2, SSI_MODE_MASTER, 4000000, 16); ROM_SSIEnable(SSI0_BASE); } int LTC2442_ADC_OutputRead(unsigned int i) { switch(i) { /* make cs pin to low after reading the adc data*/ LTC2442_SPI_CS_LO; case 0: { for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataPut(SSI0_BASE, ch0[ulindex]); while(SSIBusy(SSI0_BASE)){} } for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]); while(SSIBusy(SSI0_BASE)){} SysDelay(1000); } } break; case 1: { for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataPut(SSI0_BASE, ch1[ulindex]); while(SSIBusy(SSI0_BASE)){} } for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]); while(SSIBusy(SSI0_BASE)){} SysDelay(1000); } } break; case 2: { for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataPut(SSI0_BASE, ch2[ulindex]); while(SSIBusy(SSI0_BASE)){} } for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]); while(SSIBusy(SSI0_BASE)){} SysDelay(1000); } } break; case 3: { for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataPut(SSI0_BASE, ch3[ulindex]); while(SSIBusy(SSI0_BASE)){} } for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { ROM_SSIDataGet(SSI0_BASE, &ulDataRx[ulindex]); while(SSIBusy(SSI0_BASE)){} SysDelay(1000); } } break; default: break; } /* make cs pin to high after reading the adc data*/ LTC2442_SPI_CS_HI; Raw_Value1 = ulDataRx[0]; //MSB bit sending out of the ADC first Raw_Value2 = ulDataRx[1]; temp = Raw_Value1 << 16; //shift the MSB bit left by 16 bit position/16bit MSB and then 16 bit LSB temp1 = temp | ulDataRx[1] ; temp1 &= 0x1FFFFFFF; /*force high three bits to zero*/ temp1 >>= 5; /*truncate lowest 5 bits/shift to right*/ return temp1; }
Please help me to solve the issue.
Thanks,
Alphy