Softserial not working with A7 as input

hello,
i have a project with arduino nano where I use Software Serial on pins 11,12 for communication with nextion display.
Other pins are used for digital or analog inputs, all work great, that is until I declare A7 as input - thats when nextion stops receiving data.
I am aware that I do not need to declare pins as inputs, and when I don't declare A7 explicitly as INPUT, it works as desired (as voltage meter).
I tried even with nano disconnected from anything else but nextion and it still stops working after declaring A7.
Any ideas ?

#define v_aku1 A7
pinMode(v_aku1, INPUT); 

Pins A7 and A7 are analog inputs only, they do not have the digital circuitry.

Yes...and?? I am using it as analog input. Software serial works on pins 11 and 12.

If you use pinMode(A7, INPUT); then you are trying to configure as a digital pin which it can't be so don't do it

Software serial is digital, so you cannot use an A6 or A7. It works on 11 and 12 because those are digital pins. A7 can be used as a voltage meter because it is an analog input only. The pinMode function will do nothing to that pin because pinMode only applies to digital.

If I read the original post correctly then SoftwareSerial is on pins 11 and 12 and works OK unless A7 is set to be an INPUT. SS is not being used on A7

Yes that is right.
SoftwareSerial is on pins 11 and 12 and works OK unless A7 is set to be an INPUT. SS is not being used on A7
Sorry for my bad english.
So that's obviously a rookie mistake to declare A7 as input. But how does it work that it locks up the transmission on SS?

Here is the problem. The pinMode function starts out:

void pinMode(uint8_t pin, uint8_t mode)
{
	uint8_t bit = digitalPinToBitMask(pin);
	uint8_t port = digitalPinToPort(pin);
	volatile uint8_t *reg, *out;

	if (port == NOT_A_PIN) return;

Then it modifies I/O registers depending on the value of port and bit. When you pass A7 to the function, it gets the value of port and bit by looking up in a table indexed by the pin. A7 has the value 21. However the tables have only 20 elements. So it reads whatever data is in memory beyond the end of the table. If the value is not NOT_A_PIN (which is defined as 0), the function merrily proceeds to mess up some registers, which just might be configuring pins 11 and 12.

Thank you. That is the answer I was looking for.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.