2020/11/19 09:47:41
johndpar
Hi
 
Is it possible to simulate a framing error?
 
I've tried a few things including pulsing the RX pin low for about 2 character times using an Async stimulus and using a Pin/Register Action to force the bit directly, but without success.
 
MPLAB 5.45 on Linux x64
 
Any ideas?
 
Thanks
 
John
2020/11/20 10:04:28
GeorgePauley
The simulator doesn't model the UART at the pin level.  So bouncing the (UART) pins won't do much in the simulator.

You can simply set the FERR signal.  First and easiest way is to put RC1STA in the MPLAB X watch window.  Then, at a time of your choosing, simply set RC1STA.FERR to the desired value inside the watch window. 
 
The short fall of the watch window approach is that you have to manually set a breakpoint and manually set the FERR bit each time.  An alternative approach, though a bit more involved, is to use SCL to set FERR. SCL is a VHDL-like scripting language that is used to automatically inject register and pin values, at user defined points, into a simulator session.  You can find a good user's guide to SCL in the docs sub directory of your MPLAB X installation.  Once you've set up your SCL script to your needs, it will automatically be ran each debug session.
2020/11/20 13:12:39
ric
GeorgePauley
You can simply set the FERR signal.  First and easiest way is to put RC1STA in the MPLAB X watch window.  Then, at a time of your choosing, simply set RC1STA.FERR to the desired value inside the watch window. 

Isn't that what he was trying when he said:
"using a Pin/Register Action to force the bit directly"
2020/11/21 00:19:58
johndpar
Hi George and Ric
Thanks for this. I had tried setting the FERR bit using the Pin/Register Actions, but I'm guessing that that alone will not fire the interrupt.
What I'm trying to simulate is a break condition on the receive line, i.e. a low signal for a couple of character times, which would normally generate a framing error.
This is the beginning of a DMX protocol frame. After the break condition, there is a sequence of bytes.
My code is waiting for the UART interrupt to check the the FERR bit and advance the receive state variable to the next value. The breakpoint in the IRQ handler never fires.
 
I tried setting the FERR bit using the Watches window and the bit just gets cleared again immediately.
 
Any suggestions?
 
Kind regards
John
2020/11/21 00:39:44
ric
The interrupt is triggered by RCIF getting set, not FERR. FERR is just like a parity bit.
So as well as setting the FERR bit, you will need to simulate 0x00 being received as well.
 
2020/11/21 07:46:04
GeorgePauley
Sorry gang, didn't notice the desired interrupt aspect.  Just set the interrupt flag at the same time you set the FERR flag and the interrupt will occur.  Assuming the interrupt is properly enabled, etc.
2020/11/21 13:08:15
johndpar
Great - that worked! Thanks George
I've stepped through the code and all seems good.
Kind regards
John
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account