USB to RS232 adapter


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jan 2006
    Location
    Toronto
    Posts
    109

    Default

    Squibcakes: Is it possible to get a copy of the source you have working with the DT interrupts? I greatly apreciate all the help you guys are giving me.

    Thanks.

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

    Talking

    Sure thing brother,

    Play around with the baud rates and see what max data speed you get. 250K would be awesome! but I think some sought of hardware hand shaking is needed to get up to those speeds. Hahaha

    Anyway, first step I think is to increase the buffer size form 1 char to as DT said, about 64 Chars.

    Code:
    '****************************************************************
    
        INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
        INCLUDE "ReEnterPBP-18.bas"     ; Include if using PBP interrupts
    
    '   USB sample program for PIC18F4550 CDC serial port emulation
    
    '   Compilation of this program requires that specific support files be
    '   available in the SOURCE DIRECTORY!!  
    
    '   18F*.BAS	Device header files that use the USB libraries
    '	CDCDESC.ASM	Descriptor file	for CDC	serial demo
    '	JADESC.ASM	Descriptor file	for Jan	Axelson	demo
    '	MOUSDESC.ASM	Descriptor file	for mouse demo
    '	PBPCDC.INF	INF file for the CDC serial driver
    '	USB.TXT		This file
    '	USB18.ASM	USB assembler file
    '	USB18.INC	USB definitions	file
    '	USB18MEM.ASM	USB memory allocation file
    '	USBCDC.BAS	CDC serial demo	BASIC program file
    '	USBDESC.ASM	Include	file for descriptor file
    
    '   You WILL also need to modify the
    '   file USBDESC.ASM so that the only line used is -> include "CDCDESC.ASM"
    
    '   MUST use the 4 MHz xtal for this.
    '   this program receives data via usb virtual port then sends out via serial
    '   usart.
       
        
        '   USART module
        '   ------------
        Define    OSC     48
        DEFINE    HSER_RCSTA   90h
        DEFINE    HSER_TXSTA   20h
        DEFINE    HSER_BAUD    4800
        DEFINE    HSER_CLROERR 1
        
        '   USB module
        '   ----------    
        UCFG    var byte EXT        ' include UCFG register... Yeah Melabs didn't :o(
        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[16]
        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 = 16
        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
    Cheers

  3. #3
    Join Date
    Sep 2006
    Location
    Venezuela - Caracas
    Posts
    48

    Default i don't send to pc data recived from pc

    Data of hserin is ok

    ............
    USBService ' Must service USB regularly

    Cnt = 10
    USBIn 3, Buffer, Cnt, MainLoop

    ' Send to pc data recived from pc
    GOTO OutLoop <---------not work, not send buffer

    GOTO Mainloop
    .........

    Code:
    INCLUDE "modedefs.bas"
    
       ' Configuração
       asm
          __CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L  
                             ;              ;                      ; USB clock source comes from the 96 MHz PLL divided by 2
                             ;              ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
                             ; No prescale (4 MHz oscillator input drives PLL directly)
    
    
          __CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H 
                                   ;                  ;               ; Oscillator Switchover mode disabled
                                   ;                  ; Fail-Safe Clock Monitor disabled
                                   ; XT oscillator, PLL enabled, XT used by USB
          __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 & _CP3_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
    
       Buffer    VAR BYTE[16]
       Cnt       VAR BYTE
       A         VAR BYTE
       B         VAR BYTE
       C         VAR BYTE
    
    
       PIC_TX    VAR PORTC.6     ' Transmit Pin
       PIC_RX    VAR PORTC.7     ' Receive Pin
    
       ADCON1 = 15               ' Set all I/Os to Digital
       INTCON2.7 = 1             ' Disable PortB Pullups         
       CMCON = 7                 ' Disable Comparators
    
       ' Interrupt Settings
       RCON.7 = 0                ' Disable Priority Interrupts, 1 to Enable
    
       ' Enable/Disable Interrupts
       INTCON.4 = 0              ' Disable INT0 (PORTB.0)
       INTCON3.3 = 0             ' Disable INT1 (PORTB.1)
       INTCON3.4 = 0             ' Disable INT2 (PORTB.2)
       INTCON.5 = 0              ' Disable TMR0 (Timmer 0)
    
       INTCON.6 = 1              ' Enable Peripheral Interrupts
       INTCON.7 = 1              ' Enable Global Interrupt Handler
    
       PIE1.4 = 0                ' Disable USART Transmit Interrupt
       PIE1.5 = 1                ' Enable USART Receive Interrupt
       PIE2.5 = 0                ' Disable USB Interrupt
    
       PAUSE 1000
    
       USBInit
    
       ON INTERRUPT GOTO Main_Interrupt_Handler
       ENABLE INTERRUPT
    
    ' Main Program Loop
    MainLoop:
       USBService            ' Must service USB regularly
       
       Cnt = 10
       USBIn 3, Buffer, Cnt, MainLoop
       
       ' Send to pc data recived from pc
       GOTO OutLoop    
       
    GOTO Mainloop
    	
    ' Interrupt Handler
    '-------------------------------------------------------------------------------
       DISABLE INTERRUPT     ' No Interrupts past this point
    Main_Interrupt_Handler:
       ' USART Transmit Interrupt
       IF PIR1.4 = 1 THEN
          PIR1.4 = 0
       ENDIF
    
       ' USART Receive Interrupt
       IF PIR1.5 = 1 THEN
          HSERIN [A, B, C]
     
          Buffer[0] = A
          Buffer[1] = B
          Buffer[2] = C
          Buffer[3] = 13
          Buffer[4] = 10
          Cnt = 4
        
    OutLoop:
          USBService        ' Must service USB regularly
          USBOut 3, Buffer, Cnt, OutLoop
    
          PIR1.5 = 0
       ENDIF
    
    '-------------------------------------------------------------------------------
    IntDone:
       RESUME                ' Return to main program
       ENABLE INTERRUPT
       
    '-------------------------------------------------------------------------------
    END
    ..: Don't worry, be happy :..

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. USB to rs232 emulator
    By Pic2008 in forum USB
    Replies: 0
    Last Post: - 5th March 2010, 15:54
  3. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 20:17
  4. Bafo USB to serial adapter
    By ardhuru in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 29th July 2006, 18:48
  5. USB to Serial Adapter with 9.6v
    By serandre in forum Serial
    Replies: 3
    Last Post: - 10th May 2006, 20:16

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