Hi all,
Firstly, I have fixed my problem (so the system now works) but I dont know why!
Basically, I have a PIC16 controller with a configuration such that when a character is received on the RX line it will dump that into a buffer in SRAM. I know that the buffer mechanism works because that same code is being used for other things. The UART is configured correctly and I have read all the documentation and errata for the device.
Now here is what I dont understand.
Upon receiving the first character the processor hangs. I cannot debug the system because I am using all IO as IO (none free for the debugger) so I dont know why its latching up. I also noticed that if I disconnect the RX line and then probe that line with an oscilloscope probe it causes the latching of the device. I then added a pull up resistor which fixed the latchup from the probe (but still latches up when a character is sent).
The hang is not being caused by overflow and frame errors as my code (which you will see shortly) addresses those problems.
However, there was a temporary fix (that makes no sense).....
When the PIC hangs, I can reset the chip manually by pulling MCLR down and when I do, the chip spontaneously works again as if nothing ever happened AND characters reception works great! By trial and error I discovered that the error was somewhere around the interrupt code because if I disable the interrupt for UART reception, the chip would not hang when a byte came down the RX line. I then put my ISR code into the main loop to see if the code was at fault but the code worked fine (just meant that the chip would not handle the incoming byte as soon as it had arrived).
So, I have a device that hangs when RCIF is triggered, works after a RESET and works if I disable the interrupt. Eventually, I changed the interrupt code so that the first interrupt to be handled was the RCIF. Magically, it now works (yes, I have other interrupts being checked including timers and CCP).
Here is the old ISR "decider" code - this hangs on RCIF
Here is the new ISR "decider" code - This works great
Firstly, I have fixed my problem (so the system now works) but I dont know why!
Basically, I have a PIC16 controller with a configuration such that when a character is received on the RX line it will dump that into a buffer in SRAM. I know that the buffer mechanism works because that same code is being used for other things. The UART is configured correctly and I have read all the documentation and errata for the device.
Now here is what I dont understand.
Upon receiving the first character the processor hangs. I cannot debug the system because I am using all IO as IO (none free for the debugger) so I dont know why its latching up. I also noticed that if I disconnect the RX line and then probe that line with an oscilloscope probe it causes the latching of the device. I then added a pull up resistor which fixed the latchup from the probe (but still latches up when a character is sent).
The hang is not being caused by overflow and frame errors as my code (which you will see shortly) addresses those problems.
However, there was a temporary fix (that makes no sense).....
When the PIC hangs, I can reset the chip manually by pulling MCLR down and when I do, the chip spontaneously works again as if nothing ever happened AND characters reception works great! By trial and error I discovered that the error was somewhere around the interrupt code because if I disable the interrupt for UART reception, the chip would not hang when a byte came down the RX line. I then put my ISR code into the main loop to see if the code was at fault but the code worked fine (just meant that the chip would not handle the incoming byte as soon as it had arrived).
So, I have a device that hangs when RCIF is triggered, works after a RESET and works if I disable the interrupt. Eventually, I changed the interrupt code so that the first interrupt to be handled was the RCIF. Magically, it now works (yes, I have other interrupts being checked including timers and CCP).
Here is the old ISR "decider" code - this hangs on RCIF
Code:
banksel PIR1
btfsc PIR1, CCP1IF ; Was the PS2 Clock line triggered?
goto ps2Handle ; If it was, handel it!
btfsc INTCON, INTF ; Was the CS pin triggered?
goto csHandel ; Chip select handel
btfsc INTCON, TMR0IE ; Was the interrupt the timer?
goto timerInterrupt ; Sort out the timer
btfsc PIR1, RCIF ; Has a byte been received over UART?
goto uartInterrupt ; Store the byte
goto interrupt.end ;
Code:
banksel PIR1
btfsc PIR1, RCIF ; Has a byte been received over UART?
goto uartInterrupt ; Store the byte
btfsc PIR1, CCP1IF ; Was the PS2 Clock line triggered?
goto ps2Handle ; If it was, handel it!
btfsc INTCON, INTF ; Was the CS pin triggered?
goto csHandel ; Chip select handel
btfsc INTCON, TMR0IE ; Was the interrupt the timer?
goto timerInterrupt ; Sort out the timer
goto interrupt.end ;
Last edited: