News:

;) This forum is the property of Proton software developers

Main Menu

Interrupt during RSOut

Started by shantanu@india, Jan 14, 2022, 10:24 AM

Previous topic - Next topic

shantanu@india

Hi,
I generally prefer hardware UART but in a particular case I am forced to use HSEROut and RSOut together.
The program has a more or less heavy interrpt routine.
Do I need to disable the interrupt before executing RSOut and reenable it after it?
I am sending out 6 bytes @9600baud
Regards
Shantanu

JonW

Are you concerned that the buffer may overrun on the Hardware Uart?  Difficult to understand what are asking as we dont know the loading and speed of the hardware uart or if and what's processes in the ISR.

trastikata

I found out in my practice that HW interrupts can cause problems with software asynchronous transfers, depending on UART speeds and interrupt cycles.

Slow UART speeds, fast and low frequency interrupts usually don't cause problems. You can actually calculate the bit length, the interrupt length and frequency, and see if it will affect the UART bit detection.

Therefore whenever I have lengthy interrupts, I usually disable the HW interrupt for the duration of the UART communication, if the program logic allows it.


shantanu@india

This is a 18F24K22 running @16MHz

There are two kinds of hardware interrupts... TMR1 @ 100 msec which has an instruction load of about 50 instruction cycles per interrupt and.... PIR1/USART1 which receives 18 bytes @9600 baud at interval of 3 secs.
The main routine has to respond to the USART1 interrupt by sending out 12 bytes @ 3 secs.
The RSOut periodically sends out data(@ 60 secs) comprising of 6 bytes.
Occassionally, the RSOut packet is getting corrupted.
Regards
Shantanu

JonW

For the timer ISR you can check the time left prior to sending the SW transmit routine.  Once timer is ok you can then disable the Int, send a RSbyte, check the HW Uart buffer and empty if full and then process the next rsout bye etc.  Once done re-enable HW Uarts.

Doesnt the 24k22 have 2 HW Uarts, if so you cant you use them both?


shantanu@india

Yes John two hardware USART's would have been ideal but uart2 pins are engaged otherwise.
Regards
Shantanu

trastikata

Shantanu,

do the HW UART read and write happen entirely in the HW interrupt or they are byte driven? That's to say once the HW UART read/write starts, do you go back and forward to the interrupt at every byte read/sent or you do everything in the interrupt and then go back to the main program?

JonW

Surely if you dont need the second HW uart you can swap the RSout pin and the HW uart, unless you cant change the PCB.

If not you are left at scheduling the rsout around the timer and HW buffer.  Can you increase the baud rates at all or even look at diplexing the HW uart TX to serve both transmit channels, can control with a logic gate or analog switch (3157) gated from the rsout pin?