USB has stopped working

General discussion on mikroPascal PRO for PIC32.
Post Reply
Author
Message
bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

USB has stopped working

#1 Post by bobspencerr » 10 Jun 2013 12:26

Me again,
I have been working on a program which uses the Mini32 board and has been communicating with USB quite nicely all along but after a while working on various areas of the code I noticed an error popping up saying that the USB Device has malfunctioned.

I have systematically remmed out all cod not related to the USB and even pasted the functions into the sample file for the MINI32 and to ne avail.
If I load the MINI Polling sample, the chip communicates just fine. I have checked and rechecked the settings and even pasted the whole source into the working sample and then it stops again.
Last edited by bobspencerr on 10 Jun 2013 23:57, edited 1 time in total.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: USB has stopped working

#2 Post by jpc » 10 Jun 2013 12:55

hello Bob, at what speed is data coming in? i see you have several delay_ms() calls in you loop, could it be this is to slow?
From my experience it is also good use to set the IP_level of your interrupt even if this would be the only ISR
Au royaume des aveugles, les borgnes sont rois.

bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

Re: USB has stopped working

#3 Post by bobspencerr » 10 Jun 2013 13:02

Thanks for the reply JPC.
I have used the Interrupt Assistant to create the code for the USB so Im not sure how to use the IP_Level other than specifying the ILevel in the header.
I wouldnt have thought that long delays in the main body of the code word affect the USB interrupt function as it is designed to break out of long code when it occures, isnt it?

Thanks for your input, I appreciate it.

By the way, as I said, I removed all code and left only the main USB functionality and it still didnt work.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: USB has stopped working

#4 Post by jpc » 10 Jun 2013 13:11

it is in fact one of the weaknesses of the interrupt assistant, it does not set the priority level but only informs the compiler on this probably to allow it to decide what registers to save and restore inside the interrupt, it is the users responsability to set the IP_leven accordingly so if you have it declared at IPLevel 7 you should set this before enabling the interrupts in the init-section.
The most readable way is to use something like

Code: Select all

  USBIP0_bit := 1;
  USBIP1_bit := 1;
  USBIP2_bit := 1;
The interrupt will deal with each packet as it arrives but with the long delays might overwrite earlyer packet before it is processed, you would need some extra buffering to solve this.
Au royaume des aveugles, les borgnes sont rois.

bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

Re: USB has stopped working

#5 Post by bobspencerr » 10 Jun 2013 13:21

JPC You sir are a legend.

It fixed it instantly. I cant thank you enough for your help. I have spent three days working on this and you just got it right straight away.

Thank you very much.
:D

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: USB has stopped working

#6 Post by filip » 11 Jun 2013 14:02

Hi,

If you carefully read the Interrupts topic in the Help file, you will see the Interrupt Coding Requirements :
1. Write the Interrupt Service Routine. You may use Interrupt Assistant to easily write this routine.
2. Initialize the module which will generate an interrupt.
3. Set the correct priority and subpriority for the used module according to the priorities set in the Interrupt Service Routine.
4. Enable Interrupts.
Regards,
Filip.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: USB has stopped working

#7 Post by jpc » 11 Jun 2013 15:25

Filip,

it has been suggested before, the interrupt assistant could provide at least a template that suggest the user to fill in these priority bits or even better generate the code for this. The interrupt assistant as it currently exists is a bit misleading as starters think all is done after the assistant pasted the (incomplete) code in their application.
Au royaume des aveugles, les borgnes sont rois.

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: USB has stopped working

#8 Post by LGR » 11 Jun 2013 17:53

I agree with jpc on this. I ran into this same issue a while ago with UART interrupts, and spent a significant amount of time getting to the bottom of it.
If you know what you're doing, you're not learning anything.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: USB has stopped working

#9 Post by filip » 12 Jun 2013 09:24

Hi,

OK, thank you for your suggestion, I will pass it to our developers.

Regards,
Filip.

Post Reply

Return to “mikroPascal PRO for PIC32 General”