Framing error if I disable transmitter after shift register is empty?


Closed Thread
Results 1 to 40 of 46

Hybrid View

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

    Default Re: Framing error if I disable transmitter after shift register is empty?

    as best i can see the data sheet indicates that what u are trying should be ok
    Name:  Untitled.jpg
Views: 5795
Size:  163.2 KB

    could hserout pacing be too slow to buffer tx data, and not really triggering back-back transmissions ?
    if so then the last byte is still not sent yet.

    if you used a decent chip you could make the tx pin open drain and not need this sort of worry
    Warning I'm not a teacher

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

    Default Re: Framing error if I disable transmitter after shift register is empty?

    I'm using a 16F1937, and I've done this successully in the past on this PIC model.

    Check this out, it's always after the last HSEROUT:

    Code:
        TXSTA.5 = 1                     ' TXEN: Transmit Enable bit
        hserout ["1"]
        hserout ["2"]
        hserout ["3"]
        hserout ["4"]
        hserout ["5"]                             
        while TXSTA.1 = 0               ' Check TRMT: Transmit Shift Register Status bit
        wend
    '    TXSTA.5 = 0                     ' <----- Causes Framing error after last byte !
    Name:  Framing error.png
Views: 5839
Size:  45.6 KB
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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

    Default Re: Framing error if I disable transmitter after shift register is empty?

    Quote Originally Posted by richard View Post
    ...could hserout pacing be too slow to buffer tx data, and not really triggering back-back transmissions ?
    if so then the last byte is still not sent yet....
    I thought this would ensure all bytes were transmitted?

    Code:
        while TXSTA.1 = 0
        wend

    Quote Originally Posted by richard View Post
    ...if you used a decent chip you could make the tx pin open drain and not need this sort of worry
    I don't see why a 16F1937 could not do this reliably...?
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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

    Default Re: Framing error if I disable transmitter after shift register is empty?

    The last byte DOES get transmitted.

    Code:
        TXSTA.5 = 1                     ' TXEN: Transmit Enable bit
        hserout ["1"]
        pause 1
        hserout ["2"]
        pause 1
        hserout ["3"]
        pause 1
        hserout ["4"]
        pause 1
        hserout ["5"]                             
        pause 1
        while TXSTA.1 = 0               ' Check TRMT: Transmit Shift Register Status bit
        wend
        TXSTA.5 = 0                     ' <----- Causes Framing error after last byte !

    Something happens when the transmitter is disabled:

    Name:  Framing error a.png
Views: 6536
Size:  61.6 KB


    I compare with my code and wiring on my old test circuit, and I can't see anything different...?
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170

    Default Re: Framing error if I disable transmitter after shift register is empty?

    The Shift register you mentioned is the 2 Bytes Buffer?

    Ioannis

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

    Default Re: Framing error if I disable transmitter after shift register is empty?

    Quote Originally Posted by Ioannis View Post
    The Shift register you mentioned is the 2 Bytes Buffer?

    Ioannis
    I suppose so. This is from the datasheet for TXSTA register:

    bit 1 TRMT: Transmit Shift Register Status bit
    1 = TSR empty
    0 = TSR full
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

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

    Default Re: Framing error if I disable transmitter after shift register is empty?

    It's getting even dumber by the minute.

    TX code on 1st 16F1937:

    Code:
    #CONFIG
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
     __CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF
    #ENDCONFIG
    
    DEFINE OSC 32
    SPLLEN          CON %1              ' PLL enable
    IRCF            CON %1110           ' to enable 8 MHz
    SCS             CON %00             ' system clock determined by FOSC
    OSCCON = (SPLLEN << 7) | (IRCF << 3) | SCS
    
    DEFINE  HSER_RCSTA 90h                          ' Enable serial port & continuous receive
    DEFINE  HSER_TXSTA 24h                          ' Enable transmit, BRGH = 1
    Define  HSER_BAUD 115200
    DEFINE  HSER_CLROERR 1                          ' Clear overflow automatically
    DEFINE  HSER_SPBRGH  0
    DEFINE  HSER_SPBRG  68
    BAUDCON.3 = 1                                   ' Enable 16 bit baudrate generator
    
    ANSELA = %00000000
    ANSELB = %00000000
    'ANSELC = %00000000                      ' ...not available
    ANSELD = %00000000
    ANSELE = %00000000
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %10000000
    TRISD = %00000000
    TRISE = %00000000
    
    BlinkLED                    VAR LatB.5
    
        Pause 200
    
        TXSTA.5 = 1                     ' TXEN: Transmit Enable bit
        hserout [   "[", 1, "]"]                             
        while TXSTA.1 = 0               ' Check TRMT: Transmit Shift Register Status bit
        wend
        TXSTA.5 = 0                     ' <----- Causes Framing error after last byte !
    
    Mainloop:
        BlinkLED = 1
        BlinkLED = 0
        goto mainloop
    end

    RX code on 2nd 16F1937:

    Code:
    #CONFIG
     __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF 
     __CONFIG _CONFIG2, _WRT_OFF & _VCAPEN_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF
    #ENDCONFIG
    
    include "DT_INTS-14.bas"
    include "ReEnterPBP.bas"
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RX_INT,  _ReceiveInterrupt,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    ENDASM
    
    DEFINE OSC 32
    SPLLEN          CON %1              ' PLL enable
    IRCF            CON %1110           ' to enable 8 MHz
    SCS             CON %00             ' system clock determined by FOSC
    OSCCON = (SPLLEN << 7) | (IRCF << 3) | SCS
    
    DEFINE  HSER_RCSTA 90h              ' Enable serial port & continuous receive
    DEFINE  HSER_TXSTA 24h              ' Enable transmit, BRGH = 1
    Define  HSER_BAUD 115200
    DEFINE  HSER_CLROERR 1              ' Clear overflow automatically
    DEFINE  HSER_SPBRGH  0
    DEFINE  HSER_SPBRG  68
    BAUDCON.3 = 1                       ' Enable 16 bit baudrate generator
    
    ANSELA = %00000000
    ANSELB = %00000000
    'ANSELC = %00000000                      ' ...not available
    ANSELD = %00000000
    ANSELE = %00000000                      ' Pin E0 = ADC input
    
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %10000000
    TRISD = %00000000
    TRISE = %00000000
    
    LEDblink            var PORTD.0
    
    RecvData                var BYTE[11]
    
        LEDblink = 0
        goto Start
    
    ReceiveInterrupt:
        hserin [ wait("["), STR RecvData\11\"]" ]
    
        TXSTA.5 = 1
        hserout [   "[", 0, "]"   ]                            
        while TXSTA.1 = 0              ' Check TRMT bit
        wend
        TXSTA.5 = 0
    
    @ INT_RETURN
    
    Start:
        Pause 200                           ' Let PIC and LCD stabilize
        
    @   INT_ENABLE   RX_INT
    
    Mainloop:
        LEDblink = 1
        LEDblink = 0
        GOTO Mainloop
    end

    The RX PIC has the exact same HSEROUT code:
    - enable transmitter
    - transmit data
    - wait until buffer is empty
    - disable transmitter


    DISABLE transmitter causes a FRAMING ERROR on 1st PIC, but not on Ack message on 2nd PIC.

    Name:  Framing error b.png
Views: 6348
Size:  21.7 KB

    This has to be a really stupid error cause there's practically no code left.


    EDIT: Does it make a difference if I disable transmitter inside the Interrupt routine?

    EDIT SOME MORE: I moved the DISABLE out of the ISR and into Mainloop, it didn't make a difference during RX on the 2nd PIC.
    Last edited by Demon; - 23rd September 2024 at 20:35.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  8. #8
    Join Date
    Aug 2011
    Posts
    457

    Default Re: Framing error if I disable transmitter after shift register is empty?

    I'm not sure exactly what you intend to do, but TRMT gets asserted half-way into the STOP bit, so if you immediately disable the TX then the STOP bit will be half the time and generate a framing error.

    The datasheet doesn't really specify that TXEN controls the state of the TX output pin (see datasheet section 25.1.1.1), but if it does return control back to the IO PORTC/TRISC registers then you'd have to make sure that the TX pin (RC6) is set to output high.

    If you want it to be an input/tristate with an external pullup then set TRISC6.

Similar Threads

  1. Trying to emulate shift register
    By RuudNL in forum General
    Replies: 0
    Last Post: - 17th March 2013, 19:57
  2. pic+shift register+lcd
    By eworld in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd October 2012, 05:11
  3. Long shift register
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 18th April 2009, 19:14
  4. Framing Error /w USART
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th February 2007, 01:34
  5. Replies: 15
    Last Post: - 30th January 2005, 03:58

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