No Data out of RCREG


Closed Thread
Results 1 to 4 of 4
  1. #1
    grayfuse's Avatar
    grayfuse Guest

    Default No Data out of RCREG

    Hello list, I'm new to the forums, but they have been very helpful!

    Perhaps someone can help me with this snag... I'm using Hardware Serial Interrupts on a 18F452 reading in midi data. From the LED I have in the interrupt, I can tell the interrupt is operational, and I know that I'm reading the RCREG register because it clears the RCIF flag allowing main loop to run again.

    Even though these two things are happening, the RCREG variable I'm putting into inByte is showing up as an empty value. Does anyone know why this could be happening? Code is below...

    Code:
    DEFINE OSC 20
    DEFINE HSER_BAUD 31250
    
       On Interrupt Goto myint  ' Define interrupt handler (PBP  Gimme)  
    
       RCSTA =   $90            'didnt want to look up the binary for these ;)
       TXSTA =   $24
       INTCON =  %11000000      ' Enable peripheral interrupts
       PIE1.5 = 1               ' Enable Serial Interrupt
    
    loop:  
    
    LOW led
        'main loop
    Goto loop        
    
    ' INTERRUPT HANDLER
    Disable                         ' PBP Command - No interrupting past this point
        myint:                     ' If we get here, an interrupt has been thrown
           INTCON = 0              ' clear INTCON (maybe redundant)
           
           if PIR1.5 = 1 THEN      ' If Serial Interrupt (for mult interrupts)
              HIGH led
              inByte = RCREG       ' if this clears RCREG, then this will also
                                   ' reset the PIR1.5 flag, therefore allowing
                                   ' main loop to run again
           ENDIF
           INTCON = %11000000      ' Clear external interrupt flag
    
       Resume                      ' Glorified PBP "Return" to main program
    Enable

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    first thing i notice, as you don't use any HSERIN/HSEROUT, i doubt the HSER_BAUD will do something for you so what about if you remove it and use
    SPBRG=39?

    next one have a look to the following link. It could be handy.
    http://www.picbasic.co.uk/forum/show...1&postcount=11

    AND the following could be interesting too.. i just can't remind where i have posted it here. BTW have fun
    Code:
        '
        '   Simple program to handle USART interrupt using PIC16F877 @20MHZ
        '   ===============================================================
        '
        '   This program will Blink a LED on PORTB.0 to show
        '   that the PIC is running.  
        '
        '   This program also allow the user to activate or deactivate 
        '   a LED connected on PORTB.1 pin by sending command from a PC
        '   terminal software using 9600,n,8,1 setting
        '
        '   User command:
        '   =============
        '                1. If character "1" is received => enable the LED
        '                2. if character "2" is received => disable the LED
        '
        '
        DEFINE LOADER_USED 1        ' using bootloader
        DEFINE OSC 20               ' running at 20 MHZ
        
        '    PORT setting
        '    ============
             '
             TRISC=%10000000        ' RC.7 => USART RX pin set to input
                                    ' all other pin set to output
                                    '
             TRISB=0                ' RB<7:0> set to output
        
        '    USART setting
        '    =============
             ' Since we will not use HSERIN/HSEROUT, we must
             ' write directly to internal PIC register
             ' 
             TXSTA=$24              ' enable transmit and SPBRGH=1
             RCSTA=$90              ' Enable USART and continuous receive
             SPBRG=129              ' BAUD RATE = 9600 BAUDS
       
        '    Interrupt definition
        '    ====================
             '
             PIE1.5   =1            ' enable USART receive interrupt
             INTCON.6 =1            ' enable peripheral interrupt
        
        '    Alias definition
        '    ================
             '
             RCIF      var PIR1.5   ' receiver interrupt
             StatusLED var PORTB.0  ' the LED who show a 'running process'
             UserLED   var PORTB.1  ' the LED that user want to control
             
        '    Variable definition
        '    ===================
             '
             Delay     var word     ' 
             DataIn    var byte     ' use to store RCREG content
             Discard   var byte     ' use to erase RCREG register
            
        '    Hardware/software initialisation
        '    ================================
             '
             PORTB=0                ' clear PORTB         
             on interrupt goto USARTInterrupt
            
    Start:
        '    Main program loop that make the user happy to
        '    see a LED flashing to mean that something is 
        '    running 
        '
        toggle statusled
        for delay = 1 to 5000       ' use a loop delay to ensure
          pauseus 5                 ' getting interrupt as fast as
          next                      ' possible
        goto start
        
    
    disable interrupt
    USARTInterrupt:
        '    Here's the interrupt routine who will make the user
        '    much happy by giving him the feeling to have the 
        '    control on the machine when the status of the user
        '    LED will change
        '
        RCSTA=0                     ' Disable serial port AND
                                    ' clear possible error (FERR,OERR)
                                    
        datain=RCREG                ' Get data
                                    
        while RCif                  ' wait untill the RCREG is empty
              discard=RCREG         ' by reading it and store result in a
        wend                        ' don't care variable
                                    
        select case datain          ' What to do with that data???
                                    
               case "1"             ' User selection = 1
                    userled=1       '      => Enable the LED
                                    
               case "2"             ' User selection =2
                    userled=0       '      => disable the LED
                                    
               end select           
        RCSTA=$90                   ' Re-enable the serial PORT AND
        resume                      ' get out of here
    enable interrupt
    So in your code yes you can receive something... is this a valid data? i don't think so. You can even have an interrupt by sending an audio signal or else to your USART. So BaudRate is the main problem... i guess or you don't use any RS-232 inverter like MAX232
    Last edited by mister_e; - 23rd September 2005 at 01:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    grayfuse's Avatar
    grayfuse Guest


    Did you find this post helpful? Yes | No

    Default Thanks!

    That was the problem, thanks a lot! Never took into account the Define was a PBP define that wasn't doing specifically what I needed.

    Thanks again!

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    PBP define will work only if you use HSERIN/HSEROUT. While you don't use them but interrupt, they'll not be considered.

    Thanks to Bruce for this precious discover many times ago !
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 05:47
  2. Nokia 3310 display text
    By chai98a in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th August 2007, 04:39
  3. Big characters on HD44780 4x20
    By erpalma in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 7th January 2007, 03:21
  4. LCD + bar graph
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 5th October 2005, 15:50
  5. Sinus calculating !
    By Don Mario in forum mel PIC BASIC Pro
    Replies: 29
    Last Post: - 29th November 2004, 00:56

Members who have read this thread : 1

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