PDA

View Full Version : USB HID: Unable to reset USB



psrainey
30th August 2017, 08:13
I am are using the USB HID Demo code from the new samples on a PIC18F2550 and I am experiencing an issue.
If the USB crashes, which it only does occasionally on power up on some computers, I cannot reset the USB except by disconnecting and reconnecting the physical USB connector OR applying an external reset to the processor.
I should point out that it has never been seen to fail once signed on.
I am using the "USBLED" PortC.2 to detect a failure and then when it has failed I attempt a reset. I do not seem to be able to reset the processor although we know that the code is detecting the failure successfully.
I have tried "GOTO 0, ASM RESET, and the Watchdog but the USB routine seems to somehow intercept all attempts at reset.
Any ideas how we can restart the USB routing so that it re-connects after a failure.

Any help or ideas appreciated.


While 1 = 1 ' Create an infinite loop
If USB_tAttached = True Then
GoSub GetSwitches ' ****** Check Ports and set new buffer values if changed ********
If NewButton = 1 Then ' If a port has changed write
HID_WriteArray(Buffer,3) ' Write Data from buffers to USB
NewButton = 0 ' Not a new value anymore!
EndIf
If USBLED = 1 Then
Clrwdt
Toggle PZOLED 'Diag LED
Else
PZOLED = 0
' Delay loop in here to stop it instantly resetting
@ reset
EndIf
EndIf
Wend

Les
30th August 2017, 08:54
A reset on a PIC device does not refresh or reset most of the SFRs, and none of the RAM is flushed etc.

You'll need to disable the USB peripheral using the SFRs, then restart it.

psrainey
30th August 2017, 10:51
I am new to this processor and its USB handling. Do you have any information (or a link) on using SFR's

Your help much appreciated.

towlerg
30th August 2017, 14:04
Quick and dirty, execute a RESET command (actually nor a Basic commend but used in-line as if it were).

psrainey
30th August 2017, 14:33
Thanks guys, I will hopefully have some time later to try the reset. I have a feeling I did try before and it didn't work, but worth trying again.