CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

rs232 with interrupt on change pin

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ralph79



Joined: 29 Aug 2007
Posts: 87

View user's profile Send private message

rs232 with interrupt on change pin
PostPosted: Wed Feb 05, 2020 8:14 am     Reply with quote

hi all,

I know that is a very strange thing, but for an old control board, I need to have serial communication (receiving and transmitting) in a pin that doesn't have external interrupt or rda interrupt. Basically I need to have 2 serial ports (and the micro just has one in hardware, and I can't use the external interrupt pin).
So my idea is to use the interrupt on change (pin) capability for processing the data.
The micro is the PIC16F1936 and the CCS compiler is v. 5.089.
Code:

#use rs232(baud = 57600,parity=N, xmit = PIN_C6, rcv = PIN_C7, bits=8, stream=PORT_1, errors, restart_wdt)
#use rs232 baud= 38400,parity=N, xmit = PIN_B6, rcv = PIN_B7, bits=8, stream=PORT_BTT, errors, restart_wdt, disable_ints, FORCE_SW)


I have tried with and without FORCE_SW and disable_ints..
Code:
clear_interrupt(INT_RB7_H2L);
enable_interrupts(INT_RB7_H2L);


I have also tried with INT_RB7 and INT_RB (the best configuration until now is INT_RB7_H2L).
Code:
#int_RB
void RB_isr (void)    // function for software uart
{
    int8 ch_port2;
    ch_port2= fgetc(PORT_BTT);
}

#INT_RDA         // rs232 receive data available
void RDA_isr(void)
{
  int8 ch_port1;
  ch_port1= getchar();
   .......
   .....

}

This configuration almost works, but in 20 of 30 bytes it corrupts 1 or 2. So is there any way of getting it to work?
Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Feb 05, 2020 8:34 am     Reply with quote

Problem is that as configured, your 'software' channel takes longer
to receive a character, than the hardware serial. Now while it is servicing
the software RS232, other interrupts can't be serviced, so depending on the
channel timings, if more than one byte of data arrives on the hardware
port while it is servicing the software port, data will be lost.
This will also happen when the software port sends characters as well
Using 'DISABLE_INTS' means that interrupts will be disabled during
the character transmission.
Preferably 'swap' the ports. If using this approach, you always want the
software serial to handle the characters that take the least time.
ralph79



Joined: 29 Aug 2007
Posts: 87

View user's profile Send private message

PostPosted: Wed Feb 05, 2020 10:33 am     Reply with quote

I can't swap the ports.
The most that I can do is lowering the bit rate from the port1 (hardware) to 19200. I can't make anything more.
I have tried to not include the disable_ints option but the result is more or less the same. My system acts like a master and slave. So its not possible to have tx2 and rx2 at same time.
By the way I have the micro at 32MHZ so that I can have time for almost everything. Its just a problem of timing/garbage/bit corruption in one soft serial.
I posted this thread because, I assumed that I was forgetting of some detail in soft interrupt.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Wed Feb 05, 2020 11:22 am     Reply with quote

Yes, the key is that while you are receiving using this approach (and
transmitting if disable interrupts is used), for the whole 'character time',
you can't handle any other interrupt...

Suggestions:

Lowering the hardware rate should help.
Alternative, receive using a timer handler instead. I posted a version a while
ago:

<http://www.ccsinfo.com/forum/viewtopic.php?t=39958&highlight=software+rs232+disturbed+interrupts>

This was coded for 9600bps, but at your processor speed should work to
38400bps, by changing the timer period.
ralph79



Joined: 29 Aug 2007
Posts: 87

View user's profile Send private message

PostPosted: Fri Feb 07, 2020 3:36 am     Reply with quote

I managed to put it working. I had to remove all the things that could interrupt in the middle of the reception. I had to increase the timers interrupt time so that I could give time to my "soft serial" to pick up all the bytes.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group