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.

MSP430 F2132 DCO frequency varies wildly between processors

Other Parts Discussed in Thread: MSP430F2132

We use an MSP430F2132 in two different assemblies.  The firmware for the two boards is different but they use the same clock settings and baud rate.  In both assemblies we are seeing batches of processor that will not communicate correctly.  When debugging the firmware it was found that the factory calibrated DCO settings that are stored in flash do not generate an accurate clock.  Below is the code we use to set a 1 MHz clock and 9600 baud rate (UCAXBR divider of 104 according to processor specs 1 MHz / 9600).

       // this adjusts the DCO's fundemental frequency

       BCSCTL1 = CALBC1_1MHZ;     // Set DCO

       DCOCTL = CALDCO_1MHZ;

       // initialize UART to 9600 baud based on 1 MHz clock / 9600 = 104 (0x68) remainder 1

       UINT8 tbuf;

 

       // set the swrst bit then zero all other bits in the register

       UCA0CTL1 |= UCSWRST;

       UCA0CTL1 &= UCSWRST;

 

       UCA0CTL0 = 0x00;

 

       UCA0CTL1 |= UCSSEL_2;

 

       UCA0BR0 = 0x68;

       UCA0BR1 = 0x00;

 

       UCA0MCTL = 0x00;

 

       UCA0MCTL |= (UCBRS_1 | UCBRF_0);

      

       tbuf = UCA0RXBUF;             // reset any pending interrupt conditions

       tbuf = 0;

       UCA0TXBUF = tbuf;

 

       // now reset UART0's software reset bit to allow opperation

       // this cannot be done until the above registers are initialized

       UCA0CTL1 &= ~UCSWRST;

 

       // enable UART0's receive interrupts

       IE2 |= UCA0RXIE;

This section of code is the same for both board assemblies and there has been a wide variance of clocks ranging from 825KHz to 1.046 MHz.  This causes the baud rate timing to be off and boards that fall too far below 1 MHz cannot communicate.  The only way I can get the failing boards to communicate is to manually tweak UCA0BRx register values.  I am seeing a variance of 86 - 109 in order to fix the boards that are not communicating.  The firmware should be able use a fixed Baud Rate divider across all processors if the clock is stable.  It is not acceptable to have custom firmware on every single board. 

 

  • Normally the calibrated frequencies are good enough for a UART communication, especially at low baudrates like 9600. Did you have a look whether your INFO A memory is still containing the constants. Maybe you have overwritten them during flashing. This can happen if a simple checkbox is enabled somewhere in your IDE.

    These lines

    // set the swrst bit then zero all other bits in the register
    UCA0CTL1 |= UCSWRST;
    UCA0CTL1 &= UCSWRST;

    is the same as

    UCA0CTL1 = UCSWRST;

    and you can also write 104 instead of 0x68 to UCA0BR0 which is easier to read.

    Again

    UCA0MCTL  = 0x00;
    UCA0MCTL |= (UCBRS_1 | UCBRF_0);

    is the same as

    UCA0MCTL = UCBRS_1;

    Clear pending interrupt flags normally isn't done by reading the RXBUF or writing something to the TXBUF. You should clear them by writing to the IFG2 register. I don't know exactly at the moment, but I can remember that clearing pending flags isn't possible while in reset-state (or was it just the USI). But you can clear them after releasing the USCI from reset and BEFORE enabling the interrupt capability for it.

    But I can't see anything wrong with your configuration. I would have a look at the INFO A first.

    Dennis

  • Dennis Eichmann said:
    UCA0CTL1 |= UCSWRST;
    UCA0CTL1 &= UCSWRST;
    is the same as
    UCA0CTL1 = UCSWRST;

    Dennis, the purpose of the two lines with SWRST probably was to set and clear it, in order to 'restart' the USCI. There’s a missing ‘~’ before the second SWRST. Otherwise you’re right, the current outcome is SWRST set and all others cleared. I agree on 104 instead of 0x68, as it is a numerical value connected with 1MHz and 9600Bd, and not with 0xF4240Hz and 0x0x2580Bd :)

    When SWRST is set, no interrupts are pending. All IFG bits are cleared, also all IE bits are cleared. When clearing SWRST, TXIFG gets set (and can be manually cleared if required, but shouldn’t - simply set TXIE only when there is something to send.

  • For me it looked like he wanted to set only the SWRST-bit which he actually does. First setting the bit and then AND the register with only that bit which leads to only SWRST to be set, although some kind of complicated :-)

    BUT if you are right and he wanted to set and reset the bit again to restart the SM, then configuring the USCI while active will maybe cause some problems.
  • You’re right, altering the configuration with SWRST clear is a bad idea. Well, that’s the problem if you see the code but not the intention. (same with code where the comment doesn’t match the code, or when there are just numerical values used instead of symbol, with no comments at all)
  • I was able to recover the clock settings on 1 part but we determined that the other chip must have been flashed wrong. We have swapped the processor at the board house and it works correctly now. Thanks.

**Attention** This is a public forum