USB to COM converter


Closed Thread
Results 1 to 8 of 8
  1. #1

    Question USB to COM converter

    Hi all,
    after I finished our USBMOUSE and USBKeyboard successfully , I try to make usb to com converter so I try USBCDC emulator example , so now I can send from usb to com but I can't recive from COM to our usb so I think there is wrong in Hserin section, if anyone have hint to help me

    here is my code , I use PIC18F4455 with 20MHZ crystal , at baud rate 9600bps
    ' Pic Configuration
    ' =================
    asm

    __CONFIG _CONFIG1L, _USBDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _PLLDIV_5_1L
    __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_ON_1H & _IESO_OFF_1H

    __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
    __CONFIG _CONFIG2H, _WDT_OFF_2H
    __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
    __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L


    endasm


    INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts

    DEFINE OSC 48

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1

    ' USB module
    ' ----------
    UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't (
    ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

    ' ANALOG I/O CONFIG
    ' -----------------
    ADCON1 = 15 ' Set all I/Os to Digital
    CMCON = 7 ' Disable Comparator

    Buffer VAR BYTE[8]
    Cnt VAR BYTE
    B0 VAR BYTE

    ASM
    INT_LIST macro ; IntSource,Label,Type,ResetFlag?
    INT_Handler RX_INT,_SendUsB,PBP,yes
    endm
    INT_CREATE ; Creates the interrupt processor
    INT_ENABLE RX_INT ; enable external (RX) interrupts
    ENDASM

    USBInit

    ' Main Program Loop

    MainLoop:
    USBService ' Must service USB regularly
    Cnt = 8
    USBIn 3, Buffer, Cnt, MainLoop

    HSEROUT [STR Buffer\Cnt]
    GOTO Mainloop

    '---[RX_INT - interrupt handler]------------------------------------------------
    ' PROGRAM COMES HERE WHEN DATA ENTERS THE USART PORT
    SendUsB:
    HSERIN [B0]
    Buffer[0] = b0
    cnt = 1

    OutLoop:
    USBService ' Must service USB regularly
    USBOut 3, Buffer, Cnt, OutLoop

    @ INT_RETURN

  2. #2
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by iugmoh View Post
    HSERIN [B0]
    Buffer[0] = b0
    You HSERIN, but how do you know anything is actually there?
    How do you know that your connections are is good?
    Or that your sending device is working properly?

  3. #3

    Default

    I make a new code to test hserin and hserout , I noted that Hserout working weill but HSERIN not getting any data, I sure that the connection is true but I think that there thing error in code , I don't know

    here is my code:

    ' Pic Configuration
    ' =================
    asm

    __CONFIG _CONFIG1L, _USBDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _PLLDIV_5_1L
    __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_ON_1H & _IESO_OFF_1H

    __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
    __CONFIG _CONFIG2H, _WDT_OFF_2H
    __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
    __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L

    __CONFIG _CONFIG5L, _CP0_ON_5L & _CP1_ON_5L & _CP2_ON_5L
    __CONFIG _CONFIG5H, _CPB_ON_5H
    endasm


    DEFINE OSC 48

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1

    ' USB module
    ' ----------
    UCFG var byte EXT ' include UCFG register... Yeah Melabs didn't (
    ucfg = %00010100 ' enable internal USB pull-up, Full speed USB

    ' ANALOG I/O CONFIG
    ' -----------------
    ADCON1 = 15 ' Set all I/Os to Digital
    CMCON = 7 ' Disable Comparator

    Buffer VAR BYTE[8]
    Cnt VAR BYTE
    B0 VAR BYTE
    output portb.0
    high portb.0
    pause 1000
    low portb.0

    ' Main Program Loop

    MainLoop:
    HSERIN 1000,goo,[B0]
    high portb.0
    goo:
    HSEROUT ["send"]

    GOTO Mainloop
    end

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

    Default

    did you tried without any USB?
    Steve

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

  5. #5
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by mister_e View Post
    did you tried without any USB?
    It always rolls right back to the basics...doesn't it...

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

    Default

    nope.. i haven't talked about led blink yet
    Steve

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

  7. #7

    Question

    Finally I dot it , I make a USB to COM converter cable or COM to USB converter cable and save about 40 $ thanks for all members who help me in my project.

    But in my project I have some notes :
    SEROUT2 PIC_TX,84,["hello",13,10] ; at baud rate 9600 (work)
    SEROUT PIC_TX,84,["hello",13,10] ; at baud rate 9600 (not work)
    SEROUT PIC_TX,T9600,["hello",13,10] ; at baud rate 9600 (work)
    serin rx,T9600,b0 ( work)
    serin rx,T9600,[b0] (not work)

    * configurations for USART will be on osc defined in pbp code not on external crytall
    for example you will get configurations for 9600 at osc=48MHZ not on osc=20MHZ
    does the brackets in serin have any meaning ?

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

    Default

    SEROUT/SEROUT2 baudrate mode are quite different. Both are listed in the manual

    as for the bracket in SERIN... well, the manual also explain the syntax... the code example is also self-explanatory
    Code:
    ' Wait until the character “A” is received serially on Pin1 and put next character into B0
    SERIN 1,N2400,["A"],B0
    SERIN/SEROUT don't use the USART, it's software solution. HSERIN/HSEROUT use the USART.

    And you're right, you use the OSC value for your USART.
    Last edited by mister_e; - 20th April 2008 at 14:24.
    Steve

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

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 20:17
  3. serial to usb converter
    By nicjo in forum Serial
    Replies: 3
    Last Post: - 17th September 2008, 23:52
  4. USB PIC without USB Connection
    By Tissy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th December 2005, 17:39
  5. Serial to USB converter
    By jrt4fun in forum USB
    Replies: 6
    Last Post: - 8th August 2005, 15:14

Members who have read this thread : 1

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