Go Down

Topic: PCINT and SoftwareSerial (Read 775 times) previous topic - next topic

Shamrock123

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




PaulS

The art of getting good answers lies in asking good questions.

stuart0

#2
Feb 10, 2017, 03:07 am Last Edit: Feb 10, 2017, 04:13 am by stuart0
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.


Code: [Select]
#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

stuart0

#3
Feb 10, 2017, 03:28 am Last Edit: Feb 10, 2017, 03:29 am by stuart0
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?
Code: [Select]

#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
 
*/

Shamrock123

to stuart0,


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

stuart0

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.

Go Up