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.

ADS1256: ADS1256 and TM4C129 SSI communication issue

Part Number: ADS1256

Hi,

I am new to ADS1256 and testing it out for a project. I am trying to communicate ADS1256 with my TM4C129exl launchpad. I am facing a peculiar problem of getting the same repeated value of 0x003e regardless of the commands I give. I am using a Wingoneer ADS1256 module. I have included the code below:

/*
pdwn -> 3.3
cs ->PN4
drdy ->Not connected
dout -> pdo
din -> pd1
sclk -> pd3
gnd
5v
*/

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "driverlib/ssi.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "UART.h"
#include "driverlib/uart.h"
uint32_t ui32SysClkFreq;

int i;
uint8_t k,j=0;
char buffer [sizeof(long)*8+1];

int main(void)
{
uint32_t ui32Index;
uint32_t ui32Data[4] =1;
ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

/*Uart initialization*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Port A for Uart
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, ui32SysClkFreq, 9600,(UART_CONFIG_WLEN_8 |
UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

/*SPI initialization*/
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_4);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinConfigure(GPIO_PD3_SSI2CLK);
SSIAdvModeSet(SSI2_BASE,SSI_ADV_MODE_LEGACY);
GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);
GPIOPinTypeSSI(GPIO_PORTD_BASE,GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);
SSIConfigSetExpClk(SSI2_BASE, ui32SysClkFreq, SSI_FRF_MOTO_MODE_1,
SSI_MODE_MASTER, 250000, 8);
SSIEnable(SSI2_BASE);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_4,16);

while(1)
{

GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_4,0); // deasserting CS
/*read status register*/
SSIDataPut(SSI2_BASE, 0x10); // send 1st command byte -0b00010000
SSIDataPut(SSI2_BASE, 0x01); // send 2nd command byte -0b00000000
while(SSIBusy(SSI2_BASE))
{
}
SSIDataGet(SSI2_BASE, &ui32Data[0]);
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_4,16); // asserting CS

/*Uart communication*/
ltoa(ui32Data[0],&buffer[0]);
while(buffer[j]!=0)
{
UARTCharPut(UART0_BASE, buffer[j]);
j++;
}
j=0;
UARTCharPut(UART0_BASE, '\n');
SysCtlDelay(100000);


}
}

Any help regarding this matter is welcome. 

TIA

  • Hi Mustahsin,

    Have you looked at the SPI communication on an oscilloscope? I highly recommend doing so when starting out because it may help you see what is happening on the SPI bus that you otherwise wouldn't be able to know from looking at the code.

    I don't see anything particularly wrong, but you may want to use the "SSIDataGetNonBlocking()" function before starting SPI communication to make sure the SPI FIFO has been cleared. Also, when sending two bytes of data, make sure to read out two bytes of data. Perhaps all you need to do is read the next value in the FIFO.
  • Hi,

    Thanks for getting back to me. I made some changes and ran the code. It seems one of the issue is the sclk frequency used.  It seems I can read back the values of the registers

    01h,03h and 04h. The registers 00h gives random values and 02h returns nothing on the miso line. I am attaching the code and also the spi communication on the oscilloscope.

    #include <stdint.h>

    #include <stdbool.h>

    #include "inc/hw_memmap.h"

    #include "inc/hw_ssi.h"

    #include "inc/hw_types.h"

    #include "driverlib/ssi.h"

    #include "driverlib/gpio.h"

    #include "driverlib/pin_map.h"

    #include "driverlib/sysctl.h"

    #include "UART.h"

    #include "driverlib/uart.h"

    uint32_t ui32SysClkFreq;

    int i;

    uint8_t k,j=0;

    char buffer [sizeof(long)*8+1];

    int main(void)

    {

    uint32_t ui32Index;

    long ui32Data[4] =1;

    ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |

    SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

    /*Uart initialization*/

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // Port A for Uart

    GPIOPinConfigure(GPIO_PA0_U0RX);

    GPIOPinConfigure(GPIO_PA1_U0TX);

    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    UARTConfigSetExpClk(UART0_BASE, ui32SysClkFreq, 9600,(UART_CONFIG_WLEN_8 |

    UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

    /*SPI initialization*/

    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // CS control

    GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_4);

    GPIOPinTypeGPIOInput(GPIO_PORTN_BASE, GPIO_PIN_5); //DRDY

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    GPIOPinConfigure(GPIO_PD3_SSI2CLK);

    SSIAdvModeSet(SSI2_BASE,SSI_ADV_MODE_LEGACY);

    GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);

    GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);

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

    SSIConfigSetExpClk(SSI2_BASE, ui32SysClkFreq, SSI_FRF_MOTO_MODE_1,

    SSI_MODE_MASTER, 2000000, 16);

    SSIEnable(SSI2_BASE);

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_4,16);

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_4,0); // deasserting CS

    //send reset command

    while(GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_5)){}; // check DRDY line

    for(i=0; i<1000;i++) // delay before first SCLK

    SSIDataPut(SSI2_BASE, 0xfe); // reset command

    while(SSIBusy(SSI2_BASE))

    {

    }

    SSIDataPut(SSI2_BASE,0x0f);  // SDATAC command

    while(SSIBusy(SSI2_BASE))

    {

    }

               //WREG DRATE COMMMAND

    SSIDataPut(SSI2_BASE, 0x53);

    for(i=0; i<1000;i++)

    SSIDataPut(SSI2_BASE, 0x00);

    for(i=0; i<1000;i++)

    SSIDataPut(SSI2_BASE, 0xa1);

    for(i=0; i<1000;i++)

    while(SSIBusy(SSI2_BASE))

    {

    }

    for(i=0; i<1000;i++);

           /*WREG MUX

    SSIDataPut(SSI2_BASE, 0x51);

    while(SSIBusy(SSI2_BASE))

    {

    }

    SSIDataPut(SSI2_BASE, 0x00);

    while(SSIBusy(SSI2_BASE))

    {

    }

    SSIDataPut(SSI2_BASE, 0x01);

    while(SSIBusy(SSI2_BASE))

    {

    }*/

    while(1)

    {

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_4,0); // deasserting CS

    /*read DRATE register*/

    while(GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_5)){}; // check DRDY line

    SSIDataPut(SSI2_BASE, 0x11); // send 1st command byte -0b00010000

    for(i=0; i<100;i++)

    SSIDataPut(SSI2_BASE, 0x00); // send 2nd command byte -0b00000000

    while(SSIBusy(SSI2_BASE))

    {

    }

    // SSIDataGet(SSI2_BASE, &ui32Data[0]);

    GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_4,16); // asserting CS

    }}

    Miso(Purple) - read back value(01h) =01h

    (13h) read back value = F0h

    similarly, I got E0h for (14h- register). I cannot also write to the registers it seems. 

  • Hi Mustahsin,

    I have a couple of suggestions to try:

    • I would recommend using 8-bit SPI frame (instead of 16-bit frames as you are currently using). The reset command is only 8-bits and not all other commands will be a multiple of 16 bits, so it may be easier to simply send SPI command byte by byte.

    • The 2 MHz SCLK is a little fast for the ADS1256 if you're using the nominal 7.68 MHz ADC clock. The SPI clock should not exceed 1/4th the frequency of the ADC clock, so you might try using a a slightly lower SCLK frequency.

    • The continuous SCLK is probably causing some issues with reading registers. The ADS1256 has a t6 delay required between the command bytes and the register data byte(s). See figure 34 in the ADS1256 datasheet.

    • If you can try to capture a single RREG command on the oscilloscope with the /CS signal included so that you can see how this command is framed. For troubleshooting, it is okay to loop 1000 times, but I would recommend including the toggling of /CS in the loop to make it easier to differentiate between commands.
       
  • Hi Mustahsin,

    I just want to follow-up and see if my last post was able to help you resolve your issue or not. Did you find the cause of this problem?

    Let us know if you are still having issues and we'll do our best to help!
  • Hi,

    Thanks for getting back to me
    I tried the first two suggestions. It did not work. I got little sidetracked. I am still working on it and will get back to you with the results as soon as possible.

    regards,
    Mustahsin