Personal tools

Log in

Changes

From IGEP - ISEE Wiki

Jump to: navigation, search

How to use RS485

1,196 bytes removed, 18:39, 10 September 2012
m
IGEP BERLIN
= Overview of =<section begin=overview />This How-To is meant to be a starting point for people to learn to use RS-485 port on IGEP devices as quickly and easily as possible. We use [http://labs.isee.biz/index.php/IGEP_firmware_Yocto IGEP YOCTO Firmware] and RS485 example which describe how to setup and write data on the RS-485 port.<section end=overview />
This How-To is meant to be a starting point for people to learn to use the RS-485 port on IGEP0020 board. = Requirements =
Below this How*[http://www.ubuntu.com/ Ubuntu] distribution or [http://labs.isee.biz/index.php/IGEP_SDK_Virtual_Machine IGEP SDK VM].*[http://www.isee.biz/component/zoo/item/igep-To is a short .c file which describe how to setup and write data on the RSyocto-toolcahin-485 port. sdk IGEP YOCTO Toolchain SDK] *2 IGEP devices
=Add RS-485 support = Feedback and Contributing ==Flash memory==Boot IGEP with a [http://labs.isee.biz/index.php/How_to_create_a_SD-card_with_the_latest_software_image MicroSD card].
At any point, if you see a mistake you can contribute *Connect to this How[http://labs.isee.biz/index.php/IGEPv2#Log_into_IGEPv2_via_Ethernet_interface IGEP]<pre>mkdir /tmp/tempmount -Tot jffs2 /dev/mtdblock1 /tmp/temp </pre> Now, mtdblock1 partition is mounted at /tmp/temp directory. Modify igep.ini located in: /tmp/temp/igep. ini
= *Add RS-485 support to Linux :<pre>board.ei485=yes</pre> Save changes, power down IGEP, unplug MicroSD card and power up your board.
==Micro SD= Using kernel 2=Plug SD card in your computer, boot partition should be appear.6Modify igep.35ini located in: /media/boot/igep.13 ===ini
In this kernel is not necessary add *Add RS-485 support:<pre>board.ei485=yes</pre> Save changes, plug SD card in IGEP and power up your board.
=== Using kernel 2.6.33 series ==IGEPv2 =
Follow RS-485 port is located at [http://wwwlabs.igepisee.esbiz/index.php?option=com_kunena&amp;Itemid=97&amp;func=view&amp;catid=13&amp;id=1195&amp;limit=6 /Connectors_Summary#J940_connector J940 connector], connect two IGEPv2 devices like this:
=== Using kernel 2.6.28 series ===
 
Tested on a 2.6.28.10-3 version kernel.
 
To use correctly the RS-485 interface chip we need to configure the serial port driver in the kernel to manage the RTS signal (Request To Send) to enable the TX section (DE pin) only when data are transmitted on TXD line (Transmit Data). This is a software only solution, requiring no special hardware, but timing control for delays is only accurate to the next nearest jiffy.
 
First of all, download the latest stable kernel version
 
$ wget http://downloads.igep.es/sources/kernel/linux-omap-2.6.28.10-3.tar.gz
$ tar xzf linux-omap-2.6.28.10-3.tar.gz
$ cd linux-omap-2.6.28.10-3
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- igep0020_defconfig
 
Next, enable the RS-485 support.
 
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
 
Configure the kernel to enable RS-485 support.
 
Device drivers ---&gt;
Character devices ---&gt;
Serial drivers ---&gt;
*** serial port extensions ***
[*] Allow hand shake line half duplex direction signaling
 
Finally build kernel image with RS-485 support
 
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- uImage
 
= Test RS-485 communication with two IGEP0020 boards =
 
Connect two IGEP0020 boards using J940 connector like this:
<pre> J940 J940
--- ---
| 1 |---------- GND --------------| 1 || 2 |-X X-| 2 || 3 |-X X-| 3 || 4 |---------- A --------------| 4 || 5 |---------- B --------------| 5 | --- ---</pre> Setup a NFS-TFTP environment (poky-image-sato) for each board using kernel image with RS-485 support, and power up  Build the example for your target boards (485-example.c at the end of this article),   $ cd linux-omap-2.6.28.10-3 $ arm-none-linux-gnueabi-gcc 485-example.c -o 485-example -Iinclude -Iarch/arm/include
and copy to target rootfs== Program ==[http://labs.isee.biz/index.php/How_to_setup_a_cross_compiler#Download.2FInstall_IGEP_SDK Download an Install] IGEP SDK if you don't have it.
Now, open a [[Using SSH to communicate|ssh console]] to the first board and execute the microcom commandCreate source code text file:
rootFirst of all you need to initialize a suitable environment in the bash shell console inside your machine. <br> You can do this sourcing once the environment-setup script. <pre>jdoe@igep0020:ubuntu ~# microcom $ source /devopt/ttyS0 connected to 'poky/dev1.2/ttyS0' environment-setup-armv7a-vfp-neon-poky-linux-gnueabi </pre> Create a single .c file (9600 bps485-example.c), exit with ctrlusing your preferred editor (vi, nano, gedit, ...) <br> 485-Xexample.c: <pre>/* 485-example.c : Basic example of RS485 half duplex transmission */#include <stdio.h>#include <string.h>#include <unistd.h>#include <fcntl.h>#include <errno.h>#include <termios.h>
On second board, open a ssh and execute the 485 example: #include <sys/ioctl.h>#include <asm/ioctls.h>
root@igep0020:~# ./485-example If all is ok, should appear "ABC" in microcom console.   root@igep0020:~# microcom /dev/ttyS0 connected to '/dev/ttyS0' (9600 bps), exit with ctrl-X... ABC = Appendix A: 485-example.c&nbsp;: Basic example of RS-485 half duplex transmission =include <pre>/* 485-example.c&nbsp;: Basic example of RS485 half duplex transmission */#include &lt;stdio.h&gt;#include &lt;string.h&gt;#include &lt;unistd.h&gt;#include &lt;fcntl.h&gt;#include &lt;errno.h&gt;#include &lt;termios.h&gt; #include &lt;sys/ioctl.h&gt;#include &lt;asm/ioctls.h&gt; #include &lt;linux/rs485serial.h&gt;>
int main(void)
{
char dev[] = "/dev/ttyS0ttyO0"; char tosend[] = {'A', 'B', 'C'}; struct serial_rs485_settings serial_rs485 ctrl485; int status; int fd;
struct termios ti; speed_t speed;
/* Open the port */ fd = open(dev, O_RDWR); if (fd &lt; < 0) { printf("%s: Unable to open.\n", dev); return -1; }
/* Set the port in 485 mode */ ctrl485.flags = SER_RS485_MODE SER_RS485_ENABLED | SER_RS485_MODE_RTS | SER_RS485_RTS_TX_LOWSER_RS485_RTS_ON_SEND; ctrl485.delay_before_send delay_rts_before_send = 0; ctrl485.delay_after_send delay_rts_after_send = 0;
status = ioctl(fd, TIOCSRS485, &amp;ctrl485); if (status) { printf("%s: Unable to configure port in 485 mode, status (%i)\n", dev, status); return -1; }
/* Set the port speed */ speed = B9600; tcgetattr(fd, &amp;ti); cfsetospeed(&amp;ti, speed); cfsetispeed(&amp;ti, speed); tcsetattr(fd, TCSANOW, &amp;ti);
/* Send content to RS485 */ if (write(fd, tosend, sizeof(tosend))&nbsp;!= sizeof(tosend)) { printf("%s: write() failed\n", dev); }
return 0;
}
</pre>
*Build arm binary executable:
Cross toolchain tools are available into the built-in virtual machine Poky SDK. You only need open bash terminal prompt and write commands: <pre>jdoe@ubuntu ~/Desktop $ arm-poky-linux-gnueabi-gcc -o 485-example 485-example.c</pre> = References =
== Test ===== IGEP 1 ===*[http:Get a remote shell and execute microcom program<pre>microcom -s 9600 -X /dev/markmail.orgttyO0</message/hu4ydmvwa4g7xtec#query:Auto%20RS485%20direction%20control+page:1+mid:uyw4hqsipap5z4il+state:results PATCH/RFC Auto RS-485 direction control ]pre>
*Discussions on RS-485 auto direction control seem to be split over a number of threads. Here are some threads: **http://marc.info/?t=121805745200001&amp;r=1&amp;w=2 **http://marc.info/?t=121690034200007&amp;r=1&amp;w=IGEP 2 **http://marc.info/?t=122821576400003&amp;r=1&amp;w=2 **http://marc.info/?t=122822457300004&amp;r=1&amp;w=2 Transfer arm executable file from virtual machine to IGEP Board **httpExecute arm executable file inside IGEP Board (remote shell)://marc.info/?t=122954923400001&amp;r=1&amp;w=2 <br>**http<pre>root@igep00x0://marc~# .info/?t=122964426200001&amp;r=1&amp;w=2 **http://marc.info/?t=121566595900001&amp;r=1&amp;w=2 **http:485-example<//marc.info/?t=121805198200004&amp;r=1&amp;w=2pre>
==Results = ISEE References =If you follow steps correctly you can see the next result at IGEP1:<pre>root@igep00x0:~# microcom -s 9600 -X /dev/ttyO0ABC </pre>=IGEP BERLIN ='''under construction'''
Read the [http://igep.es/index.php?option=com_content&view=article&id=99&Itemid=129&dir=%2Fvar%2Fwww%2Fvhosts%2Figep.es%2Fhttpdocs%2Fdownloads%2F01-ISEE_Products%2FIGEPv2%2FHW_User_Manuals&download_file=%2Fvar%2Fwww%2Fvhosts%2Figep.es%2Fhttpdocs%2Fdownloads%2F01-ISEE_Products%2FIGEPv2%2FHW_User_Manuals%2FMAN-PR-IGEP.0020-001.23.HW_RC.pdf Official IGEP0020 Hardware Reference Manual] (chapter "5.3 CONNECTOR J940: POWER + RS-485" )<br>
[[Category:Tutorials]]
[[Category:Peripherals|RS485]]
[[Category:RS485]]
[[Category:IGEP0020]]
4,199
edits