Serial and interrupt


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    12

    Default Serial and interrupt

    How do one use a interrupt with the SERIN function? Basically what I'm trying to accomplish is to have a blinking LED and an interrupt on porta.5 - where I retrive a byte and then continue with the main loop.

    Currently my code isn't working as expected. It seems that the interrupt doesn't resume the main program loop after SERIN.

    I'm compiling for pic12f629.

    btw, to be able to do multitasking (updating LEDS and receiving from serial port) do I need to use interrupts?

    Code:
    INCLUDE "modedefs.bas" 'For the Baud Rate modes
    
    char var byte
    
    ON INTERRUPT GOTO myint ' Interrupt handler is myint
    
    INTCON.3 = 1 'PORTA change interupt enabled
    INTCON.7 = 1 'Global interrupt enabled
    IOC.3 = 1
    
    led_on:
    high porta.0
    pause 500
    low porta.0
    pause 500
    goto led_on
    
    ' Interrupt handler 
    DISABLE ' Disable interrupts in handler
    myint: 
    SerIN PORTA.3, T9600, ["b"],char    ' Will be uesed later
    INTCON.0 = 0 'Clear GPIF
    RESUME ' Return to main program
    ENABLE ' Enable interrupts after handler
    
    End

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


    Did you find this post helpful? Yes | No

    Default

    You just don't want to use a Software bit banged solution with interrupt. Move on a PIC with Real Hardware USART and use USART inetrrupt.

    It might be doable with your PIC, but on slower baudrate, using ASM interrupt (maybe instant interrupt), and an home made serial routine. No way this might work 100% properly with ON INTERRUPT even more with internal OSC.

    You could still try something and reduce your delay, using short PAUSEUS loop might work better.

    Using DEBUGIN would also help.

    If you build yourself the Master you could send few garbarge data, then a Synch character, then your data. Says
    SEROUT2 ....[REP 0\32, "~", YourData]

    on the receiver side you just use WAIT("~") ... might work.....
    Last edited by mister_e; - 4th February 2009 at 22:19.
    Steve

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

  3. #3
    Join Date
    Feb 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    The thing is that it's kinda to late to change the pic for my current project

    Well it seems that I will be coding my own serial routine after all...

    In what way is the debugIN function different except the syntax?

    Do you have some more info about instant interrupt? Something to get me started.

    Anyway thanks for the help

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


    Did you find this post helpful? Yes | No

    Default

    DEBUGIN works better on higher baudrate on Slower Speed OSC. Check your manual about that. Syntax is a bit different as well.

    Instant-Interrupt
    http://darreltaylor.com/DT_INTS-14/intro.html
    Steve

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

  5. #5
    Join Date
    Feb 2009
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Before posting posting to this forum I tried "DT_INTS-14" but I got some compailing errors, any idea how to fix them?

    Code:
    wsave3 position request 416 beyond RAM_END 95
    wsave2 position request 288 beyond RAM_END 95
    wsave1 position request 160 beyond RAM_END 95
    Unable to fit variable RS2_Save

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


    Did you find this post helpful? Yes | No

    Default

    open DT_INTS-14.bas file, there you'll find
    Code:
    ' --- IF any of these three lines cause an error ?? ---------------------------- 
    '       Comment them out to fix the problem ----
    ' -- It depends on which Chip you are using, as to which variables are needed --
    wsave1      var byte    $A0     SYSTEM      ' location for W if in bank1
    wsave2      var byte    $120    SYSTEM      ' location for W if in bank2
    wsave3      var byte    $1A0    SYSTEM      ' location for W if in bank3
    So, just modify it as requested
    Code:
    ' --- IF any of these three lines cause an error ?? ---------------------------- 
    '       Comment them out to fix the problem ----
    ' -- It depends on which Chip you are using, as to which variables are needed --
    ;wsave1      var byte    $A0     SYSTEM      ' location for W if in bank1
    ;wsave2      var byte    $120    SYSTEM      ' location for W if in bank2
    ;wsave3      var byte    $1A0    SYSTEM      ' location for W if in bank3
    Steve

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

Similar Threads

  1. Instant Interrupts - Revisited
    By Darrel Taylor in forum Code Examples
    Replies: 772
    Last Post: - 17th February 2016, 22:14
  2. 18F2480 asm interrupt
    By Richard Storie in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th March 2009, 19:40
  3. Serial and Port B interrupt
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th November 2008, 16:22
  4. timer and serial interrupt
    By yourmomOS in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 14th July 2006, 18:02
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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