USBEN turns off automatically if FCMEN or IESO is on
I copied and edited mla HID Bootloader USB codes to use them in my app (MCU: PIC18F14K50).
It works but there are some strange things:
I used "while(mHIDRxIsBusy()) SLEEP();" to enter IDLE mode while waiting for data (IDLEN is set). If I don't send any data for some seconds, device clock stops. I'm sure because a timer toggles LATB (an LED) each 250ms and LED freezes (on or off) after some seconds. It is not suspend mode because my code turns off LEDs (not freeze) while entering suspend.
I tried to use Fail-Safe clock feature to find the problem but it caused even more problem! If I enable FCMEN or IESO, USBEN turns off after about 0.1s. Windows doesn't response to device connection at all. Used "while(1) LATBbits.LATB6 = UCONbits.USBEN;" to read USBEN bit as I don't have debug header.
Does anyone have any idea about the source these problems? If you need, I can upload my project.
I used FCMEN on anther USB project based on mla HID custom on exactly this MCU and it worked fine.