Other Parts Discussed in Thread: MSP-EXP430FR2355
Tool/software: Code Composer Studio
HI
I am trying to learn how to use functions (beginner in C code). i have written a simple LED toggle code that i am using, to verify that i am actually setting Mclk using the function.
When the function code is embedded directly into main program - leds toggle is fast on my MSP-EXP430FR2355..
When using a function - i have verified using disassembly that code is not embedded and leds toggle slowly.
Attached code:
in file setclk.h:
#ifndef SETCLK_H_
#define SETCLK_H_
extern void setclk (void); // Declaration for Function Set-Clk
#endif /* SETCLK_H_ */
in file setclk.c :
#include <msp430.h>
#include <setclk.h>
extern void setclk (void) // Definition for Function Set-Clk
{
//======== set CPU clock directly by registers for either 16Mhz or 8Mhz. ====================
// Configure one FRAM wait-state as required by the device data-sheet for MCLK operation beyond 8MHz
// must be done before configuring the clock system.
FRCTL0 = FRCTLPW | NWAITS_2; // for up to 8Mhz use FRCTLPW | NWAITS_0 , for Up to 16Mhz use NWAITS_1, for Up to 24Mhz use NWAITS_2
__bis_SR_register(SCG0); // disable FLL to enable writing the registers.
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
CSCTL0 = 0x0000; // Set lowest possible DCOx, MODx ofer: MOD=0 DCO=0
CSCTL1 = DCOFTRIMEN_1 | DCOFTRIM0 | DCOFTRIM1 | DCORSEL_5;// DCOFTRIM=5, DCO Range = 16MHz
CSCTL2 = FLLD_0 + 487; // DCOCLKDIV = 16MHz ; For 8Mhz operation use: CSCTL2 = FLLD_1 + 244; set FLLD=1 result in /2 divider and FLLN=244
// Worst-case settling time for the DCO when the DCO range bits have been changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
// UG for optimization. 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle.
__delay_cycles(250000);
__bic_SR_register(SCG0); // enable FLL
//======== End of set clock directly by registers =============
}
in file main.c :
#include <msp430.h>
#include <setclk.h>
void main(void) {
//==== Variables for Main =============== // if variable outside of main - additional 500 bytes of Flash.
unsigned int i=0;
//==== End of Variables for Main ========
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode to activate previously configured port settings
void setclk (void); // Executing Function Set-Clk
P1DIR |= BIT0 | BIT1 | BIT2; // Set P1.0 to output direction
P6DIR |= BIT6; // Set P6.6 to output direction
while (1) // loop forever the below code
{
// toggle LED with delay
if (i==0) // check for delay value.
{
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
P6OUT ^= BIT6; // Toggle P6.6 using exclusive-OR
i=64000; // start over
}
else
{
i=i-1; // count delay
}
}
}
// ========= End of Main =================
CCS does not produce any errors, rather not including the code of the function.
1) What i have done wrong.
2) Why there are no errors?