Personal tools

Log in

Changes

From IGEP - ISEE Wiki

Jump to: navigation, search

User:Pau pajuelo

4,396 bytes removed, 11:47, 29 August 2012
no edit summary
= How to use RS485 on IGEP0020 board =
= 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.
 
= Requirements =
 
*[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-yocto-toolcahin-sdk IGEP YOCTO Toolchain SDK]
*2 IGEP devices
 
= Add RS-485 support =
== 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].
 
*Connect to [http://labs.isee.biz/index.php/IGEPv2#Log_into_IGEPv2_via_Ethernet_interface IGEP]
<pre>mkdir /tmp/temp
mount -t 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:
<pre>board.ei485=yes</pre>
Save changes, power down IGEP, unplug MicroSD card and power up your board.
 
== Micro SD==
Plug SD card in your computer, boot partition should be appear. Modify igep.ini located in: /media/boot/igep.ini
 
*Add RS-485 support:
<pre>board.ei485=yes</pre>
Save changes, plug SD card in IGEP and power up your board.
 
= IGEPv2 =
 
RS-485 port is located at [http://labs.isee.biz/index.php/Connectors_Summary#J940_connector J940 connector], connect two IGEPv2 devices like this:
 
<pre> J940 J940
--- ---
| 1 |---------- GND --------------| 1 |
| 2 |-X X-| 2 |
| 3 |-X X-| 3 |
| 4 |---------- A --------------| 4 |
| 5 |---------- B --------------| 5 |
--- ---</pre>
 
== 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.
 
Create source code text file:
 
First 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@ubuntu ~ $ source /opt/poky/1.2/environment-setup-armv7a-vfp-neon-poky-linux-gnueabi </pre>
Create a single .c file (485-example.c), using your preferred editor (vi, nano, gedit, ...) <br> 485-example.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>
 
#include <sys/ioctl.h>
#include <asm/ioctls.h>
 
#include <linux/serial.h>
 
int main(void)
{
char dev[] = "/dev/ttyO0";
char tosend[] = {'A', 'B', 'C'};
struct serial_rs485 ctrl485;
int status;
int fd;
 
struct termios ti;
speed_t speed;
 
/* Open the port */
fd = open(dev, O_RDWR);
if (fd < 0) {
printf("%s: Unable to open.\n", dev);
return -1;
}
 
/* Set the port in 485 mode */
ctrl485.flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND;
ctrl485.delay_rts_before_send = 0;
ctrl485.delay_rts_after_send = 0;
 
status = ioctl(fd, TIOCSRS485, &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, &ti);
cfsetospeed(&ti, speed);
cfsetispeed(&ti, speed);
tcsetattr(fd, TCSANOW, &ti);
 
/* Send content to RS485 */
if (write(fd, tosend, sizeof(tosend)) != 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>
 
== Test ==
=== IGEP 1 ===
*Get a remote shell and execute microcom program
<pre>microcom -s 9600 -X /dev/ttyO0</pre>
 
=== IGEP 2 ===
*Transfer arm executable file from virtual machine to IGEP Board
*Execute arm executable file inside IGEP Board (remote shell):<br>
<pre>root@igep00x0:~# ./485-example</pre>
 
== Results ==
If you follow steps correctly you can see the next result at IGEP1:
<pre>root@igep00x0:~# microcom -s 9600 -X /dev/ttyO0
ABC </pre>
 
[[Category:RS485]]
= igep.ini parameters =
4,199
edits