Create project Need help?
waltro

RS485 Sniffer

Status: Proposal
8092
10
votes
September 8, 2013
Sniff.jpg

If a RS485 network with few or many nodes is in operation or should be realized, it may be extremely helpful to monitor all activities, means messages, on the bus. The proper instrument doing this is a sniffer, which records all messages on the bus and sends it in readable format to PC and/or saves it on an SDCard. This would easily allow to the developer to identify errors in the protocol or wrong operating nodes. The here introduced RS485 sniffer performs this task as a freestanding module .

It has the following specifications:

* Monitors the RS485 traffic on the bus with up to 19.2 KBaud.

* Translates each received byte into two ASCII-characters and sends it to the PC with 115.2 KBaud.

*In addition or alternately it stores the information on a SD-Card in FAT32-format. It can be used without PC. (SD-Cards with 2 and 8 GB have been tested.)

* Real time Clock for time stamps of each message.

*Controllable by PC-commands and/or by one button and 3 LEDs as mode indication.

Hardware:

Base is a PIC-Ready-Board from MikroElektronika equipped with a PIC18F46K22. This MCU has two UARTs, which are used for the communication to the RS 485 bus and PC. Large flash and RAM capacities allow a big firmware and big data buffers. The wrap area and a daughter board contain the peripherals like RS485 transceiver, RTC, SD-Card interface, control button and 3 LEDs. For later software extension a LAN-interface (ENC28J60) has been added. The connection to PC via USB (FT232RL) is part of the PIC-Ready-Board. Power can be taken from USB or external power supply.

Software:

The software is realized with Pascal Pro 6.01 from MikroElektronika.

It supports the following commands and functions:

*settim = sets RTC time

*setdat = sets RTC date

*gettim = shows RTC time

*getdat = shows RTC date

*snitty = sniffs RS485 and sends data to PC

*snisdc = sniffs RS485 and sends data to SD-Card

*snitsd = sniffs RS485 and sends data to PC and SD-Card

*sniweb = not yet implemented, for further use

A one-button-control allows to start all modes without PC commands and indicates it with the three LEDs (green = idle, yellow = sniff PC, red = sniff SD-Card, yellow + red = sniff on PC and SD-Card). Multiple pressing of the button chooses the modes. A single hit terminates a running sniff.

The software is structured modular and is divided in to 5 Finite-State-Machines (FMS). Each FMS performs a dedicated task, which allows easy development and maintenance. The RS485 and PC-communication runs interrupt-controlled, the storage on SD-Card runs due to library design in poll mode. In order to avoid data losses, the incoming messages are stored in a ring buffer and then spooled out either to PC and/or SD-Card.

There is room for the following extensions:

* Access to the sniffer over the web for control and reports.

* Filter to show only messages to or from a specified node.

* Filter to show only messages with a specified content, e.g. 0x1A on byte 6.

Remark:

This sniffer is adapted to the RS485 protocol of the author. The ElektorBus is not (yet) supported. But due to the very modular software approach an adaption to the Elektor protocol should be possible with reasonable effort.

For information:

The RS485 protocol of the author has the following characteristic:

* MultiMaster, each node is able to send to each other.

* Variable message length from 7 to 255 bytes.

* Flexible payload, no predefined content structure.

* Advanced collision detection due to continuous bus monitoring performed by each node and random start of transmission with bitbanging before.

* Efficient 9 bit transmission, nodes will be only interrupted from address bytes.

* Communication integrity due to read-after-write, CRC16 and Ack/Nack mechanism.

* Broadcast facility, each node belongs to a group and has a specified priority.

* Simple interface by call interface and call-back routines, designed for multitasking.

The following items are attached:

* Schematics of PIC-ready-board and extensions (made with DesignSpark)

* Pictures of the board(s)

* PascalPro project with included source and hex files

* Screen shots of sniffs on PC and SDCard

* Screen shots of logic analyzer showing the different sniff modes

 

Read the full post
Show less
Software
Other

Loading comments...