Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
Clearing the ACTVIF bit before the internal
hardware is synchronized may not have an effect on
the value of ACTVIF. Additionally, if the USB module
uses the clock from the 96 MHz PLL source, then after
clearing the SUSPND bit, the USB module may not be
immediately operational while waiting for the 96 MHz
PLL to lock. The application code should clear the
ACTVIF flag
 
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.

Latest threads

Back
Top