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.

Interfacing MSP430 with AD9834 (sine wave generator) by SPI

Other Parts Discussed in Thread: MSP430F2619

Hi,


I am using the MSP430F2619 MCU.
I am trying to send data to the AD9834, there is an OCTAL BUFFER(74HC244)  inbetween my MCU and AD9834,
I have connected the buffer to the MCU via the following pins:

Pin connections



(See Pic)
P3.1 (UCB0SIMO),
P3.2(UCB0SOMI),
P3.3(UCB0CLK),
P1.6(GPIO) for enable (active low enable), and
P2.1(CA3) for AD9834 reset.

Also i need to send three different words one after another to the AD9834 through the Buffer.

Ox2200 for ctrl reg
0xA000 for setting phase
0x4000 and 0x47DD for setting frequency.



Before i show the code, here are the USCI_B0__SPI register values.

BEFORE PROGRAM EXECUTION :

UCBOCTL0__SPI = 0x01
UCBOCTL1__SPI = 0x01
UCBOBRO__SPI = 0x00
UCBOBR1__SPI = 0x00
UCBOSTAT__SPI = 0x00
UCBORXBUF__SPI = 0x00
UCBOTXBUF__SPI = 0x00

AFTER PROGRAM EXECUTION:

UCBOCTL0__SPI = 0x69
UCBOCTL1__SPI = 0x80
UCBOBRO__SPI = 0x02
UCBOBR1__SPI = 0x00
UCBOSTAT__SPI = 0x20
UCBORXBUF__SPI = 0x00
UCBOTXBUF__SPI = 0x00

here's the code.

#include  <msp430x26x.h>

unsigned char MST_Data,SLV_Data;

void main(void)

{
  volatile unsigned int i;

  WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
  if (CALBC1_12MHZ ==0xFF || CALDCO_12MHZ == 0xFF)                                     
  {  
    while(1);                               // If calibration constants erased
                                            // do not load, trap CPU!!
  }    
  BCSCTL1 = CALBC1_12MHZ;                    // Set DCO
  DCOCTL = CALDCO_12MHZ;
  for(i=2100;i>0;i--);                      // Wait for DCO to stabilize.
                                       
 
  P1SEL |=0x40;                             // Switch off buffer
  P3SEL |= 0x0E;                            // P3.3,2,1 option select
  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

 P1OUT &= ~0x02;                           // Now with SPI signals initialized,
  P1OUT |= 0x02;                            // reset slave

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


  UCB0TXBUF = MST_Data;                     // Transmit first character

 

   

  _BIS_SR(LPM0_bits + GIE);                 // CPU off, enable interrupts
}

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

  while (!(IFG2 & UCB0TXIFG));              // USCI_B0 TX buffer ready?

 P1SEL |=0x00;                             // Switch-on/Enable buffer
for(i=100;i>0;i--);

 P2SEL |=0x02;                             //Reset Sig gen
for(i=100;i>0;i--);


 P2SEL |=0x00;                             //Remove Reset
for(i=100;i>0;i--);

 
  UCB0TXBUF = 0x022;                     // Send MSB of Ctrl word
for(i=100;i>0;i--);

 
  UCB0TXBUF = 0x00;                     // Send LSB of ctrl word
for(i=100;i>0;i--);

 
  UCB0TXBUF = 0xA0;                     // Send MSB of phase value
for(i=100;i>0;i--);

 
  UCB0TXBUF = 0x00;                     // Send LSB of phase value
for(i=100;i>0;i--);

UCB0TXBUF = 0x040;                     // Send MSB of M14 of freq reg
for(i=100;i>0;i--);

UCB0TXBUF = 0x00;                     // Send LSB of M14 of freq reg
for(i=100;i>0;i--);

UCB0TXBUF = 0x047;                     // Send MSB of L14 of freq reg
for(i=100;i>0;i--);

UCB0TXBUF = 0xDD;                     // Send LSB of L14 of freq reg
for(i=100;i>0;i--);

 P1SEL |=0x40;                             // Switch-off/Disable buffer





  for(i=30;i>0;i--);                        // Add time between transmissions to
}                                           // make sure slave can keep up


I dont get any sine output from the AD9834.

I have the following doubts:

1) I am setting the contents of Bit Rate Control Register 0 and 1, as 0x02 and 0 respectively, is it right?


2) Has the buffer been enabled during the execution of the program?

3) Is the code in the ISR right?

4) My XTCLK is 12MHz, i am setting DCO as 12MHz, is it right?

5) Which lines of code are unnecessary?

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



  • Hi!

    What is the purpose of the octal buffer/line driver between the MCU and the DDS? 

  • Hi Greg,

    Honestly, the buffer serves no purpose. I had the schematics from the previous version of the board, on which the buffer was present, and that board worked fine. So i just used the same buffer on my board too.

    But fortunately after posting this question, i went back and tweaked my code a bit, and now the buffer works fine.

    best wishes

    janmay 

  • The problem was with the initialization.

    The buffer wont be enabled on start-up. I had to write a "1" to it during initializing and a "0" in the ISR (its an active low enable pin) before i sent any data to make it work.

    best wishes

    janmay

  • Hi janmay,

    glad to hear about your advance. If I were you I'd remove the buffer circuitry completely. As far as I know both the DDS and the MCU can work on 3.3V level thus there is no need to level shift the logic lines.

    kind regards,

    Greg 

  • Hi Greg,

    The "buffer" you are talking about is an Op-amp based buffer, the one i am using is mostly a switch, and yes the thought of removing it crossed my mind, but as its working now, i will let it stay.

    Its also a DIP based chip, so i can always short the terminals, if ever it fails to work.

    Best wishes

    janmay

  • JustGreg said:

    Hi janmay,

    glad to hear about your advance. If I were you I'd remove the buffer circuitry completely. As far as I know both the DDS and the MCU can work on 3.3V level thus there is no need to level shift the logic lines.

    kind regards,

    Greg 

     Hi Greg, I use twin ad9833 and ad9834/9850 on same MSP no buffer at all, just low value resistor in series from MSP to DDS to smooth line spike.

    Line coming from MSP and driving OE of HC244 can also be used as interrupt to open MSP buffer so external buffer has no purpose, level margin of cmos 3.3 and 5 volt threshold leave a small noise margin than supply HC from 3.3 bus, (3.3-2.5-> .8 Volt than 1.8)  and level shifting to 5V can disturb communication between chip too.

     Inserting a series 10-50 Ohm series resistor can reduce spike noises due to line drive from MSP, also some sort of noise filtering if high spectral purity on DDS side, rf and analog guideline but never a crude driver.

     Regards

     Roberto

  • Hi Roberto,

    Are you using the AD9834 to generate a sine wave??

    If yes, Which hex words are you writing to it??

    I am writing 0x2200 as the control word before entering the phase number and the frequency number, is it right??

    I would be grateful if you could list out the steps that you are following to make the AD9834 work, because i am following the steps given in AN-1070 application note from analog devices which is not working for me.

    Thanks and wish you a very happy new year. :-)

    best wishes

    janmay

  •  Hi Janmay, these day i try'd some sort of reordering my stuff but 'am sorry cannot find all module on old project I was working before moving, miss one of 9833 and 9834 module too. Software still is at early stage and 9834 test was initialized as from application note sine wave, I don't remember if it worked or not, 9834 original purpose was to generate sine or triangular wave at frequency greater than 9833. Application was low cost on educational signal generator and SDR so no particular priority is given to.

     I hope some long time has to elapse before I get again in touch with all my stuff.

     I promise test routine and post result asap I find module.

     Regards

     Roberto

  • Hi Roberto,

    Thanks for the reply. Yes, please post the test routine as soon as you get the module.

    Best wishes

    janmay

  • Hi Janmay, I remembered 9833 and 9834 are register level compatible just differ in case and max frequency so I got a close eye to your software and there where mistakes:

     P1SEL has purpose of select peripheral or I/O, in the case drive OE of buffer you need leave P1SEL bit @0 and use P1DIR and P1OUT, so to enable buffer:

     P1SEL &=~0x40; //  pin assigned to I/O

    P1DIR |= 0x40; // out direction

    Disable

      P1OUT |= 0x40;

    Enable

      P1OUT &= ~0x40;

     Try in first fix all these errors, my code was just a test to set some frequency, last attempt was in april I don't remember trouble and frequency was correct and also spectral products where low on both during phase and frequency modulation.

    Regards

     Roberto

  • Hi Roberto,

    Thanks for the suggestion, i will incorporate the changes that you mentioned and try again, thanks.

    best wishes

    janmay

  •  Hi Janmay, this is ok for OE, but you need to do same for every bit you are using of port. You also use some other bit of port 1 and you have to set output too, same for port 2. Port 3 selection exchange from I/O to SPI so that is ok.

     Regards

     Roberto

  • Hi Roberto,

    Thanks for pointing out the possible mistakes in my program. I will make the corrections and run it once again.

    best wishes

    janmay

**Attention** This is a public forum