Jump to content

Recommended Posts

Hello,

 

I am new in the MSP430 world, I just soldered the 32 kHz clock...then I bench tested with a multimeter, was OK. Then, I had  a problem with this code:

 

 

------------

 

#include  <msp430g2553.h>
 
unsigned int currentMinutes, currentSeconds;
 
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
 
BCSCTL1 |= DIVA_3; // ACLK/8
BCSCTL3 |= XCAP_3; //12.5pF cap- setting for 32768Hz crystal
 
P1DIR |= BIT0; // set P1.0 (LED1) as output
P1OUT |= BIT0; // P1.0 low
 
currentMinutes = 0;
currentSeconds = 0;
 
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 512; // 512 -> 1 sec, 30720 -> 1 min
TACTL = TASSEL_1 + ID_3 + MC_1; // ACLK, /8, upmode
 
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
return 0;
}
 
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= BIT0; // Toggle LED
}

 

 

------

 

I'm using:

 

msp430-gcc -g -Wall -Os -mmcu=msp430g2553 -o blink3.elf blink3.c
msp430-objcopy -O ihex blink3.elf blink3.hex
sudo mspdebug rf2500 "prog blink3.hex"
 
 
I don't see any problem with the clock configuration nor the interrupt. After all, you guess well....It does not blink!
 
Could anyone give me a hand please,
 
Crom

 

Share this post


Link to post
Share on other sites

Be sure you're using the LFXT1 crystal for ACLK:

 

BCSCTL3 = LFXT1S_0 | XCAP_3;

 

(or just BCSCTL3 = XCAP_3, rather than BCSCTL3 |= XCAP_3 as you have in there)

 

It should still blink without that though, and it might be the default anyway.  Good practice to force it though.

If it is using VLOCLK for some odd reason, it would blink on the scale of every ~3 seconds or so.

Share this post


Link to post
Share on other sites

Thank for the quick reply Spirilis :)

 

 

I tested both:

 

Trying to open interface 1 on 014
Initializing FET...
FET protocol version is 30394216
Set Vcc: 3000 mV
Configured for Spy-Bi-Wire
Device ID: 0x2553
  Code start address: 0xc000
  Code size         : 16384 byte = 16 kb
  RAM  start address: 0x200
  RAM  end   address: 0x3ff
  RAM  size         : 512 byte = 0 kb
Device: MSP430G2553/G2403
Number of breakpoints: 2
fet: FET returned NAK
warning: device does not support power profiling
Chip ID data: 25 53
Erasing...
Programming...
Writing  142 bytes at c000...
Writing   32 bytes at ffe0...
Done, 174 bytes total
 

But no success, it does not blink at all....any other suggestions??

Share this post


Link to post
Share on other sites

no blink?

 

if the timer doesn't work, the led should be on though

 

 

P1DIR |= BIT0; // set P1.0 (LED1) as output
P1OUT |= BIT0; // P1.0 low

P1.0 had been set to high.

 

if led is not on, may be check jumpers, h/w 1st?

 

Share this post


Link to post
Share on other sites

It is not blinking

Led is on

 

 

 

I thought that if there was a hardware problem it will set back to DCO.

All the default jumpers are on

Do you think that could be a problem with my installation of msp430-gcc

Share this post


Link to post
Share on other sites

Just tested your code in the first post on one of my spare launchpads with a G2553 installed and the micro crystal soldered on.

 

It blinks correctly.

 

Check the BCSCTL registers, I think BCSCTL3, there's a "LFXT1OF" bit you may want to test (OF = Oscillator Fault).  Maybe set P1.6 to the value of that bit after startup; instead of doing LPM3 + GIE, just set GIE and do a while(1) loop copying the LFXT1OF bit to P1.6's LED.  Your crystal might not be soldered right after all.

Share this post


Link to post
Share on other sites

Sorry, I'm a total noob with micro controllers.

 

Do you mean something like this:

 

-------

 

 

#include  <msp430g2553.h>
 
unsigned int currentMinutes, currentSeconds;
 
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
 
BCSCTL1 |= DIVA_3; // ACLK/8
BCSCTL3 = LFXT1S_0 | XCAP_3 | LFXT1OF; //12.5pF cap- setting for 32768Hz crystal
 
P1DIR |= BIT0; // set P1.0 (LED1) as output
P1OUT |= BIT0; // P1.0 low
 
  P1DIR |= BIT6;
 
currentMinutes = 0;
currentSeconds = 0;
 
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 512; // 512 -> 1 sec, 30720 -> 1 min
TACTL = TASSEL_1 + ID_3 + MC_1; // ACLK, /8, upmode
 
_BIS_SR(GIE); // Enter LPM3 w/ interrupt
 
while(1){
 
P1OUT |= LFXT1OF;
}
return 0;
}

Share this post


Link to post
Share on other sites

xtals are tricky, u might want to ground the "shell" also.

 

the ti code examples contains code to test whether there is fault w/ the oscillator. i include it below in case u don't have it and u can do a quick test.

 

u need watchdog timer and when there is oscillator fault, it will trigger nmi and u can do things.

 

in one of my projects i would "test" if clock xtal is present and use it, or if not present, i would enable VLO.

 

 

 

 msp430x20x3_LFxtal_nmi.c 
 

 

 

 

//******************************************************************************
//  MSP430F20xx Demo - LFXT1 Oscillator Fault Detection
//
//  Description: System runs normally in LPM3 with WDT timer clocked by
//  32kHz ACLK with a 1x4 second interrupt. P1.0 is normally pulsed every
//  second inside WDT interrupt. If an LFXT1 oscillator fault occurs,
//  NMI is requested forcing exit from LPM3. P1.0 is toggled rapidly by software
//  as long as LFXT1 oscillator fault is present. Assumed only LFXT1 as NMI
//  source - code does not check for other NMI sources.
//  ACLK = LFXT1 = 32768, MCLK = SMCLK = Default DCO
//
//  //*External watch crystal on XIN XOUT is required for ACLK*// 
//
//
//           MSP430F20xx
//         ---------------
//     /|\|            XIN|-
//      | |               | 32kHz
//      --|RST        XOUT|-
//        |               |
//        |           P1.0|-->LED
//
//  M. Buccini / L. Westlund
//  Texas Instruments Inc.
//  September 2005
//  Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
//******************************************************************************


#include <msp430x20x3.h>
volatile unsigned int i;


void main(void)
{
  WDTCTL = WDT_ADLY_1000;                   // WDT 1s interval timer
  IE1 |= WDTIE;                             // Enable WDT interrupt
  P1DIR = 0xFF;                             // All P1.x outputs
  P1OUT = 0;                                // All P1.x reset
  P2DIR = 0xFF;                             // All P2.x outputs
  P2OUT = 0;                                // All P2.x reset
// An immedate Osc Fault will occur next
  IE1 |= OFIE;                              // Enable Osc Fault


  while(1)
  {
   P1OUT ^= 0x01;                           // Toggle P1.0 using exclusive-OR
  _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/interrupt
  }
}


#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer (void)
{
    _BIC_SR_IRQ(LPM3_bits);                 // Clear LPM3 bits from 0(SR)
}


#pragma vector=NMI_VECTOR
__interrupt void nmi_ (void)
{
  do
  {
    IFG1 &= ~OFIFG;                         // Clear OSCFault flag
    for (i = 0xFFF; i > 0; i--);            // Time for flag to set
    P1OUT ^= 0x01;                          // Toggle P1.0 using exclusive-OR
  }
  while (IFG1 & OFIFG);                     // OSCFault flag still set?
  IE1 |= OFIE;                              // Enable Osc Fault
}

Share this post


Link to post
Share on other sites

Thanks SimpleAVR, I was not aware of that code. Could you please tell me where I could get this and similar troubleshooting examples. I have done quiet a research, but I was getting a bit frustrated.

 

I run that code and the BIT0 (red led) keeps on blinking, this code is far out my knowledge...does it mean that I have an Oscillator fault?

I'm really sorry, but what do you mean with the xtal not present?

Share this post


Link to post
Share on other sites

let me explain the code

WDTCTL = WDT_ADLY_1000;                   // WDT 1s interval timer

this sets the watchdog timer to trip every 1000ms or 1sec.

 

so if u see led blinks at 1 sec rate, it means xtal is good.

 

if it blinks a lot quicker, it would be caused by the NMI (non-maskable interrupt), generated by the OSCFault condition, inside the _nmi() interrupt handler.

 

 

this application is a very good example on what the watchdog timer is designed for. u use the timer interrupt to "acknowledge" the working condition (blink every second).

 

looks like there are many code examples here now.

 

http://www.ti.com/lsds/ti/microcontroller/16-bit_msp430/msp430_software_landing.page

 

the one i am using is slac164 in the msp430f2xx folder or something.

 

 

these are very good to learn the features of the devices and is very easy to run.

 

if it's OSCFault, try to examine your soldering, or google image of how other people solder their xtals.

 

/EDIT make sure you solder the shell / skin / case of the supplied crystal on to the PCB. it makes a difference. also, don't substitute the TI supplied crystal w/ a cheap clock crystal, it may not work.

Share this post


Link to post
Share on other sites

Wow, you don't know how impressed with this forum...thanks for the help

 

I only have a 16 MHz clock, standard form factor. Also the previous one had 3 solder joints, the third one on the case....this one only 2, but i guess that there is not need to connect the shell to the 3rd pad.(???)

 

I can see in the documentation that i can, so now I'm going to solder and try to decipher msp4302553.h to configure it.

Any tips are very welcome!! :]

Share this post


Link to post
Share on other sites

Now I don't get it...I Placed the 16MHz clock and solder, plug and upload. The blink still quiet fast

I'm setting the multimeter on continuity to verify leaks between legs and shell and it is OK, no leaks.

 

Am I missing something?

Share this post


Link to post
Share on other sites

a "crystal" is only supported at low speeds like the 32.768kHz... for a 16MHz clock, you will have to use a oscillator, the MSP doesn't support high speed crystals until the newest g2955 ones  which are SMD only right now.

Share this post


Link to post
Share on other sites

My bad...lol...I deserve a damn foreigner to myself, is my problem reading "," and "."

Yes, 16KHz dahhhhhhhhhh.....hahahah thanks

 

SO rephrasing:

 

Now I don't get it...I Placed the 16KHz clock and solder, plug and upload. The blink still quiet fast

I'm setting the multimeter on continuity to verify leaks between legs and shell and it is OK, no leaks.

 

Am I missing something?

:}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...