USBDemo, something to learn USB a little bit


Closed Thread
Results 1 to 40 of 279

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    interesting. So i can't confirm if it's a MPASM problem (5.06 now) or a PBP V2.46 problem.

    I know they fixed the config fuse problem in 2.47, but can't say if they have only edit the .INC file (LIST line) or they also change something else.

    Anyways, if it's working
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    257


    Did you find this post helpful? Yes | No

    Talking Got CDC driver working!!!

    Mr_E
    Yeah ok well thanks for your input anyway - always welcome I'm happy to edit the the .inc file and leave it at that.

    Great news! I finally got the CDC virtual comport working!!!!!!

    Now I can send data via USB (virtual comport) and out of the Pic 18F4550 USART! and vice versa!

    I'm stoked that this actually works!

    Squib

  3. #3
    Join Date
    Jan 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Good

    Thanks for your sharing!


  4. #4
    Join Date
    Feb 2007
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Nice

    Thanx for share

    I have a problem when I program the PIC with the version of the zip and that I makes all the connection necessary,
    I connect it on the USB and Windows says to me every 3 minutes Unrecognized device

    20MHz
    10nF on pin 18
    resistor 1k5 on pin 23 ?

    what did I wrong?

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    This example use a 4MHz crystal (as stated in the code and in post #1), and i suggest something higher than 220nF and you don't need the 1.5K resistor as i set the internal one.

    Now if you want to stick with the 20MHZ crystal, you'll need to modify the first __CONFIG line to
    Code:
        __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    all should be fine after that.
    Last edited by mister_e; - 22nd February 2007 at 02:24.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    For 20mhz, you also need ...
    Code:
        __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEM_OFF_1H & _IESO_OFF_1H
    DT

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    <table><tr><td></td><td>Newbie mistake from me... At least heaven's voice saved the day </td></tr></table>
    Last edited by mister_e; - 22nd February 2007 at 02:41.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Mar 2007
    Location
    West Hollywood, CA
    Posts
    38


    Did you find this post helpful? Yes | No

    Cool

    This message will now be rendered useless. I wanted to delete it, but since I can't, I've put this stupid line here.
    Last edited by SterlingY; - 14th March 2007 at 02:20.

  9. #9


    Did you find this post helpful? Yes | No

    Thumbs up I am Still Hoping Something Can be Done

    Hi, This really is a nice post, I am going to work with it, i will have to use 18f2550 since it is the available part around here.

    1. Any problem with it being the 2550? someone said "Thank god you didnīt choose the 2550" before.

    2. I guess i`ve read the answer to this but...: Usb Communications require somehow a "master"(host) and a "slave"? if this is so, i would never be able to communicate two pics through USB would I?, where i am going is that i intend to control USB devices but this could never be done if this is true, has anyone figured something without buyign those ugly USB HOST controllers? they really are a pain in the a.. you canīt find them at all(not here).

    I have a uC develpment to control by serial (rS232) port some GSM phones, but the newer models dont support serial but USB, what should be done to transfer data between a uc and them?

    It seems to me like an step backwards the fact that usb had lost the simplicity of RS232 communications in this matter.

    thanks for the hobby time again
    Last edited by Josuetas; - 5th April 2007 at 15:01.

  10. #10
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    89


    Did you find this post helpful? Yes | No

    Default

    Can i use this demo with DasyLab Or Labview ? I using both software from long time for DAQ.
    Thanks

    .

  11. #11
    bj49's Avatar
    bj49 Guest


    Did you find this post helpful? Yes | No

    Thumbs up thanks for the USB demo

    Thanks to Mister_E's USB demo and DT's ints18 and this forum I have my USB board PICF4550@ 48 Mhz running a single DS1820 displaying on VB6 and it took less than 1/2 a day and its stable and fast!

    This is my first post and I would like to congratulate this forum for the information that is available and the generosity of people like mister_e and darren taylor and others for sharing their experience;it is invaluable for me
    This demo should be pinned!

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    I'm able to use Steve's demo along with Darrel's include, but it only works when the MeLabs U2 USB programmer is connected. If I unplug the programmer, the 18F4550 is no longer recognized:

    Code:
    '***************************************************************************
    '*  Name    : USBLabX1_RH.pbp                                              *
    '*  Author  : Steve Monfette/Darrel Taylor/Demon                    *
    '*  Date    : Jan 11 2012                                                  *
    '*  Version : 3.0                                                          *
    '*  Notes   : This is a re-creation of mister-e's USBdemo for DT_HID       *
    '*          : Meant to work with mister-e's GUI                            *
    '*          : Modified for Lab X1                                          *
    '*  Hardware : PIC 18F4550, 20mhz crystal                                  *
    '*           : Lab X1 Experimental Board, 9.5V wall adapter                *
    '*           : MeLabs U2 Programmer v4.32                                  *
    '*  Software : PIC Basic Pro v2.60C                                        *
    '*           : MicroCode Studio Plus v2.2.1.1                              *
    '*           : MPASM WIN Assembler v4.02 (mplab tools/MPASM Suite)         *
    '*  PIC mods : plastic USB connector hot-glued onto top of PIC             *
    '*           : D- wired to C4 (pin 23) directly to top of pins             *
    '*           : D+ wired to C5 (pin 24) directly to top of pins             *
    '*           : two 0.1uF ceramic caps in parallel across VUSB and VSS      *
    '***************************************************************************
    '--- if you use these, you must comment the ones in the .inc file ---
    @   __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H
    @   __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_46_2L & _VREGEN_ON_2L
    @   __CONFIG    _CONFIG2H, _WDT_OFF_2H
    @   __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
    @   __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    
    DEFINE OSC 48
    
    DEFINE  LCD_DREG      PORTD         ' Set LCD data port
    DEFINE  LCD_DBIT      4             ' Set starting data bit
    DEFINE  LCD_RSREG     PORTE         ' Set LCD register select port
    DEFINE  LCD_RSBIT     0             ' Set LCD register select bit
    DEFINE  LCD_EREG      PORTE         ' Set LCD enable port
    DEFINE  LCD_EBIT      1             ' Set LCD enable bit
    DEFINE  LCD_BITS      4             ' Set LCD bus size
    DEFINE  LCD_LINES     2             ' Set number of lines on LCD
    DEFINE  LCD_COMMANDUS 2000          ' Set command delay time in microseconds
    DEFINE  LCD_DATAUS    50            ' Set data delay time in microseconds
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"        ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ; PBP Re-entry for external interrupt
    
    ASM
    INT_LIST  macro    ; IntSource,     Label,   Type, ResetFlag?
            INT_Handler   USB_Handler
            INT_Handler   INT_INT,   _ToggleLED1, PBP,    yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    endasm
    
    @   INT_ENABLE   INT_INT        ; enable external (INT) interrupts
    
    ;--- Setup USB -------------------------------------------------------------
    INCLUDE "DT_HID260.pbp"
    
    DEFINE USB_VENDORID    6017
    DEFINE USB_PRODUCTID   2000
    DEFINE USB_VERSION     1
    DEFINE USB_VENDORNAME  "Mr E/DT/RH"
    DEFINE USB_PRODUCTNAME "USBLabX1"
    DEFINE USB_SERIAL      "001"
    DEFINE USB_INSIZE      8    ;  IN report is PIC to PC (8,16,32,64)
    DEFINE USB_OUTSIZE     8    ; OUT report is PC to PIC
    DEFINE USB_POLLIN      10   ; Polling times in mS, MIN=1 MAX=10
    DEFINE USB_POLLOUT     10
    
    ; --- Each USB status LED is optional, comment them if not used ------------
    ; --- They can be assigned to any pin, and no further action is required --- 
    DEFINE USB_LEDPOLARITY 1       ; LED ON State [0 or 1]  (default = 1)
    DEFINE USB_PLUGGEDLED  PORTD,0 ; LED indicates if USB is connected
    DEFINE USB_TXLED       PORTD,1 ;  "      "     data being sent to PC
    DEFINE USB_RXLED       PORTD,2 ;  "      "     data being received from PC
    
    ;--- Setup ADC -------------------------------------------------------------
    DEFINE ADC_BITS 8  ; Number of bits in ADCIN result
    
        TRISA = %00000011               ' Set port A pins to 6 output, 2 input
        TRISB = %00001111               ' Set port B pins to 4 output, 4 input
                                        ' B0 = External Interrupt
        TRISC = %00000000               ' Set all port C pins to output
        TRISD = %00000000               ' Set all port D pins to output
        TRISE = %00000000               ' Set all port E pins to output
    
    ;--- Variables -------------------------------------------------------------
    Value0      VAR  WORD : Value0 = 0
    Value1      VAR  WORD : Value1 = 0
    DUTY1       VAR  WORD
    DUTY2       VAR  WORD
    LED1        VAR PORTD.3
    WS_CHAR     VAR BYTE
    WS_BYTE     VAR BYTE
    WS_LOOPW    VAR WORD
    ;--- Initialize ------------------------------------------------------------
        ADCON2.7 = 0       ; left justify    (Change this if ADFM in diff register)
        ADCON1 = %00001101     ; AN0 & AN1 analog
        INTCON2 = %00000000    ; Pull-up resistors, falling edge
    
        PORTB = %00000000      ; Set output on keypad to prevent floating pins
    
    
        PAUSE   2000                     ' Wait for USB to initalize
        LCDOUT  $FE,1,"LabX1 18F4550 USB"
        PORTD = 0                       ' Clear LEDs from LCD operations
        ARRAYWRITE USBTXBuffer, ["Lab X1  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        
    ;--- The Main Loop ---------------------------------------------------------
    Main:
        FOR WS_LOOPW = 0 to 1000           ; Check for incomming USB data while waiting
    @       ON_USBRX_GOSUB  _HandleRX
            PAUSE 1
        NEXT WS_LOOPW
        
        ADCIN 0, Value0            ; Send A/D about once/sec
        ADCIN 1, Value1
        ARRAYWRITE USBTXBuffer, [Value0, Value1, PORTD.3, 0, 0, 0, 0, 0]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
    
        GOTO Main
    end
    
    ;---- Receive incoming data PORTB LEDS and CCP PWM dutycycle ---------------
    HandleRX:
        ARRAYREAD  USBRXBuffer,[WS_BYTE, DUTY1.LowByte, DUTY1.HighByte, _
                                        DUTY2.LowByte, DUTY2.HighByte]
        LCDOUT  $FE,$C0,BIN WS_BYTE
        PORTD = 0                       ' Clear LEDs from LCD operations
    return
    
    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
        TOGGLE LED1
        ARRAYWRITE USBTXBuffer, ["Button  "]
        IF Plugged THEN GOSUB DoUSBOut     ; only send when USB is connected
        PORTB = 0               ' Set output on keypad to prevent floating pins
    @ INT_RETURN
    On the Lab X1:
    - PWM logic is not active.
    - buttons 1, 2, 3 and 4 on the keypad activate Port A2 LED.
    - AN 0 and 1 work as expected.

    On the PC:
    - Port B is displayed on the LCD.

    Any idea why Windows XP Home would need the USB programmer connected in order to recognize the PIC?

    Everything works fine if I reconnect the programmer.

    Robert
    Last edited by Demon; - 4th October 2016 at 18:13.

  13. #13
    Join Date
    Dec 2011
    Posts
    4


    Did you find this post helpful? Yes | No

    Default Re: USBDemo, something to learn USB a little bit

    DataToSend's array size is 8. i want to make it 16. i mean i want to send 16 variable at the same time. not 8. can anybody help me?

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 08:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 11:38
  3. Replies: 9
    Last Post: - 31st July 2008, 09:56
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 01:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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