News:

Let's find out together what makes a PIC Tick!

Main Menu

SINGLE AND DUAL SERIAL TERMINAL

Started by JonW, Today at 11:28 AM

Previous topic - Next topic

JonW

Guys

I have added my serial terminals to the site FREELOADER PAGE

These are single- and dual-terminal, very handy when multiple instances are needed.

Demo here is a PIC18F27J53 serial bridge running at 921600 baud!!, written in Positron Basic.  In the past I have used CCS, simply for the ease of the USB, but can now use Positron.

It is written in the CCS C style to keep it simple: a handful of plain calls (start, bytes waiting, read, write, print) and nothing else to learn. The 27J53's built-in USB appears on the PC as a CDC serial port. Whatever baud rate you select on that port is sent to the PIC by the PC (the CDC line-coding request), and the PIC sets its own UART to match automatically. The data then exits the PIC's UART, passes through a CP2102, and returns to a second port on the PC.

The USB stack is my own, written from the ground up, and I've been working on it for ages (if you remember back): none of the compiler's USB library is used. The UART is read via an interrupt into a 256-byte ring buffer, which lets it keep up at 921600. Tested with 600-byte sends in both directions with no loss.

I've also bought a PID/VID, so I can now build a USB bootloader for the 27J53 and even port the library to the P1429; these devices are cheap, and you can then have a CDC-to-PIC device that you can tweak to your liking. 

Before it's shared, I need to get some answers from Les on memory, etc as I have had to edit the PPI to move the memory allocation about and release more RAM to the user. The current PPI limits user RAM  to 1k for a massive buffer, but IMHO it's not needed.



JonW

Here is a demo of the USB in use, if you are familiar with CCS (I know some are on here), you will notice the similarity..

'****************************************************************************
'*  MWUSB_DEMO_27J53 - a USB serial port on mwave's own stack               *
'*                                                                          *
'*  Board: PIC18F27J53 USB DEV rev 1.0.  Load with FREELOADER, through      *
'*  either bootloader (serial mwboot or the USB one).                       *
'*  Needs MW_USB.inc in the same folder as this file.                       *
'*                                                                          *
'*  The same program as USB_CDC_DEMO_27J53.bas, with the include changed:   *
'*  nothing from the compiler's USB library is used.                        *
'*                                                                          *
'*  Open the USB COM port (the MCU's own connector, USBC2) in a terminal:   *
'*    - every character typed comes straight back                           *
'*    - Enter (CR) also gets a line "ENTER n", n counting up                *
'*  LED4 (RB1) is lit while the PC has the port set up.                     *
'*  The UART (CP2102, 115200) prints one banner line and is not used again. *
'*                                                                          *
'*  Loaded through the USB bootloader, the port has the bootloader's VID /  *
'*  PID, so in the same socket it comes back on the same COM number.        *
'*                                                                          *
'*  STATUS: compiled with Pos8 and ran on the board, flashed and loaded     *
'*  through the USB bootloader: "HELLO" + CR echoed at once, then "ENTER 1".*
'****************************************************************************
    Device = 18F27J53
    Declare Xtal = 48
    Declare Hserial_Baud = 115200               ' UART 1 (RC6 / RC7): the banner only

    Include "MW_USB.inc"                        ' the USB serial port: mwave's own stack

    Dim bWaiting As Byte                        ' bytes waiting from the PC
    Dim bChar    As Byte                        ' the byte in hand
    Dim wEnters  As Word                        ' how many times Enter has been pressed

Main:
    Clear                                       ' all RAM to 0 (as the compiler's own USB samples do)
    ANCON0 = $FF                                ' all pins digital: on the J53 a PCFG bit SET = digital
    ANCON1 = $1F
    TRISC.6 = 0                                 ' UART TX pin an output: REQUIRED on this family
    LATB.1 = 0                                  ' LED4: latch low for good, TRISB.1 switches it
    DelayMS 10

    HRSOut 13, 10, "MWUSB DEMO", 13, 10

    MWUSB_Start()

    Do
        MWUSB_Poll()                            ' every pass: this IS the USB

        If MWUSB_Ready() = 1 Then
            TRISB.1 = 0                         ' LED4 on
        Else
            TRISB.1 = 1                         ' LED4 off
        EndIf

        bWaiting = MWUSB_Waiting()
        If bWaiting > 0 Then
            bChar = MWUSB_Read()
            MWUSB_Write(bChar)                  ' echo
            If bChar = 13 Then
                Inc wEnters
                MWUSB_Text = "ENTER " + Str$(Dec, wEnters) + "\r"
                MWUSB_Print()
            EndIf
        EndIf
    Loop

'***************************************************************************
'*  Configuration - the same as MWBOOT_27J53.bas.  FREELOADER does NOT send *
'*  these (the bootloader's stay); they are used only if this file is       *
'*  programmed directly with a PICkit.                                      *
'***************************************************************************
Config_Start
    WDTEN    = OFF
    PLLDIV   = 4                            ' <-- 16 MHz crystal
    CFGPLLEN = On                           ' PLL on from reset
    STVREN   = On
    XINST    = OFF
    CPUDIV   = OSC1                         ' no CPU divide: 48 MHz
    Cp0      = OFF
    OSC      = HSPLL                        ' crystal + PLL
    SOSCSEL  = Dig                          ' RC0 / RC1 digital
    CLKOEC   = OFF
    FCMEN    = OFF
    IESO     = OFF
    WDTPS    = 32768
    DSWDTOSC = INTOSCREF
    RTCOSC   = INTOSCREF
    DSBOREN  = OFF
    DSWDTEN  = OFF
    DSWDTPS  = G2
    IOL1WAY  = OFF
    ADCSEL   = Bit12
    MSSP7B_EN = MSK7
    WPFP     = PAGE_0
    WPCFG    = OFF
    WPDIS    = OFF
    WPEND    = PAGE_0
    LS48MHZ  = SYS48X8
Config_End



Code size is about half of the CCS equivalent...  The Right screenshot is CCS compile stats, left is Positron

▲