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.

ads1271 spi interfacing with tm4c129encpdt problem

Other Parts Discussed in Thread: ADS1271, TM4C129ENCPDT

Hi all,

     I am using tm4c129encpdt controller interfaced with ads1271 ADC ic (single IC). I configured microcontroller with 120MHZ clock speed.

ADS1271 setting -> MODE: high resolution

                                    FORMATE: SPI

First i tried to read ads1271 with gpio pin configuration and  sucessfuly i  read ads1271 with gpio pins.My code is as bellow

while(1)

{

if(GPIOPinREAD(GPIO_PORTD_BASE,GPIO_PIN_4)==0) // DRDY pin

{

for(i=23;i>=0;i--)

{

dt=GPIOPinRead(GPIO_PORTD_BASE,GPIO_PIN_0)==0) // DOUT pin

GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3,0); // Clock low

GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_3,GPIO_PIN_3); // clock high

data1 = (data1 | (dt<<i) ); // collect data in data1

Delay(5); // 5microsec delay

}

}

}

Now i want to read this ADS1271 ic with SPI configuration. My code is as bellow,

***************************************************************************************************************

SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2); 

GPIOPinConfigure(GPIO_PD0_SSI2XDATA1); // MISO

GPIOPinConfigure(GPIO_PD3_SSI2CLK); // clock

SSIConfigSetExpClk(SSI2_BASE, 120000000,SSI_FRF_MODE_3,SSI_MODE_MASTER,2000000,8,);

while(1)

{

if(GPIOPinREAD(GPIO_PORTD_BASE,GPIO_PIN_4)==0) // DRDY pin

{

for(i=2;i>=0;i--)

{

SSIDataPut1(SSI2_BASE,DUMMY); // put dummy byte before reading data

while(SSIBusy(SSI2_BASE)); 

SSIDataGet1(SSI2_BASE,&dt); // read 8 bit data

data1 = (data1 | (dt<<i) );

Delay(5); // 5microsec delay

}

}

}

This code is not working please suggest me any solution.

******************************************************************************************************************

Put and get function is as bellow

void SSIDataPut1(uint32_t ui32Base, uint8_t  ui32Data)

while(!(HWREG(ulBase + SSI_O_SR) & SSI_SR_TNF))
{
}

// Write the data to the SSI.
HWREG(ulBase + SSI_O_DR) = ui32Data; 

}

void SSIDataGet1(unsigned long ulBase, unsigned char*pulData)
{

while(!(HWREG(ulBase + SSI_O_SR) & SSI_SR_RNE))
{
}

// Read data from SSI.
*pulData = HWREG(ulBase + SSI_O_DR);
}

  • Hello Sagar,

    The SSI-2 Module GPIOs have not been configured.

    The configuration requires the call of the functions GPIOPinConfigure and GPIOPinTypeSSI. Please refer to an example code like some in D:\ti\TivaWare_C_Series-2.1.0.12573\examples\peripherals\ssi

    Secondly, I do not see CS being configured as a GPIO or from SSI-2 FSS signal neither XDAT0

    And lastly, do check the Frame Format as expected by the ADS1271 device

    Regards
    Amit
  • Hi Amit,

    Of interest - poster had "no need" to check the SPI Frame Format while, "bit banging."     So long as his signals met the slave's demands - all proved "well." (whatever "well" was!)

    Then - upon moving to "real SPI" - the need for Frame Format is (suddenly) enforced - and poster is stuck!

  • Hello cb1,

    The poster gives me a snapshot of the "working" code and does not show what has been pre-configured. Just ensuring that user has considered some of the basic configuration requirements clearly.

    Regards
    Amit
  • Indeed Amit - "devil in the details" and when hidden - much extra time/effort is the predictable (yet unwelcome) outcome...
  • Hi Amit,

    Amit Ashara said:
    The configuration requires the call of the functions GPIOPinConfigure and GPIOPinTypeSSI. Please refer to an example code like some in D:\ti\TivaWare_C_Series-2.1.0.12573\examples\peripherals\ssi

    Secondly, I do not see CS being configured as a GPIO or from SSI-2 FSS signal neither XDAT0

      As you told that SSI2 have not been configured , but it is not the case what i did is sufficient to run SPI. I am getting SPI clock i checked it on CRO.

    ADS1271 ic's datasheert says that we should read output on falling edge of clock.

    Is it compulsory to put data before get ? Because there is no need of MOSI pin for ads1271 (there is no need of put data on ads1271 ic) 

    Please suggest me any solution.

    Regards,

    Sagar

  • I have configured GPIOPinTypeSSI but still not working. Amit please suggest me what will be the type of SSI_FRF_MODE_
  • Hello Sagar,

    Yes. It is necessary for the Master to Put data to get data. Can you please paste the updated code, if it does not look something like the following?

    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    GPIOPinConfigure(GPIO_PD3_SSI2CLK);
    GPIOPinConfigure(GPIO_PD2_SSI2FSS);
    GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
    GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);

    GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
    GPIO_PIN_3);

    SSIConfigSetExpClk(SSI2_BASE, 120000000, SSI_FRF_MOTO_MODE_0,
    SSI_MODE_MASTER, 2000000, 8);

    SSIEnable(SSI2_BASE);

    Also do note that some of the devices require that FSS or CS must not be deasserted between multiple transfers, in which case the CS has to be controlled as a GPIO. Or alternatively, you can use the advanced modes

    Regards
    Amit
  • Hello Amit,

    Amit Ashara said:
    Yes. It is necessary for the Master to Put data to get data. Can you please paste the updated code, if it does not look something like the following?

         As you told that it is necessary to put data to get data , but in my case there is no need to put data. According ads1271 datasheet as if i will put data then clock will be driven by master and then there will be data lost. As datasheet says that data will change on falling clock. 

       So in my case i dont want to drive a master clock during data put. (for avoiding data loss). So what should i do , i dont want to drive master clock during data put.??

    Regards,

    Sagar

  • Hello Sagar

    What!!! The data will not be lost. it will be captured on the SSIRX pin. Without putting the data, the clock will not start and without the clock the data will not be captured.

    Regards
    Amit
  • Hello Amit,
    I got the output. Thank you for your valuable suggestion.
    Regards,
    Sagar
  • Hello Sagar,

    For sake of completeness can you update the forum what the issue was? It could be a good reference for someone running into the same issue.

    Regards
    Amit
  • Hello Amit,

    I tried the code with while loop and it is working fine.

    for(z=0;z<200;z++)

    {

    while(GPIOPinREAD(GPIO_PORTD_BASE,GPIO_PIN_4)==0) // DRDY pin

    {

    for(i=2;i>=0;i--)

    {

    SSIDataPut1(SSI2_BASE,DUMMY); // put dummy byte before reading data

    while(SSIBusy(SSI2_BASE));

    SSIDataGet1(SSI2_BASE,&dt); // read 8 bit data

    data1 = (data1 | (dt<<i) );


    }

    }

    }

    Initialy i was using for loop so before getting DRDY line low for loop gets completed(as controller is fast 120MHZ)
    instead of
    if(GPIOPinREAD(GPIO_PORTD_BASE,GPIO_PIN_4)==0) // DRDY pin
    i used
    while(GPIOPinREAD(GPIO_PORTD_BASE,GPIO_PIN_4)==0) // DRDY pin

    so uP will stop for DRDY tobe get low.

    Regards,
    Sagar
  • Hello Sagar,

    This is a blocking assignment. It would be better if you can add the GPIO change for DRDY as an interrupt and perform the transaction in the interrupt handler. Once the transaction is completed the SSI interrupt handler can be used to push back the data.

    Regards
    Amit