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.

SPI communication between ADS1293 and CC2541

Other Parts Discussed in Thread: CC2541, ADS1293

Hi, I am trying to communicate ADS1293 and CC2541 through SPI. I used the code given in the TI website, in the firmware uploaded, through the following link:-

www.ti.com/tool/TIDA-9600#technicaldocuments 

The bluetooth communication is functioning properly but I am getting all data as FF:FF:FF:FF......:FF:FF, after I removed the "if (send_buff != NULL)" condition. That means I am not getting any data from ADS1293. Secondly I examined the SPI communication between ADS1293 and CC2541 by writing a particular value to a register and reading it back continuously. I observed proper waveforms on SCLK,CS and MOSI pin, but nothing could be observed on MISO pin. That implies registers of ADS1293 are not written. I used the following code for testing SPI communication.  I am also providing my schematic along with this. Please help me figure out the problem, I have been on this for quite a number of days but am unable find out the solution. Please help me out!

#define SPI_BAUD_M 0
#define SPI_BAUD_E 16



void spiWriteByte(uint8 write)
{
U0CSR &= ~0x02; // Clear TX_BYTE
U0DBUF = write;
while (!(U0CSR & 0x02)); // Wait for TX_BYTE to be set
}

void spiReadByte(uint8 *read, uint8 write)
{
U0CSR &= ~0x02; // Clear TX_BYTE
U0DBUF = write;
while (!(U0CSR & 0x02)); // Wait for TX_BYTE to be set
*read = U0DBUF;
}

void TI_ADS1293_SPIWriteReg(uint8 addr, uint8 value)
{
uint8 inst;

P1_1 = 0; // /CS enable 

inst = 0X7F & addr; // register address
spiWriteByte(inst); // Send register address

spiWriteByte(value); // Send data value

P1_1 = 1; // /CS disable 

}

uint8 TI_ADS1293_SPIReadReg(uint8 addr)
{
uint8 pVal, inst;

P1_1 = 0; // /CS enable

inst = 0X80 | addr; // register address

// WAIT_1_3US(2); // Wait 
spiWriteByte(inst); // Send lower register address 

spiReadByte(&pVal, 0xFF); // Read data

P1_1 = 1; // /CS disable

return pVal; 

}





void main(void)
{



CLKCONCMD = (CLKCONCMD & ~(CLKCON_OSC | CLKCON_CLKSPD)) | CLKCON_CLKSPD_16M;



/***************************************************************************
* Setup I/O ports
*
* Port and pins used USART0 operating in SPI-mode are
* MISO (MI): P0_2
* MOSI (MO): P0_3
* SSN (SS) : P1_1
* SCK (C) : P0_5
*

*/



// Configure USART0 for Alternative 1 => Port P0 (PERCFG.U0CFG = 0).
PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U0CFG_ALT1; 






// Set pins 2, 3 and 5 as peripheral I/O and P1_1 as GPIO output.
P0SEL = (P0SEL) | BIT5 | BIT3 | BIT2;
P1DIR |= BIT1;


/***************************************************************************
* Configure SPI
*/

// Set USART to SPI mode and Master mode.
U0CSR &= ~(U0CSR_MODE | U0CSR_SLAVE);

// Set:
// - mantissa value
// - exponent value
// - clock phase to be centered on first edge of SCK period
// - negative clock polarity (SCK low when idle)
// - bit order for transfers to LSB first
U0BAUD = SPI_BAUD_M;
U0GCR = (U0GCR & ~(U0GCR_BAUD_E | U0GCR_CPOL | U0GCR_CPHA | U0GCR_ORDER))
| SPI_BAUD_E;


/***************************************************************************
* Transfer data
*/

TI_ADS1293_SPIWriteReg(0x00,0x01); 

int x;


while(1)
{

x = TI_ADS1293_SPIReadReg(0x00);

}

}

  • I couldn't open your uploaded schematic. It looks to me you have changed the USART0 pins for Alternative -1 from Alternative-2. Good to check there's no pin conflict because of this change in your EVM or board setup. Also, please check the SPI interface setup code. Initially, better to keep it the same as in the TI design firmware function ADS123_SPISetup. You need to keep clock phase/polarity and msb first initializations same. Thanks.
  • Thank you very much for your reply. I changed the bit order to MSB first and obtained waveforms on MOSI pins. Now I am able to properly receive ECG data on notification handle over bluetooth.
    Thank you for your help.
  • Hi, I am successfully able to receive notification packets over bluetooth on BTool. But the ECG signal which I am getting is not proper. I am guessing that the bluetooth is not able to properly transmit all the sampled ECG data by ADS1293. I have set the DEFAULT_ECG_PERIOD to 7ms but still I get around 250-300 packets( of 20 bytes each) in 10 seconds (sampling rate is 50-60Hz). Even when I change the DEFAULT_ECG_PERIOD to some other value, say 100ms, there is no change in rate of transfer through bluetooth.  I have set R1=4, R2=5 and R3 = 6  through my register settings which implies the sampling rate of ADS1293 is 1707Hz. But the bluetooth connection is not fast enough to properly transmit the sampled data.

    I am attaching an image of received ECG signal.

  • Hi Puja,

    There's distortion because CC2541 is not able to keep up with the ADS1293 sampling rate and as a result sample data is getting lost. I think the default ADS1293 sample rate tested in the CC2541 firmware is 160samples/sec. Over this rate CC2541 cannot keep up.


    Thanks,
    Vishy