FwLib_STC8 icon indicating copy to clipboard operation
FwLib_STC8 copied to clipboard

USB Clocking

Open alexpa940 opened this issue 3 years ago • 2 comments

Can USB be clocked from an external oscillator in STC8H8K64U?

alexpa940 avatar Jun 25 '22 15:06 alexpa940

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);

IOsetting avatar Jun 27 '22 04:06 IOsetting

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);

alexpa940 avatar Jun 27 '22 05:06 alexpa940