Welcome! Log In Create A New Profile

Advanced

TX/RX on J19 socket

Posted by rogerinhawaii 
TX/RX on J19 socket
June 03, 2024 03:06PM
The Einsy/Rambo board that Marlin firmware typically runs on has a J19 socket that includes TX and RX pins.

Under what circumstances does the Marlin firmware send and receive messages via those pins?

Is there something that needs to be set up in order to get those pins to be used for messages over those pins?

When Marlin IS set up to use those pins for messages, what class or object within Marlin is used for sending/receiving messages via those pins (e.g. MarlinSerial)?
VDX
Re: TX/RX on J19 socket
June 03, 2024 06:39PM
AFAIK, this is a RaspberryPi header - so look into related infos


Viktor
--------
Aufruf zum Projekt "Müll-freie Meere" - [reprap.org] -- Deutsche Facebook-Gruppe - [www.facebook.com]

Call for the project "garbage-free seas" - [reprap.org]
Re: TX/RX on J19 socket
June 03, 2024 11:36PM
Marlin serial is a complicated thing...

Most serial ports are setup by enabling the UART

ie
#define SERIAL_PORT {0-3 for a mega2560)
#define SERIAL_PORT_2 {0-3 for a mega2560)
#define SERIAL_PORT_3 {0-3 for a mega2560)

On the Einsy-Rambo
0 is wired to the Atmega32u2 for usb
1 is wired to J19
2 is wired to P3
3 is wired to P2

So all marlin needs is #define {next unused serial port eg} SERIAL_PORT_2 1

Those pins are now capable of sending and receiving G-code

Its is however not designed for a non gcode data.

Edited 2 time(s). Last edit at 06/03/2024 11:51PM by Dust.
Re: TX/RX on J19 socket
June 03, 2024 11:53PM
Excellent. Thank you for replying.

That info looks good, I'll give it a try.

Doing that
#define SERIAL_PORT_2 1
will make it so that any call to MarlinSerial, like
MarlinSerial::println("Hello world");
will send it out to the TX pin on J19.

Right?

I had searched all over, and got all sorts of suggestions, tried them all and nothing worked.

I even gave ChatGPT and Copilot a try. Again, all sorts of different (supposedly informed) directions and none that worked.

One related question, before I try your info:
One suggestion I came across was to go to the Settings screen on the Prusa and set the RPI Port to "ON".
That didn't have any impact. But might it be necessary for accessing the J19 TX and RX pins when doing the:
#define SERIAL_PORT_2 1
?
Re: TX/RX on J19 socket
June 04, 2024 12:37AM
no, by default

Gcode is designed to respond to inputs on that uart

you send a gcode to uart 0, it reply's on uart 0
you send a gcode to uart 1, it reply's on uart 1


You have to use PORT_REDIRECT to bypass this standard behaviour

Take a look at how M118 is implemented Marlin/src/gcode/host/M118.cpp

Allows you to send a message to any port

Edited 1 time(s). Last edit at 06/04/2024 12:37AM by Dust.
Re: TX/RX on J19 socket
June 04, 2024 06:48PM
I'm looking at MarlinSerial.h and it has a section with ...

#if !defined(SERIAL_PORT)
#define SERIAL_PORT 0
#endif

I can certainly follow that with what you're suggesting, namely:

#define SERIAL_PORT_2 1

but I also did a search throughout the entire set of source files for the firmware, and SERIAL_PORT_2 is not referenced anywhere.

There is an immediately following section that has:

// The presence of the UBRRH register is used to detect a UART.
#if ((SERIAL_PORT == 0 && (defined(UBRRH) || defined(UBRR0H))) || \
(SERIAL_PORT == 1 && defined(UBRR1H)) || \
(SERIAL_PORT == 2 && defined(UBRR2H)) || \
(SERIAL_PORT == 3 && defined(UBRR3H)))
#define HAS_UART
#endif

which seems to indicate that the name SERIAL_PORT can be defined for any of the possibilities you mentioned, 0, 1, 2, or 3 as:

0 is wired to the Atmega32u2 for usb
1 is wired to J19
2 is wired to P3
3 is wired to P2

So, maybe I should be redefining just SERIAL_PORT, and not a new SERIAL_PORT_2, with

#define SERIAL_PORT 1

Yes, No ??

You also just today sent more info about using the ports for passing GCodes.

Actually, I am NOT passing GCodes. I'm passing unique messages of my own design.

I've added some extra hardware to my Prusa and want that hardware to be controlled by an Arduino that I'm connecting
to the J19 TX and RX pins. At the point in the firmware where I want to tell the Arduino what to do, I'm HOPING I can
just use instructions like MarlinSerial::println("Turn that thing on"); and it will get sent out to and received by the J19 RX pin,
and my Arduino will receive the command and do it.

You've now mentioned using PORT_REDIRECT to bypass the default GCode-assing behavior, and presumably to allow me to
pass my own commands via J19 pins.

I'll take a look.

You're right, as you stated in your original reply, that "Marlin serial is a complicated thing".

You don't know how much I appreciate your help on this.
Re: TX/RX on J19 socket
June 04, 2024 07:28PM
Looking at how M118 works, the instructions all end up, after lots of subsequent #defines, using MSerial, which is just an instance of MarlinSerial.

M118 is also defined as a GCode to:

"print a visible message to the host console"

Thats not what I'm trying to do.

And I don't see anywhere that it "Allows you to send a message to any port".

Does MSerial get set to go out to through TX on J19?

The testing that I've done using MSerial seems to indicate that it is NOT going out through TX on J19. I don't know WHERE it's going.
Re: TX/RX on J19 socket
June 04, 2024 09:29PM
SERIAL_PORT_2 is referenced 155 times in 60 different files on current marlin bugfix 2.1.x

one eg [github.com]

Ie
$ grep -lr SERIAL_PORT_2 *
buildroot/tests/LPC1768
buildroot/tests/STM32F103RC_btt_USB_maple
buildroot/tests/STM32F103RC_meeb_maple
buildroot/tests/STM32F103RE_btt_USB
buildroot/tests/mks_tinybee
buildroot/tests/STM32F103RE_btt
buildroot/tests/mks_robin_nano_v1v2_maple
buildroot/tests/mega2560
buildroot/tests/STM32F103RC_btt_maple
buildroot/tests/teensy41
buildroot/tests/STM32F103RC_btt_USB
buildroot/tests/STM32F103RC_btt
buildroot/tests/mks_robin_pro_maple
Marlin/Configuration.h
Marlin/src/HAL/LPC1768/HAL.h
Marlin/src/HAL/AVR/HAL.h
Marlin/src/HAL/AVR/MarlinSerial.cpp
Marlin/src/HAL/AVR/MarlinSerial.h
Marlin/src/HAL/NATIVE_SIM/HAL.h
Marlin/src/HAL/TEENSY40_41/HAL.cpp
Marlin/src/HAL/TEENSY40_41/HAL.h
Marlin/src/HAL/STM32/HAL.h
Marlin/src/HAL/SAMD21/HAL.h
Marlin/src/HAL/STM32F1/HAL.h
Marlin/src/HAL/STM32F1/MarlinSerial.cpp
Marlin/src/HAL/STM32F1/inc/SanityCheck.h
Marlin/src/HAL/HC32/HAL.cpp
Marlin/src/HAL/HC32/HAL.h
Marlin/src/HAL/HC32/MarlinSerial.cpp
Marlin/src/HAL/HC32/inc/SanityCheck.h
Marlin/src/HAL/DUE/HAL.h
Marlin/src/HAL/DUE/MarlinSerial.cpp
Marlin/src/HAL/DUE/MarlinSerial.h
Marlin/src/HAL/DUE/MarlinSerialUSB.h
Marlin/src/HAL/DUE/MarlinSerialUSB.cpp
Marlin/src/HAL/SAMD51/HAL.h
Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h
Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h
Marlin/src/pins/stm32f1/pins_MD_D301.h
Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_common.h
Marlin/src/pins/stm32f4/pins_BTT_SKR_V2_0_common.h
Marlin/src/pins/stm32f4/pins_MELLOW_FLY_E3_V2.h
Marlin/src/pins/stm32f4/pins_BTT_E3_RRF.h
Marlin/src/pins/stm32f4/pins_I3DBEEZ9.h
Marlin/src/pins/stm32f4/pins_FYSETC_SPIDER_KING407.h
Marlin/src/pins/stm32f4/pins_BTT_OCTOPUS_V1_common.h
Marlin/src/pins/stm32h7/pins_BTT_SKR_SE_BX_common.h
Marlin/src/pins/stm32h7/pins_BTT_SKR_V3_0_common.h
Marlin/src/pins/stm32h7/pins_BTT_OCTOPUS_PRO_V1_common.h
Marlin/src/pins/stm32h7/pins_BTT_OCTOPUS_MAX_EZ.h
Marlin/src/pins/ramps/pins_LONGER3D_LKx_PRO.h
Marlin/src/inc/Conditionals_LCD.h
Marlin/src/inc/Changes.h
Marlin/src/inc/SanityCheck.h
Marlin/src/inc/Conditionals_post.h
Marlin/src/inc/Conditionals_adv.h
Marlin/src/core/serial.cpp
Marlin/src/core/serial.h
Marlin/src/lcd/extui/mks_ui/wifiSerial.h
Marlin/Configuration_adv.h

Edited 1 time(s). Last edit at 06/04/2024 09:32PM by Dust.
Re: TX/RX on J19 socket
June 05, 2024 02:35AM
This is getting very strange.

I downloaded the then most recent Marlin firmware several months ago.
I'm using VSCode to modify the Marlin firmware.

When I do a Find (CTRL/SHIFT F) and search for

SERIAL_PORT_2

it returns NO RESULTS.

Your list indicates that SERIAL_PORT_2 appears in MarlinSerial.cpp

Can you tell me where in that file it appears?

I also note that your list includes MarlinSerialUSB.cpp
and that file isn't even part of the files I have, from the GitHub.

What in the world am I doing wrong?
Re: TX/RX on J19 socket
June 05, 2024 05:00AM
Click on the "one eg" link
It takes you to the online page for MarlinSerial.cpp and to the line is it on
Re: TX/RX on J19 socket
June 05, 2024 04:59PM
Hi again,

Thanks for the link to MarlinSerial.cpp, the ORIGINAL MarlinSerial.cpp.

What I'm working with is the Prusa version of the Marlin firmware.
Having now taken a look at that original code it is clear that Prusa has made SUBSTANTIAL changes to it. A lot of the macros and constants used in the original simply
do not exist in Prusa's version. So the original approach to using TX and RX on J19 just do not apply to the Prusa firmware.

The bottom line for me is that I can't reference the approaches taken in the original in order to fix the issues I'm experiencing with Prusa's version.

I had TRIED to get assistance on the Prusa firmware RepRap page with no success, no responses, which is why I ended up looking for help here, on the original RepRap GitHub page.

[ sigh ]

I have tried dozens of approaches, followed through on numerous suggestions from lots of different forums and sources including (I'm embarrassed to say) ChatGPT and CoPilot, and none have worked.

I'm pretty much at a loss as to how to proceed. My project REQUIRES communication between the Prusa firmware and my additional Arduino via the TX/RX pins on J19. 

[ double sigh ]

Sincerely: Thank you for your help

Roger
Sorry, only registered users may post in this forum.

Click here to login