AN0505 - Communicating with a SIM using SCM117

From Serious Documentation
Jump to: navigation, search

Getting Started

If you’d like to use the SCM117 as a protocol translator or intermediary between the SIM535 and your system you will need to ensure that DIP switch position S1.5 (BOOT) is in the OFF position.

To use the SCM117 communications example project you will need to first download and install Renesas e2studio , the latest KPIT GNURX Toolchain and the Segger J-Link Software and Documentation Pack. Renesas and KPIT require free account registration to use. Additionally, you will need to download the SHIPWare Comm Demo for SCM117:

e2studio SHIPWare Comm Demo  ↴ 

To use this project, first launch e2studio. Upon starting, it will ask you to provide a path to your project. This is your e2studio "workspace". You will need to extract all files from the SHIPWare Comm Demo ZIP file into a location on your hard drive (NOTE: We recommend placing the folders somewhere with a "short" file path; long paths can cause complications with the compiler). Now, go back to the e2studios dialogue and click 'Browse'. Navigate to the location of the extracted files and then to SHIPWARE_CommDemo_SCM117/Serious/SCM117/SHIPWare/FreeRTOS/ and click 'OK'. After selecting, e2studio may ask you to update your workspace. You may have to restart e2studio on update completion and repeat the previous step.

NOTE: When the workspace opens you may see notices about toolchains being changed. This is normal since the latest toolchain you have available is likely newer than those available when this project was created.

Once loaded, you should see four projects.

Image of Project Files

The primary project is SHIPWare_SCM117_FreeRTOS, the others are libraries that it requires. When building or cleaning the project, target all actions on SHIPWare_SCM117_FreeRTOS. Debugging can be accessed by clicking on the green "bug" icon on the top menu bar.

Image of Debug Menu

You will most likely be using Option 3, SHIPWare - Segger J-Link RX Lite - Debug, since a Segger J-Link RX Lite is provided with the development kit.

You will need to plug in one end of your TC2050 cable to your RX111 Fine Adapter board, plug in the the other end of the TC2050 cable to J1 of your SCM117, plug in the JTAG cable between your Segger J-Link LITE RX and your RX111 Fine Adapter board, and ensure that the jumper on the RX111 Fine Adapter board is positioned over pins 1 and 2 (the side that says Segger J-Link), connect the Segger J-Link LITE RX to your PC using a USB cable, and ensure your SCM117 board is powered on. If the project is already built, all you need to do is click the debug session to begin.

The project has many useful items built in to help you begin developing quickly. This project is running FreeRTOS v7.5.2 through a version of our OS abstraction layer. In the Project Explorer on the left, you can open the file tree and examine SHIPWare_SCM117_FreeRTOS/src/SHIPWare Common/main.c to view where the tasks, stacks and bsp are initialized. Tasks of primary interest are the highlighted below:

Highlighted Tasks in the File Tree

Project Overview

The CAN_Link_Task pulls received frames from a queue and provides a simple structure to start handling, receiving and sending messages over the CAN bus. In that task you’ll see a comment like this on line 156:

Example of Comment Line

From here you can check the received IDs and look at or manipulate data of received frames by indirecting off pFrameIn. There is a local outbound frame kept on the stack for the convenience of sending new frames in response to frames received.

You can access this by setting the sendResponse variable on line 147 (just above the frameOut fields) to true. SHIP_CAN_PutFrame (located in the if statement on line 166) is used to copy local frames into the queue of a background CAN transmission task. The memory for received frames is freed at the end of the task’s loop unless you clear the pointer and hand off ownership of the frame to another task. Implementation depends on how you plan to use the CAN bus and the type of network you’re running, but these steps should provide a good starting point.

CAN Controller

The CAN controller itself is configured by default at compile time in the following highlighted header file. You can setup the timing, masking filtering and transmission parameters easily here.

CAN Controller in File Tree

UART

UART_SIM_Modbus_Slave_Link_Task is where the handlers for set/gets on the various Modbus data types are filtered and handled in switch statements. It already has four pre-set, addressed datatypes interfacing with the SIM535 communications demo. to give you an idea of how this can be used to connect with the SIM. Typically, you will only need to work with the switch statements in here. At the start of the task’s runtime loop you can find the configuration for the UART used (line 375). These parameters are currently set to match the accompanying example project.

UART Configuration

UARTEchoTask functions as a live console application over the RS232 transceiver on the SCM117. It prints out a banner, repeats characters back to the sender, implements an example function to crash the task, etc. At the start of the task there is a similar grouping of statements to configure the UART used (line 67). Alternatively you can disable this task and use the RS232 transceiver as purely a debug logging output. For more information about this method, please contact Serious Support.

The SHIP_Core Library and Configuration

The SHIP_Core library contains valuable components such as timers, utilities, CRC functions and more. This library is a recommended first stop when searching for functionality; if it's already been implemented, it will likely be here. NOTE: We also suggest looking through SHIPWARE_SCM117_FreeRTOS/src/SHIPWare Configuration/SHIP_PreConfig.c and SHIP_PostConfig.h configuration files to see interrupt priority levels, task configuration parameters, buffer pool setup, enabled/disabled parts of the SHIP_Core library and other parameters.

Memory Management

The memory management in this example project (not counting statically allocated memory at compile time) is managed through a central heap called SHIP_HeapMain. Viewing SHIPCore/src/SHIP_Heap.c and SHIP_Heap.h will provide you with ideas for how to acquire and free memory, as well as other tasks. The primary method of data passing between tasks and queues is done using SHIP_Buffers which are flexible structures which allow passing of data in a variety of contexts. By default, SHIP_Buffers are pulled from a central pool. There are many ways these buffers are used and many examples of how they help with performance at runtime. We suggest looking at how they're used in existing tasks as well as examining SHIPCore/src/SHIP_Buffer.c and SHIP_Buffer.h.

SCM117 Details

Details on the SCM117 board itself can be found in the SCM117 Documentation Area, including the Technical Reference Manual, Mechanical Design Package as well as other relevant documents.

You can also view SHIPWARE_SCM117_FreeRTOS/src/Platform Drivers/SCM117.c and SCM117.h to see the port configuration structures and other information about the board itself.

NOTE: For the most up to date information for your board, contact Serious Support.

SHIPTide Project

We've also providing an accompanying SHIPTide project for the SIM535 which can be converted to other platforms using the "Change Platform and Variant" feature in SHIPTide.

SIM535 Modbus RTU Master  ↴ 

The project has the required drivers in a folder within the archive. Once SHIPTide is installed you can also use the SIM Firmware Updater to ensure your SIM has the latest firmware. Before using this project, please ensure you're using the latest version of your board's firmware and the latest version of SHIPTide, available here. We have also provided links to the SIM drivers:

Windows 64-bit   ↴ 

Windows 32-bit   ↴ 

Once you have the SHIPTide project and have updated accordingly, you will find a project that may be opened in SHIPTide and loaded onto your SIM535 to demonstrate communication with the SCM117.

The Modbus Master demo has 4 buttons to interact with. The buttons and their descriptions are listed below.

  • "SEND COILF: Sends out a Modbus RTU set coil packet to slave ID 0x01 at address 0x0003. Value sent flips from 0 to 1 repeatedly.
  • "SEND HOLDING REGISTER": Sends out a Modbus RTU set holding register packet to slave ID 0x01 at address 0x0000. Value sent increments with each press.
  • "MANUAL SLAVE POLL": Triggers a single polling sequence on addresses 0x0000, 0x0001, 0x0003, 0x0004 at slave ID 0x01.
  • "AUTO POLLING ENABLED"/"AUTO POLLING DISABLED": Enables auto polling of addresses 0x0000, 0x0001, 0x0003, 0x0004 at slave ID 0x01 every 1/10th of a second.

You will also find an assortment of fields in the table below the buttons showing what data (not full packet contents) has last been sent or received as a result of polling/sends.

Once you have both projects loaded and your SCM117 is connected to your SIM, they should communicate with each other as seen by the values changing on the GUI when polling or setting/getting. The LED on the SCM117 will also indicate activity by flashing red during communications.

For additional information on communications in SHIPTide developed cargos, please refer to the following articles:

Communications
Setting up a Modbus Master Link

Receiving/Sending SIM Data

DIP Switch Reference Image

If you’d like to use the SCM117 to directly receive/transmit data from the SIM itself, you will need to ensure that DIP switch position S1.5 (BOOT) is in the ON position. This will force the software on the SCM117 that takes the board out of bypass mode to not run so the board stays in bypass. The same project mentioned above may be used as a demonstration on how to get Modbus communications working. You can then skip to the very last section of information below to download the example communications SHIPTide project for a good template on where to start with Modbus communications.

To use RS485 on the SCM117 you'll need to first configure the DIP switches on the board according to the instructions below:

DIP Switch Configuration

  • Ensure DIP switch S1.3 (232) is OFF to ensure the transceiver operates in RS422/RS485 mode
  • Set DIP switches S1.1 (SLW) and S1.2 (SPD) according to the desired maximum line rate chart
  • Ensure DIP switch S1.4 (FD/HD) is ON for half duplex receive/transmit enable control


Speed and Slew Rate Control (RS4XX Mode)

In RS4XX mode, DIP switches S1.1 (SLW) controls the slew rate and S1.2 (SPD) controls the speed of the transceiver.

S1.1 (SLW) S1.2 (SPD) Description
OFF X 20mbps max - non slew rate controlled
ON OFF 460kbps max - slew rate controlled
ON ON style="padding:2px 8px;" 115kbps max - slew rate controlled

You will also need to connect the RS422/RS485 receive/transmit data onto J2 as follows:

J2# Signal PLC Connection
5+7
bridged
A+Y R-
(inverting in/out)
6+8
bridged
B+Z R+
(inverting in/out)
4 GND GND

Add termination if needed:

  • There is no termination facility on the SCM; if cable termination is required, insert a termination resistor across pins 5 and 8 using the screw terminal version of the plug.