Usart and interrupt


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

    Default Usart and interrupt

    Hello!
    I have read a lot of discussions about hserin and interrupt, I'm writing a little code to test how usart interrupt is working but... don't work!
    Here is my code:

    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 1200
    DEFINE HSER_CLROERR 1
    GP VAR BYTE ' GP variable
    INTCON.7 = 1
    INTCON.6 = 1 ' Enable interrupt
    PIE1.5 = 1
    '
    LED VAR PORTC.5
    OUTPUT LED
    LED = 1
    on interrupt goto myint
    '
    mainprg:
    PAUSE 1 'only for test
    GOTO mainprg
    '
    DISABLE
    myint:
    LED = 0
    PAUSE 3000
    LED = 1
    WHILE RCIF ' Keep reading until RCIF is clear to flush buffer
    GP=RCREG
    WEND
    RESUME
    ENABLE

    The code put led on, I'm expect to put led off for 3 sec. when I send data to RS232 but don't work.
    The hardware is ok, I try with hserin-hserout and is working, only usart interrupt is not working
    PIC is a 18F452 at 4 Mhz
    Can anyone help me?

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Using these defines does not configure the hardware USART automatically. These USART setup parameters do nothing until you use HSERIN or HSEROUT in your code.

    If you don't use one of these commands, then none of the hardware USART library functions are compiled in your code, and there is no code to use the parameters in the DEFINE statements.

    Place at least one instance of HSERIN somewhere in your code to compile that portion of the hardware USART library with the rest of your program.

    Or manually configure the hardware USART.

    RCSTA = $90 would be the bare minimum. This enables the hardware serial port, and continuous receive. If the port isn't enabled, it can't receive inbound data & generate the interrupt.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Maurizio's Avatar
    Maurizio Guest


    Did you find this post helpful? Yes | No

    Default Ok

    Thanks Bruce for the help, now is working well.
    Regards and thanks again
    Maurizio

  4. #4
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154


    Did you find this post helpful? Yes | No

    Default

    Maurizio, could you share what was your updated code was to make your small program work.

    I am trying to set-up a USART Interupt on a 18F2550.

    Many thanks,

    Steve

Similar Threads

  1. Usart interrupt
    By tht123 in forum mel PIC BASIC
    Replies: 3
    Last Post: - 31st March 2010, 21:30
  2. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 18:14
  3. USART interrupt in PIC16F877A
    By amindzo in forum General
    Replies: 7
    Last Post: - 26th August 2006, 18:51
  4. PIC Basic PRO 16F877 USART Interrupt TX
    By BigH in forum Serial
    Replies: 8
    Last Post: - 9th January 2006, 23:26
  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