18F2580 with strange behaviour when using Hserin and RX interrupt


+ Reply to Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jul 2024
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 18F2580 with strange behaviour when using Hserin and RX interrupt

    Hi Richard,

    thanks for the help.

    According to the information on the display (when set to show the 4 incoming characters), 2 initial characters are being sent as carriage return (10 and 13) from the terminal.
    That is why it's capturing 4 but i only use the last 2.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,627


    Did you find this post helpful? Yes | No

    Default Re: 18F2580 with strange behaviour when using Hserin and RX interrupt

    Random ramblings and guesses here, take for what it is:

    I'm trying to run a code that when an incoming 2 characters is received, it triggers the interrupt and reads the message.
    That's not how it works. The ISR triggers when there's a byte is received. You can't configure it to fire after n character (short of setting up DMA and using that perhaps).

    Typically, you'd write the interrupt to receive one byte at a time, putting them into a buffer (array) while looking for some sort of qualifier for "end of message" (number of characters, time-out, certain byte sequence, whatever). Once that qualifer is met you set a flag signaling the main rotuine that data is available. LCD updates etc is handled outside of the ISR.

    You say that whatever sends the data sends 10,13 first, then two bytes of interest but you're not looking for the 10,13 sequence in order to "sync" and since you have a lot of slow code in the ISR it might get out of sync and therefor get stuck in the ISR since, once the interrupt fires your code expects 4 bytes.

    If it gets 3 it'll sit there waiting for the 4th. Then a new burst of 4 bytes comes a long, where the first one counts as the 4th. Then the code moves on to to update the display while remaining three incoming bytes overflows the UART buffer because you're updating the display and/or executing a massive PAUSE in the ISR.

    /Henrik.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,721


    Did you find this post helpful? Yes | No

    Default Re: 18F2580 with strange behaviour when using Hserin and RX interrupt

    another issue

    Code:
    OSCCON =% 01110010 '8MHz INTOSC OSCTUNE=% 01000000 '
    
    
    
    
    DEFINE OSC 8
    will enable the PLL making OSC 32MHz

    making the eusart defines incorrect

    and

    the oled display should only be initialised once
    and you dont need to clear the entire screen for every write , just clear the area that needs to be updated
    eg GLCD_CLR 0,1,127,8 ; clear a full width text line
    Warning I'm not a teacher

  4. #4
    Join Date
    Jul 2024
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 18F2580 with strange behaviour when using Hserin and RX interrupt

    Greetings HenrikOlsson and Richard,

    thank you so much for your help.

    I will make a few changes and run some tests to see if I get it running correctly.

    @Richard, regarding the osc settings, yes, you are correct,however, if I change to Define Osc 32 the code will run slower (tested before with pause 1000 and led blink). Weird things happen with this 18F2580 MCU

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,721


    Did you find this post helpful? Yes | No

    Default Re: 18F2580 with strange behaviour when using Hserin and RX interrupt

    if I change to Define Osc 32 the code will run slower (tested before with pause 1000 and led blink). Weird things happen with this 18F2580 MCU
    pll only works with primary clock sources , if you set the int-osc as primary clock then it works as expected

    Code:
    DEFINE OSC 32
    
    
        OSCCON =% 01110000 '8MHz INTOSC 
        OSCTUNE=% 01000000 '
    Warning I'm not a teacher

  6. #6
    Join Date
    Jul 2024
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 18F2580 with strange behaviour when using Hserin and RX interrupt

    Hi Richard,

    you are correct (as always)!
    I thought we had to choose internal insteal of primary since it's set to an internal osc.

Similar Threads

  1. Strange WRITECODE behaviour
    By mikebar in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th December 2015, 01:43
  2. Strange IT behaviour
    By MikeBZH in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th February 2012, 09:00
  3. Strange behaviour
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th October 2009, 22:35
  4. Strange Serout Behaviour
    By bluesmoke in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th August 2009, 04:12
  5. strange int behaviour
    By tom in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th November 2005, 15:41

Members who have read this thread : 10

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