Hi all,
I used MCF51JM128 with 8M resonator. It can download firmware with BDM. The following is my code for initial clock.
static void init_clock(void){ /* Assume 12MHz external clock source connected. */ /* In order to use the USB we need to enter PEE mode and MCGOUT set to 48 MHz. Out of reset MCG is in FEI mode. */ /**** Moving from FEI (FLL engaged internal) to PEE (PLL engaged external) mode. */ /* switch from FEI to FBE (FLL bypassed external) */ /* enable external clock source */// MCGC2 = MCGC2_HGO_MASK /* oscillator in high gain mode */// | MCGC2_EREFS_MASK /* because crystal is being used */// | MCGC2_RANGE_MASK /* 12 MHz is in high freq range */// | MCGC2_ERCLKEN_MASK; /* activate external reference clock */ MCGC2 = 0x36; while (MCGSC_OSCINIT == 0) ///<- system will be blocked in here ; /* select clock mode */ MCGC1 = (2<<6) /* CLKS = 10 -> external reference clock. */ |(2<<3); /* RDIV = 2 -> 8MHz/4=2.0 MHz */ /* wait for mode change to be done */ while (MCGSC_IREFST != 0) ; while (MCGSC_CLKST != 2) ; /* switch from FBE to PBE (PLL bypassed internal) mode */ MCGC3=MCGC3_PLLS_MASK | (6<<0); /* VDIV=6 -> multiply by 24 -> 2.0MHz * 24 = 48MHz */ while(MCGSC_PLLST != 1) ; while(MCGSC_LOCK != 1) ; /* finally switch from PBE to PEE (PLL enabled external mode) */ MCGC1 = (0<<6) /* CLKS = 0 -> PLL or FLL output clock. */ | (2<<3); /* RDIV = 2 -> 8MHz/4=2.0 MHz */ while(MCGSC_CLKST!=3) ; /* Now MCGOUT=48MHz, BUS_CLOCK=24MHz */}
System will be blocked in
while (MCGSC_OSCINIT == 0) ///<- system will be blocked in here
How do I solve this problem? Does anyone can give any advice? Thanks a lot.
Regards,
Pogo
解決済! 解決策の投稿を見る。
Is the resonator actually running? Put an oscilloscope on it and make sure you can see an 8MHz waveform.
Your code is waiting for "MCGSC_OSCINIT". Check the macro and make sure that is testing for the "OSCINIT" bit in the "MCGSC" register.
Can you view the rest of the bits in that register? Are they showing anything interesting?
The documentation for that bit says "then this bit is set after the initialization cycles of the crystal
oscillator clock have completed.", so it looks like your oscillator isn't running.
Search for other posts in this forum for the MCF51jm and also for "MCGSC_OSCINIT". There are a few.
Tom
Is the resonator actually running? Put an oscilloscope on it and make sure you can see an 8MHz waveform.
Your code is waiting for "MCGSC_OSCINIT". Check the macro and make sure that is testing for the "OSCINIT" bit in the "MCGSC" register.
Can you view the rest of the bits in that register? Are they showing anything interesting?
The documentation for that bit says "then this bit is set after the initialization cycles of the crystal
oscillator clock have completed.", so it looks like your oscillator isn't running.
Search for other posts in this forum for the MCF51jm and also for "MCGSC_OSCINIT". There are a few.
Tom
Hi TomE,
You got it. We found that the resonator can't work in our board. So we change it and use crystal as oscillator, it works well.
We don't want to use crystal because its size is too big to put it on our board. Do you know how to choose a proper resonator for MCF51JM128?
Thanks a lot.
Regards,
Pogo
> Do you know how to choose a proper resonator for MCF51JM128?
The Resonator Specifications have to match what the MCF51JM128 oscillator can handle.
The Oscillator specs should be in the Data Sheet ...
2.9 External Oscillator (XOSC) Characteristics
They detail series and feedback resistors for different frequencies and drive settings, and it does say "Oscillator crystal or resonator". I'd suggest checking your selection of the "load capacitors". They have to match the Resonator specifications.
The best person to help you out would be someone technical at your Resonator supplier.
You could fiddle with every combination of Range, Drive, Resistors and Capacitors, and you may get it working, but unless you know from theory that you're operation within specifications it could end up being unreliable in production. This happens a lot.
Tom
Hi Folks!
i been trying to configure my board (based on MCF51JM128) to run with external oscillator changing values on MCG module.
i want to use just one frecuency setting, based on minimal requirements for usb comunication (found that MCGOUT frecuency should be 48Mhz to USB module to work properly).
this is the code for standard setting for USB bootloader clock on JM128 framework program.
MCGC2 = 0x36; while(!(MCGSC & 0x02)){}; MCGC1 = 0x98; while((MCGSC & 0x1C )!= 0x08){}; MCGC3 = 0x48; while ((MCGSC & 0x48) != 0x48){}; MCGC1 = 0x18; while((MCGSC & 0x6C) != 0x6C){};
checking all registers for this code, found that at first, external clock is internal clock reference. then, mode changes to PEE.
based on datasheet, MCGC4 has no effect on this mode. im wondering how can i get 48Mhz clock reference with this setting. refering to Table 7-12. MCGOUT Frequency Calculation Options from datasheet, using PEE clock mode, FMCGOUT formula should be (Fext/R)*(M/B). in this case, R=8, B=1, M=48. with 12Mhz external oscillator, Fext/R=1.5Mhz, so is on the range of 1Mhz- 2Mhz. , but FMCGOUT= 72Mhz. Bus frecuency is 36Mhz???
which variable (B, F, M) should i change to get 48Mhz bus frecuency??
should i work on this bus frecuency, or there is a lower frecuency to work with USB module?
i've also working with SPI comunications (uSD interfacing), and UART comunications, so i need to know exactly wich is bus frecuency to change both baud rating.
thank you for your reply.
The USB can only work at 48MHz.
You should start from a working evaluation board that supports USB and copy the crystal frequency it uses and how any demo code sets up the CPU.
The only USB clock source options are in Table 16-35. USB_CTRL Field Descriptions". The only clock you can use is "11 System clock source (MCGPLLSCLK)". So MCGPLLSCLK has to be 48MHz and you then have the option of setting MCGOUT to the external crystal frequency or 48MHz divided by 1, 2, 4 or 8.
" (Fext/R)*(M/B)"
FMCGOUT doesn't matter. The USB runs from MCGPLLSCLK. So you can ignore "B" for now.
R is 2^n, so 1, 2, 4, 8, 16, 32 ...
M is 4*N.
(12/R)*M = 48, so M/R=4. That gives 4/1, 8/2, 16/4 or 32/8.
Fext/R has to be between 1 and 2MHz, so the only one of the above that satisfies that is 32/8.
So R=8, M=32 and set "B" to whatever speed you want the CPU (from MCGOUT) and other peripherals (from BUSCLK, which is MCGOUT/2) to run at.
> i've also working with SPI comunications (uSD interfacing), and UART comunications,
> so i need to know exactly wich is bus frecuency to change both baud rating.
You should write your code so that those modules (and all the timer modules) derive their clock rate and clock divider parameters from a master "#define", or better still, a master global or accessor function that returns the current clock rate in convenient units (MHz usually). That way they can work no-matter what you change the clocking to, and can even handle any on-the-fly clock speed changes that you might make for power saving reasons.
Tom
Hi tom. Thanks for replying!
i took the code from usb bootloader framework routines. also, mi board uses 12Mhz xtal y works fine with usb comunication (usb bootloader).
i will make some changes on the routine.
im a little concerned about getting the precise value of bus clock. so, i want to ensure that baud rate of communication modules is ok.
i0ll try to read master clock frecuency into a function. i've a routine to check master clock using TPM module as pwm and oscilloscope, but found that my readings aren't to much accurate.
i'll post some conclusions later.
Thanks!
Hi Tom.
i got it!!! . both modules (SPI and SCI works pretty good). finally, i got BUSCLK= 24Mhz. FMCCGOUT=48Mhz.
its the first time that this MCU runs at that speed.
i will make some changes on Delay Routines to make work LCD library and SCI2 module.
SPI baud rate is 375Khz to propperly conenct to uSD card.
SCI baud rate is 115200, nice and clean comunication trough FTDI 232 iC.
Thank you so much for your help!
Regards;
Mauricio.