Personal tools

Log in

Changes

From IGEP - ISEE Wiki

Jump to: navigation, search

How to use RS485

3,006 bytes removed, 18:39, 10 September 2012
m
IGEP BERLIN
'''under construction'''
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]]
4,199
edits