USB, PIC18F2550 and VB


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    I have found that if you put the Gosub DoUSBin routine at the beginning of the code (ie before the Main: routine) then the PIC waits for data transfer and when you send the variables from VB, then it continues with the PICs primary function and uses the variables you sent correctly. This is fine if it is a one of function when you power up the PIC. However, it is not, the PIC will always be powered-up.

    So, if you want to change the variables, then you need to reset the PIC and resend them again using USB.

    I want to get away from using a button for 'programming mode', so in otherwords it doesn't matter at what stage you send the variables from VB without there being a need for user intervention on the PIC side.

    I need to get it out of the loop !!

    Steve

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have you tried something like incrementing a variable in the DoUSBin loop, and exiting once it reaches a certain value?

    DoUSBIn:
    USBBufferCount = USBBufferSizeRX ' RX buffer size
    USBService ' keep connection alive
    X = X + 1
    PAUSEUS 5000 ' 5mS delay
    IF X > ExitVal THEN JumpOut
    USBIn 1, USBBuffer, USBBufferCount, DoUSBIn ' read data, if available
    JumpOut:
    Return
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Thank you so much Bruce, that has been driving me mad for weeks on end. I've been working alot on the other code and kinda working around this, but it works very well indeed now. You're right, it now exits from the loop and back to the main routine. You're a genius !!

    Cheers again.

    Steve

  4. #4
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Having now got that piece of code working it has presented this:

    If you remove power to the PIC and then reconnect, it of course first looks for the USB and data as per the Gosub DoUSBin etc. As at this stage the USB databuffers are empty, ie no data being sent, it stores the EEPROM variables as 0, instead of retaining the previously stored numbers.

    I have come up with this, what i think, long winded solution.

    Where by the top three lines of code read:
    Code:
    Main:
            Gosub DoUSBIN
            Gosub CheckData
            Gosub DoUSBoUT
    And then
    Code:
    CheckData:
        	If USBBuffer[9] = 0 Then
                Read 1, SecondsDelayOut     ' read previously stored
                Read 3, MinutesDelayOut     ' variables from EEPROM
                Read 5, HoursDelayOut       ' before they are blanked            
        	        SecondsDelayOut = SecondsDelay
        	        MinutesDelayOut = MinutesDelay
        	        HoursDelayOut = HoursDelay
                Return  
            Else 
    	        SecondsDelay = USBBuffer[11]
    	        MinutesDelay = USBBuffer[13]
    	        HoursDelay = USBBuffer[15]
    
    	        Write 1, SecondsDelay
    	        Write 3, MinutesDelay
    	        Write 5, Hoursdelay
            EndIf
    Return
    Obvioulsy in VB when i write the data again, i set BufferOut(10) = 1 to write the new variables.

    Is this the easiest way?

Similar Threads

  1. Sending data over USB via VB
    By Tissy in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 12th September 2005, 01:00

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts