Go to the Index page
Main page Products Case Studies Software Support Where to Buy    Contacts     SiteMap

Charon 2 DB peripherals demo firmware

Charon 2 DB Peripheral demo firmware is default embedded application for the Charon 2 modules. It's using the peripherals on the Charon 2 Development Board. This application and it's source code is well documented in this article..

Main Features

  • RS-232 serial port based basic IP address setup
  • Basic NutOs page status informations
     
  • Web applications with peripherals :
    • 8x LED diodes over shifted register
    • 8x Binary switch input over shifted register
    • 2x16 LCD display text output
    • 1x RS-232 serial port (input and output string, up to 250 bytes)
    • 1x (up to 4x) 1-Wire thermometer sensor
           
  • Well documented application source code.
  • Easy to use, easy to modify...

Other related product pages:

 

Download

  • Charon 2 Development Board demo - hex file only
    Last version of the .HEX file for the default application testing the Development Kit.
  • Charon 2 Development Board demo - full source codes
    Last version of the well documented default application for testing the Development Kit. Full source code included..
  • AVR Studio 4.7
    With original included HW STK500 adaptor, use please AVR Studio 4.7. Higher versions may have troubles, with STK 500 FW updates..  
  • Charon 2 Development Kit documentation
     - Ch2 Developmet Board detailed description, connectors pinouts & description,
    - Getting started with the default demo application, testing all peripherals..
    - Detailed description of the example application & programming routines.
    - How to compile & programm to the Charon 2 module your application...
     

Setup the IP address

At first you have to assign unique IP address to the Ethernet device. We are not supporting the DHCP because of some troubles and uncompatibilities with previous versions, we prefferes easy serial terminal setup.
Run any RS-232 terminal program (Hercules or Tera Term for example) with port parameters: 9600Bd, no parity, 8 data bits, 1 stop bit (9600 8N1). Switch the handshake control off (Flow : NONE). After power up with shorted the “SETUP jumper”, the first page of the serial setup should be displayed in the opened serial terminal.

RS-232 Setup is intended for use in setting Charon 2 network parameters. Before you connect the Charon 2 Development Kit into the network, the parameters should be set to the correct values for proper operation on the network (accessing the Charon 2 Development board from network).

You can see this page on the picture, follow the instructions and “Press any key to enter RS232 setup“.

The actual configuration is printed, and can be seen in the easy menu allowing change of basic network parameters.

When the Charon 2 DB peripherals demo firmware is loaded into the microcontroller, these network parameters are set to default values:

MAC= 00-0A-59-03-00-5F,
IP=192.168.1.100,
IP mask=255.255.255.0,
IP gateway=192.168.1.1

Just press “I” or “i” (non case sensitive) to assign an IP address for the device. There is automatic mode inserting "." (dot separators) if the number in the IP address is 3 characters long. There is ENTER automaticly inserted if the last number has 3 characters. You can't use backspace key in editing..
All entered paramethers are automaticky checked before writeing to the EEPROM = you can't set GW which is out of your basic IP address range defined by the IP address and used Network MASK. It means you have to define first the module's IP address and Network MASK, than new GateWay.

When all paramethers are OK, remove the “SETUP jumper” and press “R” for “R: Reboot (exit setup)”.

Accessing to the module with using the HTTP

The user can access this Charon 2 DB peripherals demo HTML page by an internet browser. Simply write the current Charon 2 IP address into the browser and the following page appears. The default IP address =192.168.1.100 , in browser: http://192.168.1.100.
There is a ‘welcome’ HTML page and from this page the user can enter to other pages (links on page):

On NutOs status HTML pages we can see some important NutOs operating system information. The main purpose of the implemented application on Charon 2 is peripheral control. Therefore the most important link is Peripheral control to show the following HTML page :


 

Charon 2 DB peripherals demo

LCD display control

On the webpage is an edit box to control displayed text on the external LCD display connected to the Development Board. This edit box has dimensions of 2x16 chars - the same as the connected LCD display to ensure similar visualisation.
 

LED diodes - output pins control

LED diodes present on the Development Board (as LED-bar graph) are controlled with 8 checkboxes. Each checkbox has a corresponding picture which shows the required (or present) LED state. Checkbox state represents the bit value of the output shift register - if it is checked then given bit/pin is in log.1 state and if unchecked then given bit/pin is in log.0 state. Because LED diodes are connected to VCC then LED states are opposite the checkboxe states. But the pictures display the real LED states.

Output shift register port state is displayed in one edit box as a decimal value.
 

DIP switches - input pins reading

DIP switches present on the Development Board are monitored within 8 checkboxes and 8 corresponding pictures. Each checkbox has a corresponding picture, which shows the present DIP switch state. The checkbox state represents the bit value of the input shift register - if it is checked then the given bit/pin is in log.1 state and if it is unchecked then the given bit/pin is in log.0 state. Because the DIP switch is connected to GND (when it is switched on the input pin is connected to GND) then DIP switch states are negated checkbox states. But picture displays are the real DIP switch states.

Input shift register port state is displayed in one textfield as a decimal value.
 

RS232 data output

The user can send some data (text) from this HTML page to the RS232 port located on the Development Board. The user writes the required text in the edit box and in the next update the text is transmitted to the RS232 (at baud rate given in RS232 baud rate box setting).

Because this RS232 data is sent to Charon 2 with the GET method and Ethernut supports a maximum of 256 bytes received by the GET or POST methods, length of this RS232 data output is limited to cca 70 bytes (because the whole 256 byte GET message also includes other settings: LED, DIP switch).
 

RS232 data input

When Charon 2 receives some data from RS232 the user can display this data (text) on the HTML page in the supplied textfield. This data is updated with every refresh or update of the HTML page. Charon 2 buffers a maximum of 255 bytes of received chars. If no data was received from the last refresh/update then the previously received data remains displayed.
 

RS232 baudrate control

Charon 2 RS232 line baudrate is controlled through the given edit box on the HTML page. When we transmitsome data from the HTML page to RS232 line, data is transmitted at the given baudrate. After refresh/update of the HTML page this box displays the current baud rate (therefore speed may be slightly different as required due to limited step in Charon 2 UART baud rate setting).
 

Thermometer(s) reading

The Charon 2 Development Board has a connector for connecting 1-wire thermometers. The Charon 2 measures temperature from all thermometers every 1 second. The number of connected thermometers is automatically detected. The user can read the thermometers values on the HTML page. The values are displayed in the edit box on the HTML page - in the case of multiple connected thermometers, the temperatures are displayed on multiple lines.

In the present firmware, the maximum number of thermometers that can be connected is 5 (but may be set to different value in Charon 2 firmware).
 

RS232 to TCP port 23 (telnet) link

On the HTML page is displayed information that Charon 2 works also as a converter between the RS232 line and TCP (port 23 = telnet). This converter works independently from controlling other peripherals (except baud rate of RS232 whos changes are reflected immediately).
 

Update and refresh values on HTML page

All required values are sent to the Charon 2 Development Boards peripherals by the Update/Refresh values button. Then the required data is submitted by the GET method to the Charon 2 which works as a server. The Charon 2 sets required values, collects required information and displays the modified HTML page with current peripheral values.
 

Additional pictures and links

The HTML page shows 2 pictures - logos of the main firmware/software developer companies. These pictures are links to their homepages where the user can obtain more information about embedded Ethernet (products, examples, solutions, .. ).

On the top left corner of the page is a link to the original Ethernut project (www.Ethernut.de) Use this link to see additional information about Ethernut & NutOs current operating system state.. On the top right corner is a link to the HW group (www.HW-group.com) company homepage, authors of the Charon modules and another Ethernet devices.

Description of RS232-telnet converter

RS232 to TCP port 23 (telnet) link

Charon 2 DB peripherals demo firmware works in the background as RS232 to telnet (TCP port 23) converter. To display functionality of this converter simply run telnet on a computer on the network and connect to a given IP address (default IP=192.168.1.100). Then connect a computer with a running RS232 terminal to the Charon 2 Development Board serial port (default serial port parameters are 9600,8,N,1 , but the baud rate can be changed from the HTML page). After this action the telnet client is connected with the terminal program through the network. The user can write something into the terminal and Charon 2 sends this data to the telnet client (data appears in telnet window). This also works in reverse (from telnet to RS232).
 

Description of firmware

Basic principle of firmware is to perform some actions as a result of user requirements and some background services. The background is running in threads:
  • Thermometers reading: Thermo thread
  • RS232 receiving and RS232 to TCP converter: Receiver thread
  • TCP to RS232 converter : Main program loop
  • HTML pages processing : Service threads httpd1, httpd2, httpd3, httpd4

When firmware starts it firstly opens the network and UART device. It initializes UART to default speed 9600 baudrate and loads network parameters from EEPROM. Then the Setup jumper is checked and if present runs RS232 setup. Starts Receiver thread to receiving data from RS232 line and starts

Thermo thread reads temperatures from thermosensors. Initializes network to parameters stored in EEPROM. Then register CGI samples to display web pages (NutOs status pages and Charon 2 DB peripherals demo page). Next the 4 threads are created for processing server HTTP responses (threads are named httpd1, httpd2, httpd3, httpd4). The LCD display is then initialized to default value: startup text is displayed. At the end of main routine is endless loop for processing TCP to RS232 transfer (this can be made in independent thread, but in this case the main program routine will have nothing to do).
 

LCD display control

Output to LCD display is performed during HTML page response in ShowForm routine. Required text to LCD is sent as parameter "LCDtext" from HTML page. The string value of this parameter is firstly filtered by the ReplaceHTMLStr routine to correct conversions to true text chars. Then actions for "intelligent" separation of given text to 2 lines on the LCD display is performed. Finally initialization of LCD display (LCD_Init function) and writing required text to this LCD (LCD_Puts function) takes place. Initialization is necessary because in the case of the LCD being removed, no firmware restart is required.
 
 

LED diodes - output pins control

LED diode (in bargraph) control is performed during HTML page response in ShowForm routine. Required values of the LEDs is sent as parameter "ShiftLEDOut" from HTML page. According to this parameter, value simply sets the states of LED diodes with function DevBoardShiftLedOut (because LEDs are connected to outputs of shift register on Development Board).
 
 

DIP switches - input pins reading

DIP switch state is captured during HTML page response in ShowForm routine. Capture is performed by function DevBoardShiftByteIn because DIP switches are connected to inputs of the shift register on the Development Board. State is finally inserted into HTML page.
RS232 data output

Sending data to the RS232 line is performed during HTML page response in ShowForm routine. Required data is sent as parameter "RS232DataOut" from HTML page. These parameter values are firstly filtered by function ReplaceHTMLStr and then sent to Charon 2 UART (_write function).
 

RS232 data output

Sending data to RS232 line is performed during HTML page response in ShowForm routine. Required data are sent as parameter "RS232DataOut" from HTML page. This parameter values are firstly filtered by function ReplaceHTMLStr and then sent to Charon 2 UART (_write function).


RS232 data input

RS232 receiving is processed in the background in thread Receiver. This thread simply reads data from RS232 line and if something is received, sends received data to TCP port (if client is connected) and also stores data to buffer. This buffer rxbuff can be read by user into HTML page response. Buffer rxbuff has limited size - 255 bytes.

Reading RS232 data is performed during HTML page response in ShowForm routine. Content of rxbuff buffer is inserted to HTML page.
   

RS232 baudrate control

Change of baudrate on RS232 line is performed during HTML page response in ShowForm routine. Required baud rate is sent as parameter "RS232Speed" from HTML page. According to this parameter value is set the UART baud rate (_ioctl function.
 

Thermometer(s) reading

1-wire thermometers (Dallas DS1822 or DS1820 type) capturing is processed in the background in thread Thermo. This thread works in an endless loop: Firstly detecingt all connected thermometers (TM_Init function) and then reads all detected thermometer values (TM_Init function). The temperatures are stored into buffer Temperatures. Then the thread sleeps for 1 second and repeats this sequence. Therefore new connected thermometers are detected automatically (the present firmware supports connection of up to 5 temperature sensors). From the buffer, the user reads temperature values during HTML page response.

Reading temperatures is performed during HTML page response in ShowForm routine. Temperatures buffer is read and its values are converted to temperatures and inserted in to HTML page.
 

RS232 - TCP port 23 (telnet) converter

This conversion is performed in two independent threads.
  • RS232 to TCP conversion is processed as part of the RS232 receive in thread Receiver. This thread simply reads from RS232 line and if something is received, sends received data to TCP port (if client is connected) and then stores data into buffer rxbuff for HTML page response.
     
  • TCP to RS232 conversion is made in main program. The main program finally performs a loop where it opens socket (NutTcpCreateSocket function) and then waits for client connections (NutTcpAccept function). When connection is established the stream for reading data from TCP port is opened. During connection, all received data from TCP port is transmitted to UART (in function StreamCopy). When disconnection occurs , socket is closed and this loop is restarted.

     

RS232 setup: Ethernet, TCP/IP parameters

RS232 setup routine is performed in the independent function RS232Setup. Here the RS232 menu is displayed and is where user input/output is processed.. User changes and changed network parameters and stored into EEPROM. To Exit from this routine and continue in firmware is possible using the "R" option in RS232 setup. To enter into this routine, the user must short the setup jumper and reset firmware (by reset button) on the development board
 

HTML pages and pictures

All HTML pages present in firmware are stored in project \HTMLdir directory. These pages and pictures are used as templates for generating HTML pages. To simplify HTML page generation we choose the following principle:

Charon 2 DB peripherals demo firmware only insert to this template HTML page a couple of variables in form : variable = value . Charon finds the position of insertion of this small number of variables according to the first presence of char "@". Therefore insertion place must be near the top of the page (to ensure removing other "@" char collisions). Position place is set into JavaScript function which according to this value, builds the whole HTML page visualisation: set checkboxes as bits in byte value, loads corresponding pictures to checked/unchecked checkbox, displays corresponding text to edit boxes (including some testing procedures and conversions), ... . JavaScript functions present in HTML page performs some additional functions: Edit boxes height settings according to text length, removing unsupported chars from edit box (e.g. only numbers are valid in baud rate settings) and formatting of submitted parameters.

Using this technique we transfer complicated page layout processing/testing to the client side which usually has more performance than embedded Ethernet server. Disadvantage of this method is that the client must support JavaScript language - but currently JavaScript is present in all commonly used commercial browsers.
 

Part of HTML template page for inserting variables:

...
  ShiftLEDOut      ="<#ShiftLEDOut> ";
  ShiftLEDIn       ="<#ShiftLEDIn>  ";
  LCDText          ="<#LCDText>     ";
  RS232DataOut     ="<#RS232DataOut>";
RS232Speed       ="<#RS232Speed>  ";
RS232DataIn      ="<#RS232DataIn> ";
Thermometer      ="<#Thermometer> ";

//not remove next line - this char is mark for Charon insert data command
//@
if ((ShiftLEDOut =="<#ShiftLEDOut> ")||(ShiftLEDOut==null)) 
      ShiftLEDOut = 0xAA;
if ((ShiftLEDIn  =="<#ShiftLEDIn>  ")||(ShiftLEDIn==null)) 
      ShiftLEDIn  = 0x55;
if ((LCDText =="<#LCDText> ")||(LCDText==null))
      LCDText = "    LCD Text"+"\n"+ "Ethernut project";

if ((RS232DataOut=="<#RS232DataOut>")||(RS232DataOut==null))
      RS232DataOut = "RS232 Data Out" + "\n" + "0123456789";

if ((RS232Speed =="<#RS232Speed>")||(RS232Speed==null))
      RS232Speed = 9600;

if ((RS232DataIn =="<#RS232DataIn> ")||(RS232DataIn ==null))
      RS232DataIn = "RS232 Data In" +"\n" + "0123456789";

if ((Thermometer =="<#Thermometer> ")||(Thermometer==null))
      Thermometer = 0.0001 + "\n" + 0.0002 + "\n" + 0.0003;;
...

And part of firmware source code to insert variables into template:

    ...
while (NutRomFileRead(DemoFile1,&DemoData,1)>0){
if ((DemoData!='@')||(!EnableParse)){
fprintf_P(stream, PSTR("%c"), DemoData);
}
else{
u_int i,j;
EnableParse=0;
fprintf_P(stream, PSTR("\r\n"));
/*ShiftLEDOut*/
fprintf_P(stream, PSTR("ShiftLEDOut= %d;\r\n") , ShiftLEDOut);
/*ShiftLEDIn*/
fprintf_P(stream, PSTR("ShiftLEDIn = %d;\r\n") , ShiftLEDIn);
/*LCDtext*/
j=strlen(LCDText);
fprintf_P(stream, PSTR("LCDText =unescape(\""));
for (i=0;i<j;i++){
fprintf_P(stream, PSTR("%%%02x"),LCDText[i]);
}
fprintf_P(stream, PSTR("\");\r\n"));
/*RS232DataOut*/
j=strlen(RS232DataOut);
fprintf_P(stream, PSTR("RS232DataOut =unescape(\""));
for (i=0;i<j;i++){
fprintf_P(stream, PSTR("%%%02x"),RS232DataOut[i]);
}
fprintf_P(stream, PSTR("\");\r\n"));
/*RS232Speed*/
fprintf_P(stream, PSTR("RS232Speed =%lu;\r\n") , RS232Speed);
...
...

And after processing the template page (variables are modified):

...
  ShiftLEDOut      ="<#ShiftLEDOut> ";
  ShiftLEDIn       ="<#ShiftLEDIn>  ";
  LCDText          ="<#LCDText>     ";
  RS232DataOut     ="<#RS232DataOut>";
  RS232Speed       ="<#RS232Speed>  ";
  RS232DataIn      ="<#RS232DataIn> ";
  Thermometer      ="<#Thermometer> ";
  //not remove next line - this char is mark for Charon insert data command
  //
ShiftLEDOut= 254;
ShiftLEDIn = 8;
LCDText=unescape("%20%43%68%61%72%6f%6e%20%49%49%20%64%65%6d%6f%20%0a
%45%74%68%65%72%6e%75%74%20%50%72%6f%6a%65%63%74");
RS232DataOut =unescape("%44%61%74%61%20%74%6f%20%52%53%32%33%32");
RS232Speed =9601;
RS232DataIn =unescape("");
Thermometer = 26.6250 ;
;
if ((ShiftLEDOut =="<#ShiftLEDOut>")||(ShiftLEDOut==null)) 
      ShiftLEDOut = 0xAA;
	  
if ((ShiftLEDIn  =="<#ShiftLEDIn>  ")||(ShiftLEDIn  ==null))   
      ShiftLEDIn = 0x55;
	  
if ((LCDText     =="<#LCDText>     ")||(LCDText     ==null)) 
      LCDText = "    LCD Text"+"\n"+"Ethernut project";

if ((RS232DataOut=="<#RS232DataOut>")||(RS232DataOut==null)) 
      RS232DataOut= "RS232 Data Out" + "\n" + "0123456789";

if ((RS232Speed  =="<#RS232Speed>  ")||(RS232Speed  ==null)) 
      RS232Speed= 9600;
	  
if ((RS232DataIn =="<#RS232DataIn> ")||(RS232DataIn ==null)) 
      RS232DataIn= "RS232 Data In" +"\n" + "0123456789";

if ((Thermometer =="<#Thermometer> ")||(Thermometer ==null)) 
      Thermometer= 0.0001 + "\n" + 0.0002 + "\n" + 0.0003;
...
				

Additional information

All firmware is written for use with compiler WinAVR and NutOs version 3.3.0. For use with another compiler it is necessary to rewrite some compiler unsupported functions (e.g. as strtok_r function).

Project files must be located in directory \ethernut\nut\app\<ProjectDirectory> to ensure correct inclusion of some headers.

Project was created by Ing. Igor Cesko for for the HW-group company. Additional routines for LCD display control, shift registers control, 1-wire thermometers reading, threads processing, UART control, TCP control was collected from www.HW-group.com resources and examples included in NutOS operating system www.ethetnut.de.
 
 

Compile informations

For your own Charon 2 peripherals demo code (version 1.0.4), this compile and development applications list can be useful:

Development system

Source codes:

Instalation process

  • Install WinAVR (leave checked checkbox for automatic set environment variables),
  • Install Ethernut (run file \ethernut\nut\nutconf.exe and configure system),
  • Copy Development Board demo to the directory - \ethernut\nut\app\db_demo
     

Make process

  • Current directory \ethernut\nut\app\db_demo,
  • Entry „make“ from the command line – it’ll create demo,
  • Entry „make burn“ from the command line – firmware upload to the Charon2,
  • Configure demo in the Charon 2 from the serial port on the USART0 and connect to the webpage.

 

You can test this demo online on our public IP address : 80.250.3.195 in our Prague office.

 

Ordering

Available now! You can order: Charon 2 module only or complete Charon 2 Development Kit.

We have a minimum of 20 pcs in stock at all times. It can be shipped via FedEx next day all over the world. We accept payement by Credit Cards or Wire Transfer, check our prices in the PriceList .

Or try to contact your nearest distributor of our products - International Distributors .  

Charon 2 Development Kit included

  • The Charon 2 module with MAC address and serial number on the label. 
  • The Charon I&II Development Board (Shortly Development Board only). 
  • An HW STK-500 compatible programming adapter for serial RS-232 port. 
  • A LapLink serial communication cable with a DB-9 female socket on both ends. 
  • The DS1822 1-Wire thermometer sensor 
  • A LCD display 2x16  
  • CD with all necessary software in the /Charon2/ directory

 

Recommended links & literature

 

Similar or related products

  • Project Web51 - http://web51.hw-server.com/  
     
  • Project Web51-C
    Web51-C is a development kit for creating embedded Ethernet UDP and SNMP applications based on the 8051 microcontroller family.
    Web51-C is a migration of the Web51 project that was completely written in assembler, to the C language. The free SDCC or the commercial KEIL C51 compiler can compile the application code.

 


  Main page Products Support & Download Pricelist Contacts SiteMap  


HW group - Prague - Czech republic - Europe