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/CC3200: SPI communication is not happening

Part Number: CC3200
Other Parts Discussed in Thread: ADS1247, , ADS1248

Tool/software: Code Composer Studio

Hi

I am interfacing cc3200  with ADS1247 using spi communication.The problem is i am not getting the data.I have checked in oscilloscope that sclk pin is not working means the clk pulse is not coming it is coming as a straight line.And also sometimes the return function of SPIDataPutNonBLocking funtion as 1 and someother time it is giving as 0.Plz help me in resolving the issue.Below i have attached my code.


#include <string.h>
#include "stdbool.h"
#include "stdint.h"
// Driverlib includes
#include "hw_types.h"
#include "hw_memmap.h"
#include "hw_common_reg.h"
#include "hw_ints.h"
#include "spi.h"
#include "rom.h"
#include "rom_map.h"
#include "utils.h"
#include "prcm.h"
#include "uart.h"
#include "interrupt.h"
#include "gpio.h"
#include "pin.h"


// Common interface include
#include "uart_if.h"
#include "ibp.h"

#define SPI_IF_BIT_RATE 1000000

void spiInit();
void IbpInit();
void IBP_initialize();
void send_data(unsigned char );
void rec_data();
//void receive_data1(int );
//bool ibp_self_test();

void main()
{
unsigned char ulUserData[4]="kkll";
unsigned char data4;
unsigned long pui32DataRx[2];
int i=0;
ClearTerm();
InitTerm();
MAP_PRCMPeripheralReset(PRCM_GSPI);
PinMuxConfig();
spiInit();
IbpInit();

// ibp_self_test();
Message("\t\t*************MAIN*******\n\r");
MAP_UARTCharPut(UARTA0_BASE,'c');
for(i=0;i<5;i++)
{
MAP_UARTCharPut(UARTA0_BASE, ulUserData[i]);
}

Message("\t\t*************IBP DATA*******\n\r");
send_data(ADS1248_CMD_ID);
send_data(ADS1248_CMD_WAKEUP);
receive_data(2);
data4= SPIDataGetNonBlocking(GSPI_BASE,&(pui32DataRx[0]));
Report("%x\n",pui32DataRx[0]);
Report("%x\n",&pui32DataRx[0]);
Report("%x\n",data4);
MAP_SPICSDisable(GSPI_BASE);
while(1)
{
// Message("\t\t*************IBP DATA*******\n\r");
//receive_data1(1);
}
}
void IbpInit()
{
// PK2 = POWER CONTROL

MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK);
MAP_PinTypeGPIO(PIN_03, PIN_MODE_0,false);
MAP_GPIODirModeSet(GPIOA1_BASE, 0x10, GPIO_DIR_MODE_OUT);

//PK4 = GROUND CONTROL
MAP_PinTypeGPIO(PIN_04, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA1_BASE, 0x20, GPIO_DIR_MODE_OUT);


// PN0 = SPI_EN
MAP_PRCMPeripheralClkEnable(PRCM_GPIOA0, PRCM_RUN_MODE_CLK);
MAP_PinTypeGPIO(PIN_60, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA0_BASE, 0x20, GPIO_DIR_MODE_OUT);

// PN1 = MUX_EN
MAP_PinTypeGPIO(PIN_61, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA0_BASE, 0x40, GPIO_DIR_MODE_OUT);
// PN2 MUX_SELA
MAP_PinTypeGPIO(PIN_62, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA0_BASE, 0x80, GPIO_DIR_MODE_OUT);

// PN3 MUX_sELB
MAP_PinTypeGPIO(PIN_15, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA2_BASE, 0x6, GPIO_DIR_MODE_OUT);


GPIOPinWrite(GPIOA1_BASE,GPIO_PIN_4, GPIO_PIN_4); //PK2=1
GPIOPinWrite(GPIOA1_BASE,GPIO_PIN_5,0); //PK4=1
GPIOPinWrite(GPIOA0_BASE,GPIO_PIN_5,GPIO_PIN_5); //PN0=1
GPIOPinWrite(GPIOA0_BASE,GPIO_PIN_6,GPIO_PIN_6); //PN1=1
GPIOPinWrite(GPIOA0_BASE,GPIO_PIN_7,0); //PN2=0 // mux sel-a
GPIOPinWrite(GPIOA2_BASE,GPIO_PIN_6,0); //PN3=1 // mux sel-b

/* MAP_PRCMPeripheralClkEnable(PRCM_GPIOA2, PRCM_RUN_MODE_CLK);
MAP_PinTypeGPIO(PIN_08, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA2_BASE, 0x2, GPIO_DIR_MODE_OUT);

GPIOPinWrite(GPIOA2_BASE,GPIO_PIN_1,0);*/


MAP_UtilsDelay(100000); //1MS
IBP_initialize(); // in ibp.c
Message("\t\t*******IBPINIT*********\n\r");
}

void spiInit()
{
MAP_PRCMPeripheralClkEnable(PRCM_GSPI, PRCM_RUN_MODE_CLK);

// Configure PIN_05 for SPI0 GSPI_CLK
//
MAP_PinTypeSPI(PIN_05, PIN_MODE_7);

//
// Configure PIN_06 for SPI0 GSPI_MISO
//
MAP_PinTypeSPI(PIN_06, PIN_MODE_7);

//
// Configure PIN_07 for SPI0 GSPI_MOSI
//
MAP_PinTypeSPI(PIN_07, PIN_MODE_7);

//
// Configure PIN_08 for SPI0 GSPI_CS
//
MAP_PinTypeSPI(PIN_08, PIN_MODE_7);

SPIReset(GSPI_BASE);


// Configure SPI interface
//
MAP_SPIConfigSetExpClk(GSPI_BASE,MAP_PRCMPeripheralClockGet(PRCM_GSPI),
SPI_IF_BIT_RATE,SPI_MODE_MASTER,SPI_SUB_MODE_1,
(SPI_SW_CTRL_CS |
SPI_4PIN_MODE |
SPI_TURBO_OFF |
SPI_CS_ACTIVEHIGH|
SPI_WL_8));

Message("\t\t*************SPIINIT*******\n\r");

// Enable SPI for communication
//
MAP_SPIEnable(GSPI_BASE);
MAP_SPICSEnable(GSPI_BASE);

}
/*************************************************************
* Function: IBP_initialize()
*
* Description: This function is called from Main.c before the scheduling function and
* before the self test. This is called after initializng IBP board(mux,speed,etc)
* This is used to initilaize the registers of ADC required for operation of IBP board
* and doing internal adc calibration.
*
* Parameters: NULL
*
* Returns: NULL
*
* Reentrancy: No
*
* Execution Requirements/Assumptions: NULL
*
*************************************************************/

void IBP_initialize()
{
unsigned long pui32DataRx[NUM_SSI_DATA];
while(SPIDataGetNonBlocking(GSPI_BASE, &pui32DataRx[0]))
{

}

//SysCtlDelay(650000); //= 17ms.
//SysCtlDelay(50000);
MAP_UtilsDelay(650000);
MAP_UtilsDelay(50000);
send_data(ADS1248_CMD_RESET);
//SysCtlDelay(50000);
MAP_UtilsDelay(50000);
Message("\t\t*************IBP one*******\n\r");
send_data(ADS1248_CMD_SDATAC);
send_data(ADS1248_CMD_SELFOCAL);
receive_data(1);
//SysCtlDelay(6500000); //17ms
MAP_UtilsDelay(6500000);

send_data(ADS1248_CMD_WREG); //40h
send_data(ADS1248_3_SYS0); //03h
send_data(ADS1248_1_VBIAS); //01h
send_data(ADS1248_0_MUX0); //00h
send_data(ADS1248_2_MUX1); //03h
//send_data(ADS1248_14_GAIN); //42h ADS1248_14_SPS
send_data(ADS1248_15_SPS); // from 5sps(above) to 1000sps it is set. currently set at 160(or something) sps.

receive_data(8);

send_data(ADS1248_CMD_RREG); //20h
send_data(ADS1248_3_SYS0); //03h
receive_data(2);
send_data(ADS1248_CMD_NOP);
receive_data(1);
send_data(ADS1248_CMD_NOP);
receive_data(1);
send_data(ADS1248_CMD_NOP);
receive_data(1);
send_data(ADS1248_CMD_NOP);
receive_data(1);

send_data(ADS1248_CMD_SYSGCAL);
receive_data(1);
//SysCtlDelay(6500000); //17ms
MAP_UtilsDelay(650000);

//14-----Write the respective register configuration with the WREG command (40h, 03h, 01h, 00h, 03h and 42h); --pg 37 datasheet
send_data(ADS1248_CMD_WREG); //40h
send_data(ADS1248_3_SYS0); //03h
send_data(ADS1248_1_VBIAS); //01h
send_data(ADS1248_0_MUX0); //00h
send_data(ADS1248_0_MUX0); //03h
send_data(ADS1248_15_SPS); //42h

receive_data(6);

send_data(ADS1248_CMD_RREG); //20h
send_data(ADS1248_3_SYS0);
receive_data(2);


send_data(ADS1248_CMD_NOP);
receive_data(1);
send_data(ADS1248_CMD_NOP);
receive_data(1);
send_data(ADS1248_CMD_NOP);
receive_data(1);
send_data(ADS1248_CMD_NOP);
receive_data(1);

send_data(ADS1248_CMD_SYNC); //05h
send_data(ADS1248_CMD_SYNC); //05h-------////because we have to give sync command twice---pg 38
receive_data(2);
//SysCtlDelay(650000);
MAP_UtilsDelay(650000);
Message("\t\t*************LAST IBP INIT*******\n\r");
}

void send_data(unsigned char Byte)
{
unsigned char data;
data=SPIDataPutNonBlocking(GSPI_BASE,Byte);
Report("\t\tsend data=%d\n\r",data);

}


void receive_data(int n)
{
unsigned long rec=0;
unsigned char data=0;
data=SPIDataGetNonBlocking(GSPI_BASE,&rec);
Report("\t\trec1= %d\n\r",rec);

Report("\t\t rec=%d\n\r",data);


}

  • Hello,

    I see your configuring your pins and configuring the SPI clock so assuming that is correct I'd say the only thing missing is the board initialization which you can do so by calling BoardInit(). Our CC3200 SDK has a simple spi_demo which does all the setups for you so you wont have to implement your own initialization functions. You can find the spi_demo example in the example folder in the SDK root. Even if you don't want to use the example in your project it's at least a great reference to learn how to setup SPI peripheral.

    Jesu
  • Glad I could help - closing thread.

    Jesu