PORTS Forum

Ports and Interfaces => USB => Topic started by: shantanu on October 19, 2010, 12:09:17 pm

Title: EMI causes software latchup
Post by: shantanu on October 19, 2010, 12:09:17 pm
Hi All,
I am using Jan's Visual Basic code(USBHIDIO) to communicate with PIC18F2550 configured as HID.As such there is no problem in communication & I am able get 2 bytes from the PIC for an indefinite amount of time.But sometimes any electrical appliance(soldering iron,transformer etc.) switched in the vicinity causes the program to latchup & I have to restart VB6 IDE to clear the condition.But , surprisingly ,even under the latched condition there is no problem detected in the device manager which shows the HID device which is "working properly".I have also checked the D+ & D- lines with an oscilloscope during the latched up condition;periodic transactions are present indicating that the PIC is still connected to the Windows.

So , obviously, something needs to be incorporated(quite possibly a timer) in the VB6 routine to prevent the latchup condition.

Can somebody help please?

I am reproducing the part of the code which is being called periodically by the timer(slightly modified from Jan's original code):

Code: [Select]
Private Sub ReadAndWriteToDevice()
'Sends two bytes to the device and reads two bytes back.
'On Error Resume Next
Dim byte_counter As Integer


'If the device hasn't been detected or it timed out on a previous attempt
'to access it, look for the device.
If MyDeviceDetected = False Then
    MyDeviceDetected = FindTheHid
End If

If MyDeviceDetected = True Then
 
    OutputReportData(0) = Asc("a")
    OutputReportData(1) = Asc("q")   
 End If
 
       
    'Write a report to the device
    Call WriteReport
   
    Call ReadReport
   
   
Else
End If

End Sub

Thanks.
Title: Re: EMI causes software latchup
Post by: Jan Axelson on October 19, 2010, 06:15:30 pm
I haven't looked at the VB6 code in some time...I would suggest commenting out the read and write operations and see if you get the same result when you have an open handle but aren't trying to communicate.

My .NET code is more robust and the HID communications aren't that different from VB6, so you might take a look at that example.

Jan