USB Interrupt

Status
Not open for further replies.

SneaKSz

Member
Hello all,

I want to have an interrupt when data comes in the PIC. I cant see what I"m doing wrong :
initialise:
Code:
	RCONbits.IPEN=1; // interrupt prio enable
	PIE2bits.USBIE=1; // usb IE
	IPR2bits.USBIP=1;//high interrupt
	UIEbits.TRNIE=1;//Transaction Complete Interrupt Enable bit
	UIEbits.ACTVIE=1;
	INTCON = 0b11000000; // GIE and PIE enable

interrupthandler:

Code:
#pragma interrupt YourHighPriorityISRCode
	void YourHighPriorityISRCode()
	{

		if (PIR2bits.USBIF==1){
		LATCbits.LATC3=1;
		PIR2bits.USBIF=0;
		UIRbits.TRNIF=0;
}

Someone can point me my mistake please

Thanks!
 
You have to wait before setting usb Interrupt wait till the PLL to lock. Can't tell if your doing that from your code
 
Hello be80be,

I use the PLLEN , so my xtal frequency is multiplied with 4. ( =48MHz). I'm using the USB microchip framework for low usb pin count. So i didnt have to manual set the bits of the USB registers. I didnt wait for the PLL to lock , I've changed the code now.

Code:
void InterruptHandlerHigh ()
{
	if (PIR2bits.USBIF==1){
		UCONbits.SUSPND = 0;
		while (UIRbits.ACTVIF) { UIRbits.ACTVIF = 0; }
		LATCbits.LATC3=1;
		PIR2bits.USBIF=0;
		UIRbits.TRNIF=0;
		}
}

init :

Code:
	RCONbits.IPEN=1; // interrupt prio enable
	PIE2bits.USBIE=1; // usb IE
	IPR2bits.USBIP=1;//high interrupt
	UIEbits.TRNIE=1;//Transaction Complete Interrupt Enable bit
	UIEbits.ACTVIE=1;//Bus Activity Detect Interrupt Enable bit
	INTCON = 0b11000000; // GIE and PIE enable

The weird thing is that the code doesnt jump to the high interrupt vector. Even when I remove the
'if (PIR2bits.USBIF==1){..}' the PORTC.3 has to light up (led).

main.c
View attachment main.c.txt

Thanks in advance!
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…