HOME            UP --^           NEXT-->>  Demo-2
side4linux, a simple integrated development environment!

AVRC Demo-1  Communicate with the 'MC1' Machine Controller CPU board via the 'Bterm' program.


Purpose: 
Test the Machine Controller MC-1, Central Processing Unit's ability to communicate with the controlling computer using AVR 'C'.

Requirements:
Make sure that the latest 'AVRChelp' package is installed.

Further Requirements:
Pre-Requisites:
Preamble:
This is the AVR 'C' communication testing practical for the MC-1 CPU Board, it tests the Serial port of your computer and the MC-1 CPU using the command line 'Bterm' communication program provided.


Step-1: Build the 'HelloC' Project and load it into the MC-1 CPU using the MC-1 Programmer.

As a first step in the Practical we are going to connect up all the cables used in PCBS Practical-8 and switch the computer on and then switch the power supply on. Check that all your voltages are correct and switch off in reverse sequence. Now plug in the Serial cable from 'Serial Port-0' of the MC-1 CPU to an RS232C Serial Port of your computer (refer to Figure-0 below for the correct position for 'Serial-0'). Notice here that Serial-1 shares the PortE pins with the Programmer (Atmel did this not us!) so make sure always that Serial-1 has no cable plugged into it during programming on any occasion! You should have removed the pin from pin-1 (the square sided one ) of the male IDC ribbon cable socket and pushed it into the 10 pin female plug of the serial communication ribbon cable. By doing this first you are polarizing the plug and socket so that they cannot be plugged together the wrong way round. Do not be tempted to use polarized 10 pin sockets on the pcb as we will use a 22 ribbon cable plug when needing to use both serial communication ports.

MC-1 CPU Layout
Fig-0 MC-1 CPU Top Layout showing Serial Port - 0


Switch on your computer once the serial communication ribbon cable is plugged in. Your computer should be still operating normally!
Set your preferences to the Serial port you have used, either '0' for the first serial port or '1' for the second
with 'Preferences>IDE>Basic>ComPort'

Bring up the side4linux IDE on your computer and open the test project's 'helloc.prf' file,  /SIDE/PRODUCTS/MC1/AVRC/Helloc/helloc.prf using 'Project>Open Project'  from the Main Menu as follows,

Open Project Hello C
Fig-1 Open HelloC Project Dialog


Now open the file 'main.c' using the 'Open-TXT' Toolbar button. You are now looking at a basic master 'C' language file for the Machine Controller modified for the 'Hello World' practical in this Demo. Click on the 'Build' button in the Toolbar and you should see the following in the Output Window below the open file ( or similar! ).

make  all-recursive
make[1]: Entering directory `/home/db/Data/Projects/SIDE/PRODUCTS/MC1/AVRC/Helloc'
Making all in src
make[2]: Entering directory `/home/db/Data/Projects/SIDE/PRODUCTS/MC1/AVRC/Helloc/src'
avr-gcc  -g -Wall -O2 -mmcu=atmega128 -DHAVE_CONFIG_H  -Wl,-Map,helloc.map -o helloc  atmega128.o WriteSerial.o main.o 
avr-gcc -g -Wall -O2 -mmcu=atmega128 -DHAVE_CONFIG_H -Wl,-Map,helloc.map -o output.elf atmega128.c atmega128.h WriteSerial.c WriteSerial.h main.c main.h
avr-objdump -h -S output.elf > helloc.lst
avr-objcopy -j .text -j .data -O ihex output.elf upprog.hex
avr-objcopy -j .eeprom --change-section-lma .eeprom=0 -O ihex output.elf upeeprom.hex
rm -f *.elf
make[2]: Leaving directory `/home/db/Data/Projects/SIDE/PRODUCTS/MC1/AVRC/Helloc/src'
make[2]: Entering directory `/home/db/Data/Projects/SIDE/PRODUCTS/MC1/AVRC/Helloc'
make[2]: Leaving directory `/home/db/Data/Projects/SIDE/PRODUCTS/MC1/AVRC/Helloc'
make[1]: Leaving directory `/home/db/Data/Projects/SIDE/PRODUCTS/MC1/AVRC/Helloc'

+++ Successful Make command! +++

You have done more than just compile the code, the IDE has also transferred your machine code program Flash file and your EEprom data file to the 'dbavrprog' serial programming program's 'files' directory ready for uploading to your MC-1 CPU. These files are 'upprog.hex' and 'upeeprom.hex', in 'Intel 8-bit Hex' file format. Note that if you were building your own board for an unrelated Product then the procedure will remain the same but we are concentrating only on the MC-1 for the rest of this Demo. OK, now that you have code to upload to your MC-1 CPU you will need to open the 'dbavrprog' program to program your AVR chip '. Launch the serial programming program as ,
'Tools>AVRC>AVR PROGRAM',
you should be greeted by 'sudo's' password dialog similar to the graphic below,

 Sudo Dialog Box
Fig-2 Sudo Dialog Box.

After using your normal password that you signed on with and on clicking the Continue' button you should now have the dbavrprog screen up on your display as follows,


dbavrprog Sign On Screen
Fig-3 dbavrprog sign on screen.

Now to set up access to your printer port, click on the 'SetSerial' button and you should be greeted with the message,

I/O Permission granted

    Port Access Granted, you may continue!


Try the 'ReadID' button and see if you get the following message,

  Looking for signature bytes = : 1E :  97 :  02 : 

If you do not get the message or the ID bytes are wrong then close the programmer program and alter the IDE's global Delay timing value to a higher number.

  'Preferences>IDE>Basic>
Delay Value'

( 5 = OK for 1 Gigahertz machine, more for faster machines and less for slower ones! ),

Now if you can get this far click on the 'EraseALL' button then on the 'Test' button. This should turn up the following message or something similar!

Testing Flash Memory for Full Erasure!
Trying to Upload Intel Hex file files/upprog.hex to measure length!
Verify program Flash of length 004F0h bytes in progress!

Verify Program Address     0 = FFFF
Verify Program Address   100 = FFFF
Verify Program Address   200 = FFFF
Verify Program Address   300 = FFFF
Verify Program Address   400 = FFFF
Verify Program Address   500 = FFFF

 Trying to read 'EESAVE' Fuse on chip,  'EESAVE' flag = 0
 OK testing Flash Memory, I will now test EEprom Memory for Full Erasure.

Verify EEprom Address -->     0 = FF
Verify EEprom Address -->   100 = FF
Verify EEprom Address -->   200 = FF
Verify EEprom Address -->   300 = FF
Verify EEprom Address -->   400 = FF
Verify EEprom Address -->   500 = FF
Verify EEprom Address -->   600 = FF
Verify EEprom Address -->   700 = FF
Verify EEprom Address -->   800 = FF
Verify EEprom Address -->   900 = FF
Verify EEprom Address -->   A00 = FF
Verify EEprom Address -->   B00 = FF
Verify EEprom Address -->   C00 = FF
Verify EEprom Address -->   D00 = FF
Verify EEprom Address -->   E00 = FF
Verify EEprom Address -->   F00 = FF
Verify EEprom Address -->  1000 = FF

The Program and EEprom memory are erased!

Once you can complete 'Test' successfully you are ready to do some programming!
Click on the 'WriteFlash' button and get the following or something similar!

Attempting to write the program Flash Type-2

Uploading Intel Hex file files/upprog.hex to Program Flash memory

Writing Addr: 00000 Data|05C0|
Writing Addr: 00100 Data|002D|
Writing Addr: 00200 Data|0D91|

Writing Image to Program Flash
Writing Page: 0000
Writing program Flash Page:0 to chip
Verifying Page 00:80 Addr 00080
Writing Page: 0001
Writing program Flash Page:1 to chip
Verifying Page 01:80 Addr 00100
Writing Page: 0002
Writing program Flash Page:2 to chip
Verifying Page 02:80 Addr 00180
Writing Page: 0003
Writing program Flash Page:3 to chip
Verifying Page 03:80 Addr 00200
Writing Page: 0004
Writing program Flash Page:4 to chip
Verifying Page 04:80 Addr 00280

Write from file to Program Flash was successful

Notice that you must click on the 'EraseALL'  button then the 'Test' button and test the Flash for erasure before trying to program the Flash! The EEprom can be programmed at anytime but you must set the 'EESAVE' fuse yourself (unset by default) to prevent the 'EraseALL' button from erasing the EEprom along with the Flash. Also once the 'EESAVE' fuse is set then the 'Test' button only checks the Flash for erasure.

Step-2: Call up the command line version of 'bterm' to look for the 'sign-on message'.
  1. Switch off the power supply.
  2. Close the programmer program and change workspace by clicking on the workspace switcher or right clicking on your Desktop.
  3. Change to the '/SIDE/TOOLS/SIDEtools/CLC/Bterm/src' directory and open a 'root' terminal there.
For newcomers you can do this as follows from a normal terminal e.g.,
if your user name was 'fred', from the Linux Desktop's Main Menue where you call programs,

MainMenue>Accessories>Terminal
You have changed to bterm's Project source directory and now issue the following command './bterm 0',  or './bterm 1' depending on the Computer's serial port you are using.
You should see the following on your screen (or similar!),

Attempting to Set Permissions
I/O Permission granted
Bterm GLASS TERMINAL PROGRAM Ver 1.6 (c) D. BURKE 17/7/1992 -> 2007
Commands available are,
    QR   <enter>    Toggle RESET line of MC-1 programmer to reset MC-1 CPU.

     ~    <enter>     Enter a 'tilde' then press 'enter' to Quit!

Displaying UART Registers

port --> 02F8   contents --> 10
port --> 02F9   contents --> 0
port --> 02FA   contents --> 1
port --> 02FB   contents --> 7
port --> 02FC   contents --> 1
port --> 02FD   contents --> 96
port --> 02FE   contents --> 0
scale reg low  -->   contents --> 12
scale reg high -->   contents --> 0

Notice the full stop and forward slash before the program name, this says to launch this program from the current folder and not some other program called bterm from the usual PATH.
  Also notice the space between the change directory 'cd' command and the forward slash that starts the target directory location. For other ways of using 'su' and 'sudo' re-read 'setup C build environment.txt'  and re-read PCBS Demo-8.

Step-3: Verify the Sign On Message and End.

Turn on the power supply and the following message should appear on the screen or similar!
( if not then try turning the power supply off then on again. If that does not work then issue a 'QR' reset command on the bterm terminal. )

MC-1 Ver 8.0 -  Hello World!

If you do not get the sign on message ( or it is corrupted ) then there are some reasons,
So look at the 'main.c' file in the IDE Notebook window ( similar to below ),

// Opening file for AVR ATmega128 chip to run the 'Hello World' program from the MC-1 CPU.

#include <avr/sleep.h>          // for 'sleep_mode()' function
#include "main.h"                  // edit to tell compiler your Xtal frequency!
#include "atmega128.h"         // user written chip specific functions
#include "WriteSerial.h"        // user written serial port output functions

int main(void)
{
  atmega128_InitChip();            // initiate chip also telling us the Xtal frequency
  WriteSerial_0("MC-1 Ver 8.0 - Hello World!\n"); // send 'Hello World' message on serial-0

  for (;;) sleep_mode();           // loop forever, and let interrupts do the rest!
  return(0);


Notice the 'return' value, this is needed to keep the 'C' compiler happy as we are using the 'GNU' compiler outside it's normal environment of returning to an operating system. You can see that we have included 'include' files to allow access to routines in the 'AVR LibC' library and also some files to provide write functions to our serial-0 port which you can open for your own interest. Click on the 'Files' tab in the File Tree Explorer to the left of the Notebook and expand the arrows to see Functions available.

You must put your 'include' files into the Project,
Project>Add Files to Project
to have them compiled and linked into the output Hex file.

We have gone out of our way to make this build environment similar to the other 'C' build environments in 'side4linux' so check out 'CLC' and 'GNOMEC' projects for more Demo's and help.
Do not forget to set the crystal frequency in 'main.h' if your crystal is different to ours!

Congratulations if you have got this far as this is the end of Demo-1!


In Demo-2 we will set up a new Product using an Atmel AVR ATtiny13 to show you how to use 'side4linux' for building your own Products and related Projects.


We will provide other demos as 'side4linux' develops to cover integration into a real world machine controller.