12-10-2020 07:11 AM
Hello,
I'am trying to use LINX on on board that has several hardware serial
By default, the LINX firmware communicate over the main serial. For some reason I would like to set the communication over serial1.
Is this feasible? If yes, can you please let me know what should be changed in the firmware? I tried to look into the code but did not find clear evidence..
NB : i'am talking about the communication between PC and board. Not set an UART peripheral over serial1...
I hope I 'am clear, thanks in advance for your help !
02-17-2021 03:39 AM - edited 02-17-2021 03:40 AM
Hello again,
I still have the problem, so after a few weeks I would like to raise this question again...
If not clear I can give more informations.
Many thanks in advance !
antoine
02-17-2021 03:55 AM
You did not receive an answer since you are not detailed enough what you try to do.
What hardware do you want to use Linx with?
Which serial port? On your computer? On the Linx device?
What is the mainSerial and what is serial1?
02-17-2021 05:03 AM
Hello Rolf,
First of all, many thanks for your reply and kind help.
I would like to use a arduino pro micro, wich is officialy supported in linx.
This device have built-in serial USB converter in the ATMega32U4 chip.
It works flowlessly over the USB port and USB cable, device regognized as "COM7" on my computer.
This device also have an additionnal HW serial. (TX and RX pin on pin 0 and 1).
If I connect a serial-USB adapter like FTDI converter on these pins, device is recognized as "COM8" on my computer.
Serial Communication is tested OK through both (built in USB and HW TX and rx pins), with arduino basic examples.
But I need to call "serial" functions for COM over USB, and "serial1" over the TX RX pins.
This is conform with the board spec / manual.
This is were I'am stuck, as Linx firmware use lower level function for the serial listener.
I've tried to change variables like numChan in device .h files, without success so far.
The reason why I want to use the HW port (pin 0-1) is that I'll use a wireless connection to replace the cable. (wireless serial), with HC 05 BT or HC12 radio module).
NB : I can make this wireless connection with no pbm if I use an arduino pro mini. (wich has no built -in serial/usb converter)
I hope it's more clear many thanks !
Antoine
02-17-2021 08:19 AM
Hello mknix.
I believe that the built in serial USB converter and the pins 0 an 1, are the same thing.
When you say: "Serial Communication is tested OK through both (built in USB and HW TX and rx pins), with arduino basic examples." did you mean at the same time?
one possibility to solve this problem is to use SoftwareSerial Library in you Arduino Program, and create other pins rather than 0 and 1 Tx RX.
02-17-2021 08:35 AM - edited 02-17-2021 08:37 AM
thanks a lot Jorge for your feedback
Jorge wrote : [I believe that the built in serial USB converter and the pins 0 an 1, are the same thing]
I also believed this at the beginning.
But after digging more into it, it is not the case.
It's thrue for some board like uno, nano... wich have only one HW serial.
But some other boards (leonardo, micro, mega etc) have two or more HW serial.
see the table here :
https://www.arduino.cc/reference/en/language/functions/communication/serial/
you can see that micro (and pro micro) have serial over USB, and serial 1 over TX and RX pin.
Jorge wrote : [one possibility to solve this problem is to use SoftwareSerial Library in you Arduino Program, and create other pins rather than 0 and 1 Tx RX.]
I alredy used softwareserial for other projects in the past, but unfortunately it is not that simple here (as far as i tried, I'am not expert).
Seriallistener is the heart of linx, really optimised for the performance.
As the board have two HW serial, I believe (maybe wrong?) that we can route the serial flow to the second serial HW port, instead of emulating a software serial. (wich is not easy anyway).
But I don't know how to do this 😉
thanks again for your help !
02-17-2021 09:50 AM
It's not enough to change the NUM_UART_CHANS value in the according header file. You also need to extend the according
LinxArduinoXXXX::m_UartChans[NUM_UART_CHANS] = {0, 1};
in the corresponding c source file. Most sources for the different Arduino files only define one uart for uart 0.
The underlaying LinxWiringDevice class implements Serial, Serial1, Serial2, Serial3 for Linx Uart channels 0, 1, 2, 3 respectively.
Only the LinxArduinoMega class supports all 4 out of the box but you do not want to use that one for your device unless it also has ArduinoMega compatible DIO pins too.
02-17-2021 11:45 AM
Thank you so much Rolf.
This is exactly what I was looking for.
It still doesn't work, but I got the feeling that I'am very close 😉
I have searched in the library of my board for "NUM_UART_CHANS"
I get 4 results (here for a try with a leonardo):
in LinxArduinoLeonardo.h
I changed :
#define NUM_UART_CHANS 2 // was 1
in LinxArduinoLeonardo.cpp
I changed :
unsigned char LinxArduinoLeonardo::m_UartChans[NUM_UART_CHANS] ={0, 1}; // was ={0}, replaced by ={0, 1}
in LinxConfig.h
I changed :
#define NUM_UART_CHANS 2 // was 1
in LinxWiringDevice.cpp
I changed nothing, as it seems bo be were the serial mode is selected (0, 1 etc), based on variable "channel"
This is unfortunately not enough. Datas still flows over serial instead of serial 1
I'am not clear were the value of "channel" is set. Could this be the clue?
Again thanks !
Antoine
02-17-2021 12:18 PM
Hi Antoine,
Is the channel set in
Arduino_Leonardo_Serial.ino ?
02-17-2021 01:09 PM - edited 02-17-2021 01:10 PM
Hello AndyLB
Thanks for helping.
yes, I tried
LinxSerialConnection.Start(LinxDevice, 0);
and
LinxSerialConnection.Start(LinxDevice, 1);
In Arduino_Leonardo_Serial.ino
Both makes the same result
thanks a lot for the good hint anyway