HSERIN using EUSART RX interrupt - how does it really work?


Results 1 to 8 of 8

Threaded View

  1. #4
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default HSERIN using EUSART RX interrupt - how does it really work?

    Thank you Richard,

    Actually, my program works on a 8MHz basis - it should be more than enough to handle 9600bps serial data, no?

    I'd like to stick to the very basics since I'm not an ultra-programming-geek (just a curious guy). I often heard and read about DT's interrupts but it looks "too much" to me, a least, for my so small projects.


    HSerin [STR SData\5]
    puts your 690 in a blocking loop until 5 characters have been received, no matter how long it takes its not isr material
    Thanks a lot for explaining this.


    As far as I read the DS, the RX buffer can store 2 characters. Starting this thread, my example was using a 5 characters but in fact, I will always have unknown data length (I'll read sms messages) - so let's forget the 5 characters story

    Since you refer to it, why is there a buffer of "2" characters? What's its use?


    This is my latest code I modified to receive 1 character at the time giving the chance of handling variable lenght incoming data:
    Code:
    ' ====== FUSES ====================================================================================
    ' PIC 16F690 Fuses (MPASM)
    @ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
    @ ERRORLEVEL -306
    
    ' ====== REGISTERS =================================================================================
    OSCCON     = %01110000 'Internal RC set to 8Mhz - Register not to be used with XTal
    OPTION_REG = %10000000 'PORT A&B Pull-Ups (look WPUA & WPUB)
    ADCON0     = %00000000 'A/D Module
    ANSEL      = %00000000 'Select analog inputs Channels 0 to 7
    ANSELH     = %00000000 'Select analog inputs Channels 8 to 11
    INTCON     = %11000000 'INTERRUPT Control
    PIE1       = %00100000 'Peripheral Interrupts
    
    ' ====== UART SETTINGS ============================================================================
    RCSTA      = %10010000 ' Enable serial port & continuous receive
    TXSTA      = %00100000 ' Enable transmit, BRGH = 0
    SPBRG      = 12        ' 9600 Baud @ 8MHz, 0.16%
    
    ' ====== DEFINES ==================================================================================
    DEFINE OSC 8
    DEFINE NO_CLRWDT 1   ' Don't waste cycles clearing WDT  
    DEFINE HSER_CLOERR 1 ' Automatic clear overrun error 
    
    ' ====== VARIABLES ================================================================================
    LED     VAR PORTB.6
    SData   VAR BYTE(5)
    Print   VAR BIT
    
    '======= INITIALIZE ===============================================================================
    PORTB.5 = 1         ' set to avoid sending serial data garbage
    Print   = 0
    
    '======= PROGRAM ==================================================================================
    ON INTERRUPT GOTO ISR
    
    MAIN:
        IF PRINT THEN
            HSEROUT [SData]
            Print = 0
        ENDIF    
        GOTO MAIN
    END    
    
    ' ====== INTERRUPT SERVICE ROUTINE ================================================================
        Disable
    ISR:
        PRINT = 1
    	HSerin [SData]
    	Resume
        ENABLE

    Looks like a silly question, but, can I trust this code? Will it work @ 100%? Could something make it hang or stop?

    BTW, thanks for your code - I'm playing with it trying to understand it
    Last edited by flotulopex; - 24th January 2021 at 10:28.
    Roger

Similar Threads

  1. Need help: hserin, serin and serin2 does not work for me
    By PerlNoerd in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd February 2014, 21:09
  2. HSERIN + interrupt
    By tacbanon in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 21st April 2012, 14:37
  3. HSERIN with/without interrupt
    By macinug in forum Serial
    Replies: 3
    Last Post: - 19th January 2009, 17:03
  4. HSERIN doesn´t work
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2007, 14:23
  5. USB and Interrupt - can it work together ?
    By Shamir in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd October 2006, 22:24

Members who have read this thread : 3

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