I’m trying to get a FX30S to communicate with an rs485 device, but for some reason it is not possible to set the GPIO for rs485 termination resistor. rs485 mode can be set using the python script from the manual, but setting termination fails, as GPIO63 is not exported under /sys/class (and consequently no rs_term under /sys/devices/platform/msm_serial_hsl.0)
The UARTs are configured as follows:
AT!MAPUART?
!MAPUART: 17,16
/dev/ttyHSL0 exists, and seems to work
I’m fairly new to yocto/Legato/
How do I get GPIO63 to be exported for usage?
The serial interface always reverts to rs232 mode on reboot
Can this be set from Legato app, or do I need to change the startup scripts for this?
Is it possible to verify basic communication from linux console, or is a Legato app necessary to talk to the serial port? I would like to use something like the below shell script to verify that the communication is working and that the rs485 device responds as it has been verified to do with rs485->usb converver.
#!/bin/sh
disable rs232 mode
#echo 0 > /sys/class/gpio/gpio59/value
set 9600 8n1 mode
stty -F /dev/ttyHSL0 9600 cs8 -cstopb -parenb raw -echo
enable rs485 transmitter
echo 1 > /sys/class/gpio/gpio60/value
send command
echo -ne “\x3a\x04\x01\x02\x07” > /dev/ttyHSL0
disable rs485 transmitter
echo 0 > /sys/class/gpio/gpio60/value
#enable rs485 receiver
echo 0 > /sys/class/gpio/gpio61/value
show command reply in Hex format
hexdump -C < /dev/ttyHSL0
Are there any sample app’s available that use the FX30S serial port? I would greatly appreciate examples of how to use transmit/receive, but haven’t been able to find anything at all online.
I don’t have a solution to the termination resistor, but I can share some RS-485 code in case it saves you some time. Please post an update if you figure something out with GPIO63.
Oh, that’s a good question. No, it’s not necessary to manually set the RS485 RX/TX mode.
I’d guess that what’s happening is that hardware flow control is force-enabled somewhere under the hood and RTS/CTS are routed onto the transmit/receive enable pins of the SN65HVD72 transceiver, so the RS-485 interface is in listen mode whenever it’s not actively transmitting.
Since it isn’t necessary, I’ve edited the example code to remove the call to le_tty_SetFlowControl
May I impose on you again to ask what firmware version you are running on your FX30S, and whether you can see gpio63 from the filesystem? I’m running the newest downloadable version from source.sierrawireless.com
root@fx30s:~# cm info firmware
SWI9X15Y_07.11.22.00 r33729 CARMD-EV-FRMWR1 2017/01/11 18:04:06
After new factory reset, I’m now able to get my commands echoed back from the serial port in the Legato App, which happens only when the rs485 device is connected and turned on, so it seems I’m on the right track, but still not reading the expected reply. However, by accident, I found out that getting 0x11 (XON) echoed back will silence the rest of the command sequence, so it seems that ttyHSL0 on my FX30S is running Software Flow Control by default, if no mode has been set with le_tty_SetFlowControl.
I also found out from stopping/starting the gpioService app running on the device, that GPIO63 is actually advertised there,
Aug 17 23:37:02 fx30s user.info Legato: INFO | gpioService[28950]/sysfsGpio T=main | gpioSysfs.c _sysfsGpio_COMPONENT_INIT() 9658 | Starting GPIO Service for Pin 63
…so I guess I just need to learn to use the GPIO api to enable termination resistor in the app.
Would really have liked to be able to use simple command line to verify the communications before adding further complexity, but I guess it just isn’t possible…
Yes, I have a working Developer studio env. running and is able to deploy apps.
I’m also now able to read the port from the Legato App, and getting my command seqences looped back when, and only when, the rs485 device in question is connected, so it seems to be on the edge of working, I just need to figure out why I’m not getting the expected response…
It looks like we have identical setups, the reason I’m so concerned about gpio63, is that the manual for the FX30S clearly states that it should be possible to set RS485 termination with the python script supplied in the FX30S manual, which for me fails with an error that appears to be related to the “missing” sysfs gpio. That makes me worry if something fundemental isn’t working as it is supposed to, which could lead to lots of wasted time with the app.
I guess lack of termination wouldn’t necessarily be a big issue with a short cable length and 9600 baud between 2 devices only, so its mostly about an error executing a command that is listed in the manual.
Are you also getting the same error ,due to missing rs_term when running
Yeah, it sounds like our setups are really similar. Like you said, termination shouldn’t matter at 9600 baud. I’m running unterminated at 9600 baud, and I’ve done firmware updates at 115200 with 20m cables.
Do you have anything like a Saleae analyzer around? If not, you should buy one. My Logic 8 has saved many days debugging exactly this sort of thing
As far as wasting time on the app… Legato is a really nice platform, but I do question how committed they are to the FX30. The official forum is not very active. My intention is to use the FX30 as a development and demonstration platform until the Mangoh Red ships at the end of August.
Unfortunately I don’t have a logic analyzer around.
It sounds like you have been communicating successfully with various rs485 devices, are you able to confirm that?
The reason I’m asking, is that when I use Legato to set the rs_mode, based on your unsandboxed example code, I’m not able to observe the change from the file system (also after removing the .adef file requirement, which seem to be for sandboxed mode). The rs_mode file still read “RS232” after the app confirms that it has written 1 to it.
If, on the other hand, I set RS485 mode from a shell script uploaded as unsandboxed Legato app, rs_mode does read “RS485” after the script has run.
Furthermore, if I set rs485 mode like this, or manually, the Legato C app stops being able to read my commands back - it only works if rs_mode is set to RS232 mode initially.
This leads me towards the conclusion, that my C Legato App is actually communicating in RS232 mode despite having tried to set the rs_mode to RS485. And that, for whatever reason, the serial port is still silent when in rs485 mode.
This leads me towards the conclusion, that my C Legato App is actually communicating in RS232 mode despite having tried to set the rs_mode to RS485. And that, for whatever reason, the serial port is still silent when in rs485 mode.
I feel like I’m on the edge of overstepping some bounds, but if you can buy, borrow, or hack an Arduino to be a logic analyzer, it’s the difference between spending a week discovering that you’re actually in RS232 mode, or having it fixed within minutes. If you get one with an analog input it can also be useful for power profiling. They really are that useful. The Saleae ones are are really nice.
It sounds like you have been communicating successfully with various rs485 devices, are you able to confirm that?
I’ve only tried a single sensor so far. The port is definitely switching into RS-485 mode. I’m going to add a second device in the next few weeks, I’ll post here if I run into any trouble with it.
I’m trying to get support from Sierra Wireless regarding my issues (will post if I get an explanation for the missing GPIO 59/63.
Perhaps you can help me with a last thing, so I don’t have to doublecheck on each change - do you connect A->pin3 and B->pin1 on the DB9 port, or the other way around?
I’m betting on the first, as it works with my FTDI rs485-USB cable, but have read that TI is one of the companies that use the opposite AB spec…
That just solved all my problems communicating with the device. It seems like a rather glaring error in the manual, which I think SW needs to fix in the next revision…
To round off the topic, anyone using fkorans example code above as a startoff template for setting RS485 mode should probably hold off opening the tty filehandle until after RS485 mode has been set, as my trials (on R13.1.2.004) indicated that it would keep using the RS232 driver if the TTY is opened in that mode.
Hi…as per my observation hardware flow control is force-enabled somewhere under the hood and RTS/CTS are routed onto the transmit/receive enable pins of the SN65HVD72 transceiver, so the RS-485 interface is in listen mode whenever it’s not actively transmitting.