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 F5438

i need help~~

my external crystal is connect to XT1, and use 24MHz ,i set the register as the flowing code,

 

RESET       mov.w   #SFE(CSTACK),SP         ; Initialize stackpointer
                    mov.w   #WDTPW + WDTHOLD,&WDTCTL; Stop WDT
                   mov.b   #0xff,&P1DIR
                   bis.b   #0x07,&P11DIR           ; P11.2,1,0 to output direction
                   bis.b   #0x07,&P11SEL           ; P11.2 to output SMCLK, P11.1
                                                                       ; to output MCLK and P11.0 to
                                                                       ; output ACLK
                 bis.b   #0x03,&P7SEL            ; Port select XT1
                 bis.w   #SELREF_2,&UCSCTL3      ; FLL Ref = REFO
                bic.w   #XT1OFF,&UCSCTL6        ; Set XT1 On
                bis.w   #XT1DRIVE_3+XTS,&UCSCTL6; Max drive strength, adjust
                                                                                                   ; according to crystal frequency.
                                                                                                   ; LFXT1 HF mode
              mov.w   #SELA_0+SELS_0+SELM_0,&UCSCTL4
                                                                                                 ; Loop until XT1,XT2 & DCO stabilizes
do_while    bic.w   #XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG,&UCSCTL7
                                            ; Clear XT2,XT1,DCO fault flags
            bic.w   #OFIFG,&SFRIFG1         ; Clear fault flags
            bit.w   #OFIFG,&SFRIFG1         ; Test oscillator fault flag
            jc      do_while

mainloop    xor.b   #0x01,&P1OUT      ---------------->  my question is :how can i use 24MHz frequency on my I/O port ???? 
                     jmp      mainloop               ; Loop in place

  • ACLK can be directly output onto P1.0. P1DIR |= 1; P1SEL |= 1.

  • While the answer to your question has been already given (since MCLK cannot be higher than 24 MHz and toggling port pins requires more than 1 MCLK cycle each where you'd need 1/2 cycle to get 24MHz output, so directly using the hardware clock outputs is the only way), your code won't work as expected:

    you clear the OFIFG flags and then test for them. This won't work as expected. After clearing the fault flags, they will stay clear for some time. The fault flags are triggered by sort of retriggerable monoflops. This means a digital gate that remains high for a certain tiem after it has been triggered the last time and then falls to low. The time constant after which the monoflop falls to low and set the fault flag, must be chosen to fit the lowest input frequency that shall be still allowed.

    With 24MHz I guess you're using the 5438A or similar. On the 5438A, the time constant for XT1 in high-frequency mode is between 3.3 and 33 microseconds. So after clearing the fault flag(s), between 3.3 and 33 microseconds (actually even a bit more if the crystal starts oscillating but then fades away) may pass before the fault flag is set again. You'll need to wait this time before checking the fault flag and proceeding. Without waiting, your code would always continue even if there's no crystal at all.

    You're writing in assembly language, so it doesn't apply to you, but I'll write it here anyway:
    Don't use a simple for-loop as delay. It won't work. Optimizing compilers will unroll or even eliminate the loop if it doesn't do anything useful. (executing a no_operation() IS something useful for the compiler). If the loop variable isn't declared volatile (and not a local one), the loop might be partially or completely unrolled anyway. You can setup a timer with the DCOs default frequency to get an at least somewhat reliable delay.

**Attention** This is a public forum