FwLib_STC8
FwLib_STC8 copied to clipboard
USB Clocking
Can USB be clocked from an external oscillator in STC8H8K64U?
USB peripheral share the same clock source with MCU, so the answer is yes if the MCU is clocked from an external OSC, but if you mean a separate clock source for USB peripheral, the answer is no.
The register USBCLK provides limited control on USB clock.
SFR(USBCLK, 0xDC);
I used a 12 megahertz quartz. The microcontroller itself worked from it. But the USB didn't work with any of the USBCLK settings.
SFRX_ON();
XOSCCR = 0xCCU; //enable external xtal
while((XOSCCR & 0x01U) == 0){}; //wait while xtal ready
CLKDIV = 0x00U;//set divider 1
CLKSEL = 0x01U;//select external xtal
SFRX_OFF();
//SYS_EnableOscillator48M();
USB_SetClockPPL(0x1U);
USB_SetClockSource(USB_ClockSource_12M);