• AVR Freaks

Hot!PIC18F27K42 problems simulating Uart and Interrupts

Author
alexconway
Starting Member
  • Total Posts : 41
  • Reward points : 0
  • Joined: 2009/07/14 08:40:24
  • Location: 0
  • Status: offline
2020/10/20 15:54:12 (permalink)
0

PIC18F27K42 problems simulating Uart and Interrupts

I'm trying out the example at https://www.microforum.cc/blogs/entry/6-using-the-mplab-x-simulator-to-debug-uart-code/
It worked fine using the PIC16F18875 but not with a PIC18F27K42.
I generated a new project (MPLAB X v5.40, XC8 V2.30) for PIC18F27K42 and set it up using MCC with Uart1.
If I un-tick "Enable Uart Interrupts" on the Uart setup then the printf("Hello world\n") works as expected but when I enable the register injection stimulus file the U1RXB never receives anything and the U1RXIF never fires.
If I tick "Enable Uart Interrupts" on the Uart setup and enable interrupts then the printf("Hello world\n") only prints "H", U1TXIF is set but the UART1_Transmit_ISR() never runs. And with the register injection, U1RXB never receives anything and the U1RXIF never fires and the UART1_Receive_ISR() never runs.
I have tried routing RX1 and TX1 to RC7 and RC6 but that doesn't help.
I have tried an asynchronous toggle of RA0 and that works ok.
So it seems that Uart1 receive doesn't work and interrupts for Uart1 don't work.
Am I missing a magic incatation? Project attached
Thanks
Alex
#1

11 Replies Related Threads

    dan1138
    Super Member
    • Total Posts : 3990
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/20 17:19:47 (permalink)
    +1 (1)
    Since Tuesday, July 09, 2019 0:42 PM this is a known simulator bug.

    It seems to affect every PIC18FxxK42 controller simulation model.

    See: https://www.microchip.com/forums/FindPost/1104529

    You could open a support case with Microchip, but from my past experiences I expect to personally observe two spontaneous proton decays before this bug is fixed.
    #2
    ric
    Super Member
    • Total Posts : 28943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/20 17:43:45 (permalink)
    0
    But did the OP submit a Support Ticket back then, or has anyone since?
    I'd like to see a comment by George if the simulator team are aware of it...
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    dan1138
    Super Member
    • Total Posts : 3990
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/20 18:27:31 (permalink)
    +2 (2)
    ric
    But did the OP submit a Support Ticket back then, or has anyone since?
    I'd like to see a comment by George if the simulator team are aware of it...

    I am very disappointed in what George can actually get the Simulation tools group to get fixed.
     
    In my view the group has no time left to address issues with 8-bit controller simulation models that have been released to the market.
     
    To help the Original Poster I have found a hack that gets the UART working with the MPLABX v5.40 simulator.
     
    It requires that the application does not use the interrupt vector table but the "legacy" interrupt handler method. The interrupt manager must be configured with the Single ISR per interrupt box unchecked and a periodic timer interrupt as the lowest priority.
     
    This hack only works because the simulator bug is when the UART assert a service request the vector to the ISR does not occur but when the TIMER asserts a service request it does. The result is that when using the "legacy" interrupt handler method all potential interrupt sources must be checked.
     
    Attached is my proof of concept test code generated using the MCC.
    #4
    alexconway
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2009/07/14 08:40:24
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/21 00:44:49 (permalink)
    0
    Dan1138: That works ok for transmit.
    Have you tried the stimulus to feed data into U1RXB?
    I've tried it briefly with your project and I get the first H of Hello followed by squares.
    When I break into the UART1_Receive_ISR() it seems that RXOIF is always set.
    #5
    dan1138
    Super Member
    • Total Posts : 3990
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/21 14:12:11 (permalink)
    0
    alexconway
    Dan1138: That works ok for transmit.
    Have you tried the stimulus to feed data into U1RXB?
    I've tried it briefly with your project and I get the first H of Hello followed by squares.
    When I break into the UART1_Receive_ISR() it seems that RXOIF is always set.



    There are a lot more "issues" using register injection for the UART.
     
    It's on the raged edge of not working at all.
     
    I can get it to work by making the data file used to inject the data into the U1RXB register do it no faster than 20 milliseconds per packet and just one character per packet.
     
    Attached is my proof of concept project with a file that has pacing that works.
     
    The way the simulator works with this controller is more toy than tool.

    Attached Image(s)

    #6
    ric
    Super Member
    • Total Posts : 28943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/21 14:18:45 (permalink)
    0
    I assume you could speed up the timer interrupt to speed up the UART servicing as well.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    dan1138
    Super Member
    • Total Posts : 3990
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/21 14:25:37 (permalink)
    0
    ric
    I assume you could speed up the timer interrupt to speed up the UART servicing as well.

    I doubt that would work as the TIMER0 period is 1.024 milliseconds.
     
    The UART gets overrun when the register injection delay is 10 milliseconds.
     
    Whatever is bugged in the simulator seems to prevent the UART receive interrupt from being asserted too quickly.
     
    <EDIT>
    The wait times on the register data injection file are based on the instruction frequency selected in the simulator oscillator options page of the MPLABX project properties.
     
    The project I attached has this at 1MHz but I used MCC to set the system oscillator to 64MHz.
     
    The result is that the simulator thinks that TIMER0 is asserting an interrupt request 16 times slower that I thought.
     
    After getting all of the clocks set to the correct frequencies the wait object in the register data injection file can be the time interval of the TIMER0 interrupt rate.
     
    So this isn't a simulator bug just me being confused about where all the controls are.
    post edited by dan1138 - 2020/10/21 15:17:02
    #8
    GeorgePauley
    Moderator
    • Total Posts : 1274
    • Reward points : 0
    • Joined: 2009/12/01 13:59:30
    • Location: Chandler AZ
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/22 15:13:10 (permalink)
    0 (2)
    Hello gang!
     
    First, I can confirm that UART transmit the problem is real.  We have fixed it and it will be available in MPLAB X 5.50.  Possibly sooner if the MPLAB X team has already implemented the ability to download tool data packs (similar to device packs).  I'm still investigating that.

    The simulator team is a bit busy at the moment, and this issue had a few red-herrings that we wasted time chasing after, so it took us a few days to be able to say anything definitive here.

    In post #3 Ric asked a very pertinent question.  And the answer is:  No, the simulator team was unaware of this problem.  The link given in post #2 was not in the simulator forum so we didn't see it.  And it would appear the OP must not have created a support ticket.  Or if he did it didn't get to us.
     
    This issue is almost identical to another issue that arose for PIC16 about a year ago that we fixed.  So it is entirely possible that someone tried to tell us about this PIC18xxk42 issue but we missed it because... "We already fixed that issue." 

    With respect to post #8.  Early on in the simulator effort we recognized that darn near every device had a "unique" oscillator scheme.  The estimated effort for implementing all these oscillators was daunting.  So we opted to just have the user tell us what their resultant Fosc ends up being.  Modelling the various oscillators is still on our "infinitely long list of simulator improvements".  And, of course, packages like MCC are completely unaware that you are using the simulator so they end up further masking the "simulator needs you to tell it Fosc" issue by making you think you've already done everything you need to set up the oscillators.
     
    #9
    alexconway
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2009/07/14 08:40:24
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/22 16:28:34 (permalink)
    0
    As the OP if this thread, I am not the OP of that other thread.
    I was going to raise a support ticket referencing this thread but as GeorgePauley has glided in I guess I don't need to.
    I still can't get my original project to receive anything in U1RXB. Not sure what the magic difference is that dan1138 made that wasn't firing a timer and using non-vectored ISR...
    Thanks
    Alex
    #10
    dan1138
    Super Member
    • Total Posts : 3990
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/22 18:19:54 (permalink)
    +1 (1)
    alexconway
    As the OP if this thread, I am not the OP of that other thread.
    I was going to raise a support ticket referencing this thread but as GeorgePauley has glided in I guess I don't need to.

    You should definitely open a support case on this issue.
    This bug exists in the "just released" MPLABX v5.45 so I attached a project that uses all of the "new" tools.
    alexconway
    I still can't get my original project to receive anything in U1RXB. Not sure what the magic difference is that dan1138 made that wasn't firing a timer and using non-vectored ISR...

    It is finicky in the extreme to get the simulator to run my project in a way that shows the receive interrupt working.
     
    The most likely reason my project fails is the simulator is not doing the register data injection. You will need to create your own stimulus workbook file to attach the register injection data file to the U1RXB register before you build this project the first time.
     
    Please see if the attached project builds and works on your MPLABX setup.
     
    The output should look like this:

    Attached Image(s)

    #11
    alexconway
    Starting Member
    • Total Posts : 41
    • Reward points : 0
    • Joined: 2009/07/14 08:40:24
    • Location: 0
    • Status: offline
    Re: PIC18F27K42 problems simulating Uart and Interrupts 2020/10/23 14:30:34 (permalink)
    0
    Your project works ok, it's mine that won't yet. I meant that I couldn't see anything change in the U1RXIB buffer when I pause the debugger after applying the stimulus, never mind seeing it fire an interrupt or set RXIF or even an error flag, aaanyway...
    Ahh, I had to re-order my Interrupt Vector code to handle the Uart RXIF and TXIF first, before handling the Timer0.
    Now mine <ahem> works, receiving and transmitting. (still in 5.40)
    Cheers
    Alex
    #12
    Jump to:
    © 2020 APG vNext Commercial Version 4.5