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.
Tool/software: Code Composer Studio
Hi,
I am using cc3200 interfacing with ads1247 as a slave .The problem i am facing here is i am not getting the data from the slave device.And if i use the spidataput and spidataget these functions are working means it will stuck in this function after that non of the instructions are executed. And the return function of the SPIDataPutNonBlocking(GSPI_BASE,dat); is getting 1 only for the first time of sending and rest of the time i am getting zero and the return function of the SPIDataGetNonBlocking function is always zero; pls help me in this
#include <string.h>
#include "stdbool.h"
#include "stdint.h"
// Driverlib includes
#include "rom.h"
#include "rom_map.h"
#include "hw_memmap.h"
#include "hw_common_reg.h"
#include "hw_types.h"
#include "hw_ints.h"
#include "uart.h"
#include "interrupt.h"
#include "pinmux.h"
#include "utils.h"
#include "prcm.h"
#include "pin.h"
#include "gpio.h"
#include "spi.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 receive_data(int);
//void receive_data1(int );
bool ibp_self_test();
void main()
{
unsigned char ulUserData[4]="kkll";
int i=0;
ClearTerm();
InitTerm();
spiInit();
IbpInit();
PinMuxConfig();
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");
while(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_50, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA0_BASE, 0x1, 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(GPIOA0_BASE,GPIO_PIN_0,0); //PN3=1 // mux sel-b
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_2);*/ // PD2= CHIP SELECT=ACTIVE LOW
// GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0); //PD2=0 - ACCORDING TO DATASHEET , STEP 7
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);
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);
//
// Enable SPI for communication
//
MAP_SPIEnable(GSPI_BASE);
// MAP_SPICSEnable(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_3PIN_MODE |
SPI_TURBO_OFF |
// SPI_CS_ACTIVELOW|
SPI_WL_8));
Message("\t\t*************SPIINIT*******\n\r");
}
void IBP_initialize()
{
unsigned long del=650000;
unsigned long data0;
unsigned long data1;
unsigned long DataRx[NUM_SSI_DATA];
while(SPIDataGetNonBlocking (GSPI_BASE, &DataRx[0]))
{}
Message("\t\t*************IBPINITITALIZE*******\n\r");
MAP_UtilsDelay(del);
MAP_UtilsDelay(50000);
send_data(ADS1248_CMD_RESET);
MAP_UtilsDelay(50000);
Message("\t\t*************IBP one*******\n\r");
send_data(ADS1248_CMD_SDATAC);
send_data(ADS1248_CMD_SELFOCAL);
receive_data(1);
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);
MAP_UtilsDelay(del);
//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);
MAP_UtilsDelay(del);
Message("\t\t*************LAST IBP INIT*******\n\r");
}
void send_data(unsigned char dat)
{
SPIDataPutNonBlocking(GSPI_BASE,dat);
Message("\t\t*************SENDDATA*******\n\r");
}
void receive_data(int n)
{
unsigned char ui32Index;
unsigned char data;
unsigned long pui32DataRx[10];
for(ui32Index = 0; ui32Index < n; ui32Index++)
{
//
// Receive the data using the "blocking" Get function. This function
// will wait until there is data in the receive FIFO before returning.
//
data=SPIDataGetNonBlocking(GSPI_BASE,&pui32DataRx[ui32Index]);
//
// Since we are using 8-bit data, mask off the MSB.
//
// pui32DataRx[ui32Index] &= 0x00FF;
Report("%x\n",data);
//
// Display the data that SSI0 received.
//
Report("%x\n",pui32DataRx[ui32Index]);
}
Message("\t\t*************RECEIVE DATA*******\n\r");
}