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 woes : Waveform meaning ??

Hi,

For quite some time i have been trying to communicate (write the required hex word) to the AD9834, a Sig-Generator IC.

But i have been unsuccessful.

During subsequent experimentation with the code, i decided to capture the waveforms of the CLK, SIMO and SOMI pins.

The datasheet of the AD9834 states that "After FSYNC (SOMI) goes low, serial data is shifted into the input shift register of the device on the falling edges of SCLK for 16 clock pulses. FSYNC (SOMI) can be taken high after the 16th falling edge of SCLK"

Now i captured all the three signals during program execution, and this is how they look.



Top/ 1 / yellow = SIMO pin

Middle / 2 / Green = SOMI pin

Bottom / 3 / purple = CLK pin

The clk waveform looks weird to me.

I have the following doubts?

1) Does the CLK waveform look satisfactory?

2) Are my initializations correct?

3) What are the possible reasons because of which my code fails to work?

I would be eternally grateful, if someone could help me out.


PS : (I, II, III, IV and V are the 16bits of data (words) i am entering)

The Code:

#include  <msp430x26x.h>

void main (void)

{
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
DCOCTL = CALDCO_1MHZ;
for(i=2100;i>0;i--);                      // Wait for DCO to stabilize.

// initialization of port pins

P1DIR = 0xC0;
P1OUT = 0xC0;
P2DIR = 0x00;
P2OUT = 0x00;
P3SEL = 0x0E;
P3DIR = 0x0E;
P3OUT = 0x0E;
P5SEL = 0X0E;
P5DIR = 0x0E;
P5OUT = 0x0E;

// initialization concerned with UCBO

UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;    //3-pin, 8-bit SPI master
UCB0CTL1 |= UCSSEL_2;                     // SMCLK
UCB0BR0 = 0x02;                           // /2
UCB0BR1 = 0;                              //
UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
IE2 |= UCB0RXIE;                          // Enable USCI_A0 RX interrupt

// initialization concerned with UCB1

UCB1CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;    //3-pin, 8-bit SPI master
UCB1CTL1 |= UCSSEL_2;                     // SMCLK
UCB1BR0 = 0x02;                           // /2
UCB1BR1 = 0;                              //
UCB1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
UC1IE |= UCB1RXIE;                          // Enable USCI_A0 RX interrupt

// Initialize buffers

UCB0TXBUF = 0x00;
UCB1TXBUF = 0x00;

_BIS_SR(LPM0_bits+GIE);
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR (void)
{
  volatile unsigned int i;

  while (!(IFG2 & UCB0TXIFG));              // USCI_B0 TX buffer ready?
 
  while (!(UC1IFG & UCB1TXIFG));              // USCI_B1 TX buffer ready?
 
  P1OUT &= ~0xC0;
 
  // I start
  P3OUT = 0x0A;
  P5OUT = 0x0A;
  UCB0TXBUF = 0X21;
  UCB0TXBUF = 0X00;
  UCB1TXBUF = 0X21;
  UCB1TXBUF = 0X00;
 
  for(i=50;i>0;i--);
 
  P3OUT = 0x0E;
  P5OUT = 0x0E;
  for(i=50;i>0;i--);
  // I ends
 
  // II start
 
  P3OUT = 0x0A;
  P5OUT = 0x0A;
  UCB0TXBUF = 0X50;
  UCB0TXBUF = 0XC7;
  UCB1TXBUF = 0X50;
  UCB1TXBUF = 0XC7;
 
  for(i=50;i>0;i--);
 
  P3OUT = 0x0E;
  P5OUT = 0x0E;
  for(i=50;i>0;i--);
 
  // II ends
 
  // III start
 
  P3OUT = 0x0A;
  P5OUT = 0x0A;
  UCB0TXBUF = 0X40;
  UCB0TXBUF = 0X00;
  UCB1TXBUF = 0X40;
  UCB1TXBUF = 0X00;
 
  for(i=50;i>0;i--);
 
  P3OUT = 0x0E;
  P5OUT = 0x0E;
  for(i=50;i>0;i--);
  // III ends
 
  // IV start
 
  P3OUT = 0x0A;
  P5OUT = 0x0A;
  UCB0TXBUF = 0XC0;
  UCB0TXBUF = 0X00;
  UCB1TXBUF = 0XC0;
  UCB1TXBUF = 0X00;
 
  for(i=50;i>0;i--);
 
  P3OUT = 0x0E;
  P5OUT = 0x0E;
  for(i=50;i>0;i--);
  // IV ends
 
  // V starts
 
  P3OUT = 0x0A;
  P5OUT = 0x0A;
  UCB0TXBUF = 0X20;
  UCB0TXBUF = 0X00;
  UCB1TXBUF = 0X20;
  UCB1TXBUF = 0X00;
 
  for(i=50;i>0;i--);
 
  P3OUT = 0x0E;
  P5OUT = 0x0E;
  for(i=50;i>0;i--);
 
  // V ends
 
  for(i=30;i>0;i--);
 
  }


 

  • janmay b c said:
    After FSYNC (SOMI) goes low, serial data is shifted into the input shift register

    This really doesn't make sense. SOMI is slave output master input signal, and it has to be provided by teh slave for each individual clock pulse, forming the data the slave wants to send to the master.

    THe description, however, reads like FSYNC(SOMI) is a control signal.

    Now SPI usually requires an additional control signal, usually called CS. This signal mus tbe provided usign a normal GPIO pin of the MSP. It 'selects' the slave (remember, SPI is a bus) and also synchronizes the slave to a byte border.

    So if CS goes low, the slave knows that the next clock edge is the first bit of data meant for him. If CS goes high,. the slave knows that he i s not addressed anymore, and shall shut up and ignore any clock pulses.

    Your scope printout seems to confirm this: it looks like you have two outputs fighting on SOMI. (also, the clock doesn't look good too. maybe there's even more wrong)

  • Dear Sir,

    Thanks for your reply. I accidentally created two identical threads of the same name. If possible please look into this thread. I have posted my corrected code at the end of the thread , if mistakes are present, please let me know. Thanks

    http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/161423.aspx#588762

    Sorry about that.

    best wishes

    janmay

**Attention** This is a public forum