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.

the SPI interface between MSP430F5529 and ADS1298

Other Parts Discussed in Thread: MSP430F5529, ADS1298

Hi everyone,

When I try to make SPI interface between MSP430F5529 and ADS1298 , it  always doesn't work. Hope to get some help.

The following is the code.

#define CS_HIGH (P2OUT |= 0x20)
#define CS_LOW (P2OUT &= ~0x20)

//the setup for MSP430F66xx spi.

void spi_setup(void)

{

P3SEL |= BIT3+BIT4; // P3.3,4 option select
P2SEL |= BIT7; // P2.7 option select

UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL0 |= UCMST+UCSYNC+UCMSB; // 3-pin, 8-bit SPI master, MSB 
UCA0CTL1 |= UCSSEL_2; // SMCLK=8MHz
UCA0BR0 = 0x0f; // /15 
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST;   // **Initialize USCI state machine**

 for(i=50;i>0;i--);                        // Wait for slave to initialize

CS_LOW;

}

//the spi write and read function

uint8_t spi_WriteReadByte(uint8_t txdata)
{
uint8_t retry = 0, rx;

CS_LOW;
while ((UCA0IFG&0x02) == 0) //txbuf empty flag
{
retry++;
if (retry > 200)

return 0;
}
}
UCA0TXBUF = txdata; 
retry = 0;
while ((UCA0STAT&0x1)) //busy flag
{
retry++;
if (retry > 200)

return 0;
}
}
rx = UCA0RXBUF;
CS_HIGH;
return rx;

}

// to read the reg

uint8_t spi_read_reg(uint8_t addr, uint8_t len, uint8_t dat[])

uint8_t i;

CS_LOW;

spi_WriteReadByte(addr+0x20);

spi_WriteReadByte(len-1);

for (i = 0; i < len; i++)
{
 dat[i]=spi_WriteReadByte(0xff);

}
CS_HIGH;
return 0;
}

void TI_ADS1298_Init(void)
{

uint8_t d;

P2OUT &= ~0x10; //p2.4 start=0

P2OUT |= 0x01; //p2.0 reset=1

__delay_cycles(8000000); // delay 1s

P2OUT &= ~0x01; //p2.0 reset=0

__delay_cycles(800000); // delay 100ms

P2OUT |= 0x01; //p2.0 reset=1

__delay_cycles(8000); // delay 1ms

spi_WriteReadByte(ADS1298_SDATAC);

__delay_cycles(64); // delay 8us


spi_WriteReadByte(ADS1298_STOP);

__delay_cycles(64); // delay 8us

spi_read_reg(0x00, 1, &d);  

.... ....

}

 The device id (0x92) can't be read out, when debuging, the UCA0RXBUF is always 0xFF.

What's wrong with it ?

Lots of thanks !

  • “Doesn’t work” is highly ambiguous. What doesn’t work? Don’t you get any response? Or a wrong one? Is there a signal on the SPI wires at all? Did you check with a scope? What does a logic analyzer say?
    You can’t simply post your code and expect it to be fixed by us without any hint except that it doesn’t work. (and then, it could as well be a hardware problem, like twisted MOSI/MISO lines).
    I don’t know your slave device, but maybe your logic is wrong. SPI receives while transmitting. So an answer to a command will arrive with the next byte you send.
    So your SPI_WriteReadByte will return the ‘answer’ the last write. Also, you assert and de-assert CS on each access. Depending on SPI slave, this will end the current high-level protocol. So on the next function call, the slave starts a new exchange (expecting a command while sending 0xff), which will be left unfinished again. It’s like calling someone, and ending the call right after saying ‘hello’.

  • Hi,Jens-Michael, forgive my rash posting please.

    Yes, you are right, the SPI_WriteReadByte() has the problem of  handling CS. In fact later soon, I had found the mistake after post . But the problem that was no signal on SPI wires (one of them (MO) was high level)   still existed.

    The viewing tool is scope. And then after many tryings,  finally found that  the point of the problem was resetting slave.   

    Thank you for your guide and help.

     

    BR,

    Key

     

  • what is the circuit diagram of interface between MSP430F5529 and ADS1298 ??

**Attention** This is a public forum