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.

TIVA C TM4C123G SPI code, but not working. Thanks!

Other Parts Discussed in Thread: ADS1299

Hi,

I am using the TIVA board to acquire the data from ADS1299 EVM daughter board via SPI. 

I initialized the ADS1299 and then write/read register to/from it. But the value read is 0.  This is the code. Thank you! 

Qi

// INCLUDE
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "math.h"
#include "stdio.h"
#include "inc/hw_ssi.h"
#include "driverlib/ssi.h"

// DEFINE
#define ADS_WAKEUP 	0x2
#define ADS_STANDBY	0x4
#define ADS_RESET 	0x6
#define ADS_START 	0x8
#define ADS_STOP 	0xA

#define ADS_RDATAC	0x10
#define ADS_SDATAC	0x11
#define ADS_RDATA	0x12

#define ADS_RREG	0x20
#define ADS_WREG	0x40

// GLOBAL VARIABLES
uint32_t read_value;
uint32_t value;
uint32_t value2;

uint32_t inst1;
uint32_t inst2;


//SUBFUNCTIONS
void LEDTwinkleTwice();
void ADS1299_SysCmdWrite(uint32_t value);
void ADS1299_ReadCmdWrite(uint32_t value);
void ADS1299_RegWrite(uint32_t adres,uint32_t value);
uint32_t ADS1299_RegRead(uint32_t adres2);


//MAIN FUNCTION
//3 steps. (step 1) config: clock/ssi/gpio/interrupt  (step 2) config ADS1299 via SPI  (step 3) acquire DATA from ADS1299
int main(void)
{
	unsigned long ulindex=0;
	unsigned long rxindex=0;
	unsigned long ulData=0;
	unsigned long rxData[16]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
	unsigned long try=1;
	unsigned long clockget=0;
	unsigned int rxDataOne = 0xFF;

	unsigned int reg_start_adress=0xFF;
	unsigned int reg_number=0xFF;
	unsigned int reg_value=0xFF;

	//(step 1) config: clock/ssi/gpio/interrupt----------------------------------------------------------------------------------------------
	//CONFIG CLOCK: 50MHz
	SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	clockget = SysCtlClockGet();

	//CONFIG GPIO&SSI: SSI0 master
	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_5|GPIO_PIN_4|GPIO_PIN_3|GPIO_PIN_2);

	SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(),SSI_FRF_MOTO_MODE_0,SSI_MODE_MASTER,10000, 8);
	SSIEnable(SSI0_BASE);

	//CONFIG GPIO:
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1); //output, ADS SPI ~RESET,
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_2); //output, ADS SPI START,
	GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4); //output, ADS SPI ~CS,
	GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_5);  //input,  ADS SPI ~DRDY (interrupt)

	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_PIN_1); //RESET=1
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_2, 0); 		   //START=0
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_4, GPIO_PIN_4);  //CS=1

	//(step 2) config ADS1299 via SPI  ----------------------------------------------------------------------------------------------
	//(1) POR (2)RESET (3) issue SPI CS (4) SDATAC, write REG, read REG
	SysCtlDelay(8000000);						//(1) power up setup, poweronReset/OSC startup: 2power16 tclk of ADS
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,0); 			//(2) RESET=0
	SysCtlDelay(100000);						//(2) wait more than 2 tclk + 18 tclk
	GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,GPIO_PIN_1); 	//(2) RESET=1
	SysCtlDelay(100000);
	GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_4, 0); 			//(3) SPI CS=0
	SysCtlDelay(8000000);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); 			//LED for debug
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);     //LED for debug
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2, GPIO_PIN_2);   //LED for debug
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2, 0);			//LED for debug

	SSIDataPut(SSI0_BASE,ADS_SDATAC);   					//(4) SDATAC: stop ADS conversion command
	while(SSIBusy(SSI0_BASE));
    SysCtlDelay(100000);
    										//(4) write ADS reg: address (0x01-ADS CONFIG0), value(0x95), write 1 time
    reg_start_adress = 0x01;
    reg_number = 0x0; //0 represents 1 reg
    reg_value = 0x95;

    SSIDataPut(SSI0_BASE, ADS_WREG | (reg_start_adress & 0x1F));
    while(SSIBusy(SSI0_BASE));
    SysCtlDelay(100000);

    SSIDataPut(SSI0_BASE,reg_number);
    while(SSIBusy(SSI0_BASE));
    SysCtlDelay(100000);

    SSIDataPut(SSI0_BASE,reg_value);
    while(SSIBusy(SSI0_BASE));
    SysCtlDelay(100000);

			/(4) read ADS reg: address (0x01-ADS CONFIG0), read 1 time
    SSIDataPut(SSI0_BASE, ADS_RREG | (reg_start_adress & 0x1F));
    while(SSIBusy(SSI0_BASE));
    SysCtlDelay(100000);

    SSIDataPut(SSI0_BASE,reg_number);
    while(SSIBusy(SSI0_BASE));
    SysCtlDelay(100000);

    SSIDataPut(SSI0_BASE,0xFF); //dummy SPI write to get SPI RX data, which is prepared for ADS CONFIG0
    while(SSIBusy(SSI0_BASE));
    SysCtlDelay(100000);


    for(ulindex = 0; ulindex <= 6; ulindex++)
   //rx data 0 - 5 should be 0, data 6 should be 0x95 from ADS register, but it is still 0
    {	    //
    	// Wait until there is data to be read.
    	SSIDataGet(SSI0_BASE, &rxDataOne);
    	while(SSIBusy(SSI0_BASE));

    	rxData[ulindex] = rxDataOne;
    	try++;
    }

    try++;
}

 

  • Hello qi,

    Did you connect a Scope or LA and see what the transactions on the bus are? Also you are doing 7 writes but 6 reads.

    Regards
    Amit
  • Thank you Amit!

    I have measured the voltage on the pins, and it seems that the tiva board can only pull the all the SPI related pins ('cs, reset,rx, ...' pins) to 0.7V, not 0V. I am not sure if this kind of 'logic 0' can be effective to enable SPI communication?

    By the way, it seems I read 7 times:
    for(ulindex = 0; ulindex <= 6; ulindex++)

    Best,
    Qi
  • Hello Qi,

    I did not see the sign "<=" instead reading it as "<".

    The SPI related pins are CS, CLK, RX and TX. The TM4C will drive and "not pull" then low. Having said that disconnect the ADS device and check if they are being driven to 0V. I have used the TM4C in multiple SPI application and unless there is a bus contention or a faulty device (either ADS or TM4C) it should be 0V. Check if the IO specifications of the device match.

    Also when you measure 0.7V is it a Scope Shot that you have captured?

    Regards
    Amit
  • Hi,

    Thank you.

    Can I use a buffer between two boards to guarantee a good 0 or 1, by increasing the strength?

    Can you recommend a 3.3V to 3.3V multiple pin buffer (4 or even 8 inputs, the same number of outputs) ?

    Thank you!
    Qi
  • Hello Qi,

    First we need to figure out why the Pin is not being driven to 0V. Did you perform the experiments I mentioned to isolate the issue?

    Regards
    Amit