This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

external adc (LTC2452 ) interface with tm4c123gh6pz

Other Parts Discussed in Thread: TM4C123GH6PZ

Hi...i'm interfacing external adc (LTC2452 )  interface with tm4c123gh6pz through SPI communication..but i'm not able to see the output...please check my code if i have done any mistake in configuration...

#include <string.h>
#include "inc/lm4f232h5qc.h"
#include <stdio.h>
#include "inc/hw_memmap.h"
#include "driverlib/pin_map.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/softssi.h"
#include "utils/uartstdio.h"
#include "driverlib/rom.h"
#include "driverlib/ssi.h"
#include "inc/hw_gpio.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"


#define GPIO_PD0_SSI1CLK 0x00030002
#define GPIO_PD1_SSI1FSS 0x00030402
#define GPIO_PD2_SSI1RX 0x00030802
//#define GPIO_PD3_SSI1TX 0x00030C02

#define NUM_SSI_DATA 1


void Setup_SSI(void);
int readdata(void);

unsigned long int ulDataTx[NUM_SSI_DATA]; // An array of 4 data bytes to be Tx
unsigned long int ulDataRx[NUM_SSI_DATA]; // An array of 4 data bytes to be Rx
unsigned long int ulindex1;
int key;
unsigned long int Raw_Value1 ;

float ADC_Conv = 0.0000762939453125; //ref = 5, 12bit
long adcdata;
float volts;

int main(void)
{
/*Configures the system clock, the lm4f232h5qc has a 8MHz crystal onboard*/
SysCtlClockSet(SYSCTL_SYSDIV_1| SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);

Setup_SSI();
while(1)
{

adcdata = readdata();
volts = adcdata * ADC_Conv;
}


}

void Setup_SSI(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1);

// The SSI0 peripheral is on Port A and pins 2,3,4 and 5.
// Enable GPIO port A
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

// This function/s configures the pin muxing on port A pins 2,3,4 and 5
// It uses the values DEFINED at the top of the program and takes 1 parameter
GPIOPinConfigure(GPIO_PD0_SSI1CLK);
GPIOPinConfigure(GPIO_PD1_SSI1FSS);
GPIOPinConfigure(GPIO_PD2_SSI1RX);

// Configures the pins for use by the SSI, takes 2 parameters
GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_2|GPIO_PIN_0);
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1);




// Configures the SSI port for SPI master mode, it takes 6 parameters
SSIConfigSetExpClk(SSI1_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, SysCtlClockGet()/4, 16);



// Enables the SSI0 module
//GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1, 0x02);

SSIEnable(SSI1_BASE);
}

int readdata(void)
{
ulDataTx[0] = 0x0000;

GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);

for(ulindex1 = 0; ulindex1 < NUM_SSI_DATA; ulindex1++)
{
SSIDataPut(SSI1_BASE, ulDataTx[ulindex1]);
while(SSIBusy(SSI1_BASE)){}
SSIDataGet(SSI1_BASE, &ulDataRx[ulindex1]);

}

GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x02);

ulDataRx[0] &= 0xffff;
Raw_Value1 = ulDataRx[0];

return(Raw_Value1);

}

Thanks in advance

  • Hello Raaki

    My analysis of the code

    1. Is the scope showing data being sent by the ADC?

    2. If it is showing data being transmitted as expected for the Analog voltage being applied then my understanding is that the computation of the value with ADC ref would require the floating point unit to be enabled

    Regards

    Amit

  • Might some attention to, "KISS" produce faster/easier results?

    a) You must properly configure that external ADC.  (we're not told why you believe the MCU's ADC inadequate)  You should first monitor the SPI clock, then SPI data into the ADC along w/ADC's CS.  Are all present - appear as expected?

    b) Only when (a) has been achieved - should you "look" for return data from the ADC.  Suggest that you present a proper - mid-range voltage - to the ADC channel being interrogated.  Does that SPI data look reasonable?

    c) Involving floating point early - as you do - to my mind - adds undue complexity - is not appropriate at this early stage.  Stay w/normal integer calculation until you assure that all SPI transfers are correct and that the ADC is fully responsive - over it's full spec'ed input voltage range.

    Over complicating at the outset rarely yields best/fastest results...  Smaller battles are easier to monitor & manage...

  • Hi Amith..i have done same calculation for ltc2440(24 bit resolution).i can able to get the output n displayed on lcd also..just we are going to use ltc2452(16bit resolution) for one of my application..i'm using same code because i didn't find any difference in both device..when i'm reading i'm getting the output always  as 0xffff...till now  didn't connect the oscilloscope for checking the waveform..but i'm reading the rx pin..it always high only..

  • Hello Raaki,

    A scope is the best method to see what transaction on the bus is present as fast moving signals do not get captured on a multimeter that well (assuming that you have a DMM which is reading the line high).

    As long as the SCK and CS from TM4C123 is coming as expected but the RX from the LTC device not coming as expected, you may need to look at the data sheet of the LTC device to see if there "*" subtlety.

    Regards

    Amit

  • k Amith..Thank you.. i'll check with scope..

  • Hi,

    For the device LTC2452 a timer setting/use is needed. No other way since the data retrieving should be composed of three steps:

    a) Convert command, obtained by toggling CS pin low/high. (should be GPIO output pin)

    b) Delay of typical 16.6 ms, max 23 ms so a better value is 24 ms, needed for internal conversion

    c) Data retrieving - by providing 16 bits of clock and again CS set low and then high at the end of 16th bit.

    Petrei

  • Hi  Petrei. thank you for your information ...

    i'm not able to understand some points..

    1.For the device LTC2452 a timer setting/use is needed. means what???i need to use timer??

    2. Convert command means what??before reading the data  need to toggle the cs pin?

    3.Delay of typical 16.6 ms, max 23 ms so a better value is 24 ms, needed for internal conversion.

       when i need to give this much of delay in my program??

    4.Data retrieving - by providing 16 bits of clock and again CS set low and then high at the end of 16th bit.

        after reading the data need  to set cs low to high???

     

    Thank in advance.

     

  • Hi,

    Raaki, these are mainly from the data sheet. It states that data must be got after typical 16.6 ms delay from the convert command. How do you intend to have a 16.6 ms delay? Well if not with a timer then by polling, but this could be not efficient if you have also other things to do with the micro, not only conversion.

    As for data sheet - do we "speak" same one? This is what i read - didn't you the same? If I am wrong then apologize...I was only trying to highlight some programming steps.

    Petrei 

  • Hi Petrei ,....Thank you for your information..i have gone through the datasheet of ltc2452..i got to known...ltc2440 n ltc2452 are different..

    now i'll modify my program according to that..

    i'm going to do this way..

    1.first i'll make the cs pin as GPIO output

    2.second i'l make the cs pin for low to high

    3.i'll give 24ms delay

    4.i'll retrieve the data

    5.again i'll make the cs pin for low to high

     

  • Hi  Petrei ..can i use systick function for creating 24ms delay??n iwant some example..because first time i stared to use timer with this controller..please help  me.

  • Hi,

    Yes, you can. But I do not have an immediate example for that. The systick is symply to configure, set the time interval and enable interrupts and is ready to work. 

    Petrei

    Edit: read again your posts - your step 5 need more work: first set CS low, retrieve the data and then set CS high - CS has the role of SSIFSS pin.

  • K..Thank you Petrei..i didn't not use time timer..ii'm checking through simple delay function.

    int readdata(void)
    {
    ulDataTx[0] = 0x0000;

    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x02);

    delay(6);

    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x00);
    for(ulindex1 = 0; ulindex1 < NUM_SSI_DATA; ulindex1++)
    {
    SSIDataPut(SSI1_BASE, ulDataTx[ulindex1]);
    while(SSIBusy(SSI1_BASE)){}
    SSIDataGet(SSI1_BASE, &ulDataRx[ulindex1]);
    while(SSIBusy(SSI1_BASE)){}

    }

    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, 0x02);

    ulDataRx[0] &= 0xffff;
    Raw_Value1 = ulDataRx[0];

    return(Raw_Value1);

    }

    void delay(unsigned int msec)
    {

    int i,j ;
    for(i=0;i<msec;i++)
    for(j=0;j<5000;j++);


    }

    now problem is i'm getting  unexpected output..input is 1V..but i'm getting output  as 3v. what is wrong with this??solution please..

  • Hi,

    I think you have several mistakes - delay(6)? Woudn't be 16 or  better 24? If not enough time, you just check the conversion status, and that's why you get 0xFFFF.

    Also, for other things: believe that interrupt should be better than just polling. Careful also with getting data - you must not send anything else since the sending pin is not connected, just get data, SSIDataGet, one 16-bit word is enough, no loop. A second observation is the command pulse does not have a specified duration - still it is useful to gave it some duration. I woulld write this as:

    // command:

    // set pin low

    // SysCtlDelay for a half microsecond delay 

    // set pin high; to allow the chip to understand your command

    //

    // getting the data:

    // set pin low

    // SSIDataGet, one word, 16 bits

    // set pin high

    Adjust your code with these...

    Petrei

  • Hi..thank you..please can you check the data out format of LTC2442??

    i have connected the IN– pin to ground.n for  IN+ i'm giving the input  from the calibrator.

    for 0v i'm getting 0x7fff..my doubt is that device will accept the single ended input???

  • Hi,

    First, let's not mix things: is your LTC2452 problem solved?

    Then I will check the new one.

    Petrei

  • hey no no..sorry...i'm using LTC2452  only..

  • HI...Sorry For late reply...i'm using ltc2452 only..by mistake i have sent that...

  • Hi,

    Use an oscilloscope to check out the signals. Sychronize the scope with the falling edge of CS signal - check/verify first the delay. Then the debugger to see what is eventually wrong. Read again the data sheet, refine/modify your software , check again...

    Petrei