PCINT and SoftwareSerial

Hi,

I'm using Arduino Pro mini 3.3V. I want to use PCINT and SoftwareSerial at the same time. Is it possible?

I have 2 codes. 1st working with PCINT, 2nd working with SoftwareSerial. When I put them together I cant compile the code.

Is there any solution to use PCINT and SoftwareSerial together?

Thx, MM

Is it possible?

No.

PaulS:
No.

That’s interesting. Looking at the code I see that SoftwareSerial grabs all the available PCINTs. I wonder if anyone has ever thought of modifying it to work on a port by port basis, and only grab the PCINT associated with that one port. Say for example something like "SoftwareSerialB (only use PortB pins), SoftwareSerialC, SoftwareSerialD etc.

#if defined(PCINT0_vect)
ISR(PCINT0_vect)
{
  SoftwareSerial::handle_interrupt();
}
#endif

#if defined(PCINT1_vect)
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
#endif

#if defined(PCINT2_vect)
ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));
#endif

#if defined(PCINT3_vect)
ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
#endif

To elaborate on what I said above. Say for example that we wanted to use SoftwareSerial on UNO pins PB4 and PB5 (which needs the PCINT0 vector only). Would it be as simple as modifying the above SoftwareSerial code as follows?

#if defined(PCINT0_vect)
ISR(PCINT0_vect)
{
  SoftwareSerial::handle_interrupt();
}
#endif

/* Comment this section out

#if defined(PCINT1_vect)
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
#endif

#if defined(PCINT2_vect)
ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));
#endif

#if defined(PCINT3_vect)
ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
#endif

*/

to stuart0,

Should we only change SoftwareSerial lib (cut ports we don't use) or PCINT lib as well?

Shamrock123: to stuart0,

Should we only change SoftwareSerial lib (cut ports we don't use) or PCINT lib as well?

Hi Shamrock. I've never modified any libraries, but I know that there are others here who do it regularly.

Basically I'm just saying is that it looks like it should be possible to modify it so that it restricts the choice of possible pins, but only uses some, not all, of the PCINTs. I was hoping that someone with more experience with modifying libraries would chip in and comment on this.

I doubt that you'd need to do anything with the PCINT library, other than just not using the PCINTs already taken by the (modified) SoftwareSerial library. The present problem is that the SoftwareSerial library grabs all of the PCINTs, so that it can be as general as possible in terms of the pins that it can use for rx/tx.

Stuart you can absolutely change the library on a case by case basis. Just make sure that you create a copy of the library, rename the copy to something that makes it yours, modify it as you see fit (make sure to test your code as libraries can be quite complicated and modifications can have unintended consequences), then add your newly modified library into your documents libraries and restart the Arduino IDE. Easy peasy. I might have missed a step in that short description but in summation you and anyone else can easily modify a library if you have the desire, motivation, and skill.

it is really common for libraries to tie up all interrupts because when they write the library the are trying to make it portable and applicable to as many systems as possible They don't know which pcint or hardware interrupts various users are going to use. So they code it to support all possible selections.

It's programming. As long as the hardware can do what you want with enough time and effort you can make software do basically anything you want it to do.

I know this is an old topic but in case someone looks at it and needs help I'll post this.

I just glanced at the cpp and h file for software serial on Arduino. The authors made the handle_interrupt function public so all you should need to do is comment out or delete this section of the cpp

#if defined(PCINT0_vect)
ISR(PCINT0_vect)
{
  SoftwareSerial::handle_interrupt();
}
#endif

#if defined(PCINT1_vect)
ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));
#endif

#if defined(PCINT2_vect)
ISR(PCINT2_vect, ISR_ALIASOF(PCINT0_vect));
#endif

#if defined(PCINT3_vect)
ISR(PCINT3_vect, ISR_ALIASOF(PCINT0_vect));
#endif

then set your interrupts up inside of your code. You can call the software serial interrupt from inside your code. MySerial.handle_interrupt(); or whatever you want to do

I haven't test it but I will in just a second so you will know if that it does work