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.

CCS/EK-TM4C123GXL: SSI communication with ade7753

Part Number: EK-TM4C123GXL


Tool/software: Code Composer Studio


Good Morning! I am using TivaWare library functions to communicate with the ADE7753 IC, but it is not working. Can you help me please?

Detail: the CLKIN crystal is not connected

#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "inc/hw_ssi.h"
#include "driverlib/ssi.h"
#include "ADE7753.h"

#define GPIO_PA0_U0RX 0x00000001
#define GPIO_PA1_U0TX 0x00000401

#define GPIO_PA2_SSI0CLK 0x00000802
#define GPIO_PA3_SSI0FSS 0x00000C02
#define GPIO_PA4_SSI0RX 0x00001002
#define GPIO_PA5_SSI0TX 0x00001402

int32_t recebe;

void ConfigureUART(void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
    UARTStdioConfig(0, 115200, 16000000);
}

void ssi0_init (void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinConfigure(GPIO_PA2_SSI0CLK);
    GPIOPinConfigure(GPIO_PA3_SSI0FSS);
    GPIOPinConfigure(GPIO_PA4_SSI0RX);
    GPIOPinConfigure(GPIO_PA5_SSI0TX);
    GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3| GPIO_PIN_4| GPIO_PIN_5);
    SSIClockSourceSet(SSI0_BASE, SSI_CLOCK_SYSTEM);
    SSIConfigSetExpClk(SSI0_BASE,SysCtlClockGet(),SSI_FRF_MOTO_MODE_0,SSI_MODE_MASTER,1000000,24);
    SSIEnable(SSI0_BASE);
}

int32_t ssi0_read (void)
{

    SSIDataGet(SSI0_BASE, &recebe);
    while(SSIBusy(SSI0_BASE));
    return recebe;
}

void ssi0_write (int16_t dado)
{
    SSIDataPut(SSI0_BASE,dado);
    while(SSIBusy(SSI0_BASE));
}

void main()
{
    int32_t x;

    SysCtlClockSet(SYSCTL_SYSDIV_10|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); // 20MHz

    ConfigureUART();
    ssi0_init();

    ssi0_write(_IRQEN);

    x = ssi0_read;

    UARTprintf("\n%d", x); // ever result 2265
    UARTprintf("\n%d", recebe); // ever result 0

    while(1)
    {
    }
}

  • SPI is a duplex bus: (1) every transmission includes a Tx and an Rx byte (whether you're interested or not (2) you won't receive an Rx byte if you don't send a Tx byte. This means:

    A) To (only) receive, you need to Tx a so-called "dummy" byte. This (usually) can have any value -- 0x55 and 0xAA show up nicely on a scope.

    B) Each time you Put a byte, you need to Get the corresponding Rx byte so it won't get in the way later.

    Since there's an 8-element FIFO, you can Put up to 8 bytes before Get-ing any. But you need to keep count carefully.

    Example "spi_master.c" demonstrates this. It Put-s 3 bytes, then Get-s the corresponding 3 Rx bytes. I don't see this Example in Resource Explorer, but on my system it's in:

    C:\ti\TivaWare_C_Series-2.2.0.295\examples\peripherals\ssi\spi_master.c

    Unsolicited: The ADE7753 requires you to keep /CS (/FSS) low for the entire transaction, while the SSI will set /FSS high if you let the FIFO empty. You should probably read over data sheet (SPMS376E) Sec 15.3.4.2 carefully.

    [Edit: Fixed typo]

  • Hi,

      In addition to the explanation by Bruce, the SSI has an FIFO. Before you write and read any data, you should clear out any residual data in the current RXFIFO. Please refer to the spi_master.c referred by Bruce. Below is the snippet of code that is called before any write is performed. 

        //
        // Read any residual data from the SSI port.  This makes sure the receive
        // FIFOs are empty, so we don't read any unwanted junk.  This is done here
        // because the SPI SSI mode is full-duplex, which allows you to send and
        // receive at the same time.  The SSIDataGetNonBlocking function returns
        // "true" when data was returned, and "false" when no data was returned.
        // The "non-blocking" function checks if there is any data in the receive
        // FIFO and does not "hang" if there isn't.
        //
        while(SSIDataGetNonBlocking(SSI0_BASE, &pui32DataRx[0]))
        {
        }