HSEROUT of array of data with termination on a null


Closed Thread
Results 1 to 19 of 19

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,705


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT of array of data with termination on a null

    or setup printing as a background task and dump your buffer into the queue when its empty

    Code:
    '*****************************************************************
    '*  Name    : PRINT_18_TX_ASM_INT.pbp                            *
    '*  Author  : richard                                            *
    '*  Notice  :                                                    *
    '*          :                                                    *
    '*  Date    :                                                    *
    '*  Version :    18f26K22                                        *
    '*  Notes   :                                                    *
    '*          :                                                    *
    '*                                                               *
    '*****************************************************************  
      
    #CONFIG
      CONFIG  FOSC=INTIO67, PLLCFG=OFF, PRICLKEN=OFF, FCMEN=OFF, IESO=OFF
      CONFIG  PWRTEN=OFF, BOREN=SBORDIS, BORV=190, WDTEN=ON, WDTPS=32768
      CONFIG  CCP2MX=PORTC1, PBADEN=OFF, CCP3MX=PORTB5, HFOFST=ON, T3CMX=PORTC0
      CONFIG  P2BMX=PORTB5, MCLRE=EXTMCLR, STVREN=ON, LVP=OFF, XINST=OFF, DEBUG=OFF
      CONFIG  CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF, WRT0=OFF
      CONFIG  WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTC=OFF, WRTB=OFF, WRTD=OFF, EBTR0=OFF
      CONFIG  EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
    #ENDCONFIG
    
    DEFINE OSC 64
    DEFINE INTHAND do_tx
     
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $24   ' Enable transmit, BRGH = 1
    SPBRG = 130   ' 9600 Baud @ 64MHz, -0.02%
    SPBRGH = 6
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    
    prnb var byte[256]
    rpos VAR BYTE
    empty VAR BYTE
    
    TRISC=%11111111
    OSCCON    = $70   ; 64Mhz
    OSCTUNE.6 = 1     ; Enable 4x PLL 
    while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code 
    ANSELA=0
    ANSELC=0
    intcon=$c0
    empty=1
    
    pause 1000
    hserout ["ready",13,10 ] ;  PROOF OF LIFE
    pause 1000
    
    mainloop:
        if empty then
            ;hserout [13,10]
            arraywrite prnb[240],[13,10,0,"RTIOP12345678"]
            gosub print
        ENDIF
        pause 2000
    goto   mainloop
     
    '  SAMPLE OF RAW BINARY OUTPUT FROM TX PIN IN HEX
    '  0D 0A 00 52 54 49 4F 50 31 32 33 34 35 36 37 38
    '  0D 0A 00 52 54 49 4F 50 31 32 33 34 35 36 37 38
    '  ..............
    
    
    print: 
        rpos = 240   ;FOR TEST START AT INX 240 IE PRINT CHRS  240-255  IN BUFFER
        empty=0
        PIE1.4=1
    return 
     
    asm   
    do_tx
        LFSR 0, _prnb   ; Store buffer ADDR to FSR0H     
        BANKSEL _rpos 
        MOVF   _rpos,W  ; Add rpos to pointer 
        ADDWF   FSR0L,F ; Store Low byte  in FSR0
        BNC  NOV
        INCF    FSR0H ,F
    NOV 
        movf    INDF0,W
        movwf  TXREG   
        INCFSZ  _rpos,F ; Increment  rpos
        BRA    exP      ; if buffer empty turn ofF interrupt
        bcf    PIE1,TXIF
        BANKSEL _empty  ; AND SET FLAG
        BSF   _empty ,0
    exP 
        BANKSEL 0
        RETFIE 
    endasm
    Warning I'm not a teacher

  2. #2
    Join Date
    Aug 2011
    Posts
    460


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT of array of data with termination on a null

    richard's code has some merits, but in almost all cases interrupts just add overhead... they rarely speed things up if that's what you're looking for.

    Here's another version of the code I posted with the array access time buried in the byte transmit time:
    Code:
    i  var     byte
    b  var     byte[256]
    txd var byte
    
    for i = 0 to 255
        ' get byte from the array
        txd = b[i]
        ' wait for TRMT == 1
        while (TXSTA.1 = 0)
        wend
        ' send byte
        TXREG = txd
    next

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT of array of data with termination on a null

    That's great but, at 9600 baud it will be in this routine for 26.5 milliseconds. That's OK if you can afford it...
    Dave Purola,
    N8NTA
    EN82fn

  4. #4
    Join Date
    Aug 2011
    Posts
    460


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT of array of data with termination on a null

    ...trying to offload up to 256 MB of data from a flash chip to VB on laptop over 115.2k BAUD connection.
    At 115K it takes ~22ms to send 256 bytes assuming back to back transfers. At 9600 it's over 10x longer than that.

    You could use background serial transfers while you do something to read that flash chip, but you're going to have to know what you're doing to get all that working.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT of array of data with termination on a null

    you could...... forget hserout, then you can make your data buffer bigger, use longs if your pic can do it.... 18f's, then write data to ram or program mem location that can store more than 256 bytes, then access data knowing starting location and loop through data with TX routine number of chars to send. I have sent 10K bytes at a time serially at 115K over 8266esp
    I would dig up some code if interested in that technique.

Similar Threads

  1. Null statement (NOP or CONTINUE)
    By RussMartin in forum General
    Replies: 8
    Last Post: - 4th February 2009, 22:28
  2. How to get ASCII data in array.
    By Ioannis in forum Serial
    Replies: 8
    Last Post: - 6th November 2008, 21:14
  3. Bit/Byte array for Hserin/Hserout
    By mrx23 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd September 2006, 00:07
  4. 8 data and parity using HSERIN, HSEROUT
    By Smity42 in forum Serial
    Replies: 2
    Last Post: - 3rd April 2006, 02:45
  5. Array data being corrupted
    By caverman in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th March 2006, 05:22

Members who have read this thread : 2

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