¿ªÔÆÌåÓý

KD8CEC Standalone Source vs Hex missmatch on Pin definitions?


 

Been staring at the source for Ian Lee's standalone S-meter and SWR. See?

In uart_forward.cpp, at line 75 and 78 we have the definition of PINs for passthru of the Nextion protocol from the main processor:

#define TX_PIN 9
#define RX_PIN 8

However, if you look at his explanation at:?

In the illustration, he is clearly using RX pin (D!) for read from the main nano..Output is D9 as specified above.? The pre-compiled Hex files use RX/D1 and D9 so the diagram is correct.

Is this just a difference in the final selection of which pins to use and the source is just out of synch with the pre-generated HEX files? Or is there something more subtle that I am just missing. (I had thought that using RX on a nano was problematical because it is hardwired to the USB connection).

Thanks for any enlightenment you can share.?

73
Mark
AJ6CU


 

OK, to answer my own question....

The code that runs in the second Nano actually *reads* using *Hardware serial* and *writes* using the slimmed down *Software Serial* in the file uart_forward.cpp. The "ah ha!" moment was the seeing in the function "ForwardData (in i2cmeter1.ino) where instead of using SWSerial_Available()>0 he uses Serial.available()>0. And then proceeds to do a recvChar=Serial.read(); (and *not* a SWSerial_Read).? In fact the function SWSerial_Read is never used....? However, SWSerial_Write and SWSerial_Print are used to write the data to the Nextion screen. The definition of the RX_PIN is just an artifact of the slimmed down SoftwareSerial (in uart_forward.cpp) where the SWSerial_Begin initializes both a read and write pin...

I speculate that things were done this way because the hardware serial port on the Nano is shared with the USB? This allows debugging to go out over the Serial console and as long as you don't put anything in the input side of the console, you can use it for Hardware Serial RX and all is well...

Whew!? Learn something new everyday....

73
Mark
AJ6CU


 

Hi Mark,
?
Thanks for the description. Dr. Lee is a very clever and talented programmer. However, I find his code fairly cryptic and, like you, I have to puzzle over why he did some of the things he did. He packed a great deal of capability into the small memory model of the nano. And that is the reason for many of the design decisions that he made.

He has moved on to other projects and hasn't followed up on anything here in a very long time.

Nice to see someone picking up the mantle.

73,
Dean
KK4DAS
?