Egel project for

MSP430G2553

on Launchpad or Egel Kit

Willem Ouwerkerk with help from Albert Nijhof

juli 2016, full revision 2020

Leon Konings, Frans vd Markt,

Jeroen Hoekstra & Willem Ouwerkerk Willem Ouwerkerk with help from Albert Nijhofjuli 2016, General introduction

Introduction for non-forthers

Egel project table of content

The 'Egel project' consists of about 50 elementary examples of hardware control with the MSP430 in the language forth. In each example you find a file with forth source code, documentation and links to more information on the internet.



It is our aim to lower the hurdles that beginners with the MSP430 MPU find on their way to hardware programming using noForth software. With the many examples in the Egel project we hope to make it easier to understand the Texas Instruments documentation.



We recommend to read the chapters 0, 1, 2 and 3 before you choose the chapters that have your special interest!

History

The original The original Egel werkboek was written in 1997 for the AT89C2051 microcontrollers by a group of Dutch Forth-gg members. It was initially named 'Postzegelboek' (dutch) but that was considered to be too long, so it was shortened to 'Egelboek'. postzegel 'poss say ghull' = stamp egel 'ay ghull' = hedgehog boek 'book' = book

The 'Egel project' consists of about 50 elementary examples of hardware control with the MSP430 in the language forth. In each example you find a file with forth source code, documentation and links to more information on the internet.We recommend tobefore you choose the chapters that have your special interest!

0

Starting with noForth Control of on-board LEDs Materials: Only the Egel-kit or LaunchPad e00 noForth program

If you have not used noForth on a MSP430 board before, this chapter is for you. It explains from scratch how to get a running noForth program.



Where to find more information:

The following documents give a good overview of noForth and the MSP430 processor:



General introduction

Introduction for non-Forthers

Readme-1 (ram&rom.pdf)

Readme-2 (freeze&forget.pdf)

If you have not used noForth on a MSP430 board before, this chapter is for you. It explains from scratch how to get a running noForth program.The following documents give a good overview of noForth and the MSP430 processor:



All downloads and other instructions can be found on the noForth homepage.



First - set up of software and hardware:



What you need is:





Egel-kit or TI LaunchPad with MSP430G2553.

noForth C2553 or V2553 as hex-file, contained in the zipfile noforths 2553.zip.



The TI program Uniflash to burn noForth on the LaunchPad or Egel-kit. Read this document when you use the Egel-kit.

Communication-program on your computer (Windows, Linux or OSX see the homepage).

Text-editor like Crimson or Notepad++

USB-serial cable to connect the board to your computer.

Using the noForth homepage as guide, load noForth on the Egel-kit or LaunchPad.



Install the communication-program.



Connect the LaunchPad to the PC with the USB-serial cable.



Then - start the LaunchPad and Terminal:



Start the communication (terminal) program. In that program, select the port to which the Egel-kit or LaunchPad is connected, and start a connection.



NoForth returns ok on each enter if it is running. If not, check that you have done all the steps. If at first you dont succeed...



Then  load the noforth tools.f:



Once noForth is running, load the noForth tools to get additional functionality like: .S SEE and WORDS . Download the file noforth tools.f on your PC. Then upload the file to the Egel-kit or Launchpad using your communication program. With some programs it is possible to copy/paste the source code into the window of the communication-program.

Once the noForth tools are loaded, typing ' WORDS ' will show an overview of the dictionary. Well done! noForth and the tools are running, and you have loaded your first noForth-program..



Disconnect the Egel-kit/LaunchPad does not delete noForth or the tools. Reloading both is usually only needed if you want a different version of noForth.



Then - load the noForth program e00:

Load the noForth program e00 (see above) on the board and enter  FLASH .



Then - try to understand the source-code:

If you look at the source-code you will see explanatory comments. Studying and experimenting with the source code is an excellent way of learning to program in noForth! Feel free to change the source-code and see what happens.



Finally - Reloading source-code

It is smart to delete old source-code first before loading a new version, or you could run out of memory. There is a handy tool in noForth for this, a shield. When called, all words defined after it are deleted. The noForth-tools you loaded earlier are terminated by the shield ' TOOLS\ '. Type this to delete the old source-code. Then load the new source-code and see what effect your changes have. For more information on shields, see the 'noForth documentation'.





The forth command: FLASH ( -- ) \ starts the simple flasher ⇧ All downloads and other instructions can be found on the noForth homepage.What you need is:Using the noForth homepage as guide, load noForth on the Egel-kit or LaunchPad.Install the communication-program.Connect the LaunchPad to the PC with the USB-serial cable.Start the communication (terminal) program. In that program, select the port to which the Egel-kit or LaunchPad is connected, and start a connection.NoForth returns ok on each enter if it is running. If not, check that you have done all the steps. If at first you dont succeed...Once noForth is running, load the noForth tools to get additional functionality like:and. Download the file noforth tools.f on your PC. Then upload the file to the Egel-kit or Launchpad using your communication program. With some programs it is possible to copy/paste the source code into the window of the communication-program.Once the noForth tools are loaded, typing '' will show an overview of the dictionary. Well done! noForth and the tools are running, and you have loaded your first noForth-program..Disconnect the Egel-kit/LaunchPad does not delete noForth or the tools. Reloading both is usually only needed if you want a different version of noForth.Load the noForth program e00 (see above) on the board and enter .If you look at the source-code you will see explanatory comments. Studying and experimenting with the source code is an excellent way of learning to program in noForth! Feel free to change the source-code and see what happens.It is smart to delete old source-code first before loading a new version, or you could run out of memory. There is a handy tool in noForth for this, a shield. When called, all words defined after it are deleted. The noForth-tools you loaded earlier are terminated by the shield ''. Type this to delete the old source-code. Then load the new source-code and see what effect your changes have. For more information on shields, see the 'noForth documentation'.The forth command:

1

Basic port output Byte wide output to I/O-port 2, connected to eight leds Materials: Some wires, 8 leds or a ledboard, 100 Ohm resistor. e01 noForth program In this example 8 LEDS are controlled by a noForth program. If this is the first time you use noForth on a MSP430, it might be good to first work through chapter 0, which gives a detailed overview of the steps needed to get a noForth program running.



Setup of hardware:

Place eight LEDs on the breadboard. Connect the individual anodes to pins P2.0 ... P2.7 of the LaunchPad with wires. (more information on the ports in In this example 8 LEDS are controlled by a noForth program. If this is the first time you use noForth on a MSP430, it might be good to first work through chapter 0, which gives a detailed overview of the steps needed to get a noForth program running.Place eight LEDs on the breadboard. Connect the individual anodes to pins P2.0 ... P2.7 of the LaunchPad with wires. (more information on the ports in SLAU144J.PDF page 328ff. More information on P2SEL on page 50ff. of SLAS735J.PDF

Connect the



noForth program e01:

Program e01 contains two commands, COUNTER and RUNNER which demonstrate how to control the LEDs. Both terminate if you press any key. Connect the cathodes of the leds together on the breadboard with wires connect them to the ground using a 100 Ohm resistor, and finally connect the ground of the breadboard to the ground of the LaunchPad.Program e01 contains two commands, COUNTER and RUNNER which demonstrate how to control the LEDs. Both terminate if you press any key.

Forth commands: COUNTER ( -- ) Binary counter on P2 RUNNER ( -- ) Running light on P2 * Open images in a new window for a better resolution. Forth commands: ⇧

2

Basic port input and output Byte output to I/O port wired with 8 leds and bit input using a switch Materials: 8 leds or a ledboard, 100 Ohm resistor. e02 noForth program This chapter builds on the previous chapter. The addition is the S2‑switch (if you use the Egel-board and/or MSP-EXP430G2 than the switch is already on the board), which is connected to port P1.3 for input. 1.



The forth commands remain the same: COUNTER ( -- ) Binary counter on P2 RUNNER ( -- ) Running light on P2 When the S2‑switch is held down the leds will run at a higher speed in COUNTER and RUNNER .



* Open images in a new window for a better resolution. This chapter builds on the previous chapter. The addition is the S2‑switch (if you use the Egel-board and/or MSP-EXP430G2 than the switch is already on the board), which is connected to port P1.3 for input. 1.The forth commands remain the same:When the S2‑switch is held down the leds will run at a higher speed inand ⇧

3

Onboard ADC Analog to digital conversion using the internal AD converter, output to leds Materials: 8 leds or a ledboard, 100 Ohm resistor, 4K7 potmeter. e03 noForthprogram This chapter is an extension of chapter 1 and 2. This time a potentiometer of about 4K7 is added. Connect the center wire of the potentiometer to P1.7 and the other two wires to VCC and ground.



You can find more info about the ADC10, in This chapter is an extension of chapter 1 and 2. This time a potentiometer of about 4K7 is added. Connect the center wire of the potentiometer to P1.7 and the other two wires to VCC and ground.You can find more info about the ADC10, in SLAU144J.PDF on page 534 and beyond.

The forth commands: SHOW-ADC1 ( -- ) Show ADC result in binary SHOW-ADC2 ( -- ) Show ADC result as VU-meter SHOW-ADC3 ( -- ) Show ADC result on screen as text

The only way these routines differ are in the way the results are shown. The forth commands:The only way these routines differ are in the way the results are shown. * Open images in a new window for a better resolution. ⇧

4

RS232 using a Bluetooth module Bluetooth communication, visualized on the leds Materials: 8 leds or a ledboard, 100 Ohm resistor, HC08 Bluetooth module. e04 noForth program

This chapter shows how to connect a Bluetooth module to a Launchpad, use that module to receive characters and show these characters using 8 LEDs.



You can use either the HC06 or HC08 module. These modules behave like a standard serial port, only without wires! They need a voltage of 3.3V. In this example we use the RS232 (TX/RX TTL levels) interface. For more information see the



Connect the HC06/08 with the Launchpad: HC06/08 power (pin12 and 13) with Launchpad J6 (VCC and GND),

HC06/08 TX and RX (pin1 and 2) with Launchpad J1 (pin3 and 4).

Connect 8 leds as in chapter 1. Remove the jumpers TX and RX at J3 from the Launchpad. When you use the Egel-kit just press the board on the connector marked 'BLUETOOTH' as is shown on the picture.



This chapter shows how to connect a Bluetooth module to a Launchpad, use that module to receive characters and show these characters using 8 LEDs.You can use either the HC06 or HC08 module. These modules behave like a standard serial port, only without wires! They need a voltage of 3.3V. In this example we use the RS232 (TX/RX TTL levels) interface. For more information see the HC08 datasheet Connect the HC06/08 with the Launchpad:Connect 8 leds as in chapter 1. Remove the jumpers TX and RX at J3 from the Launchpad. When you use the Egel-kit just press the board on the connector marked 'BLUETOOTH' as is shown on the picture.



Load program e4.

The initial password is usually 1234.



Type STARTUP or press the reset key, and all communication will go through Bluetooth. Received characters will be shown on the leds.







How to end STARTUP:

Just press reset together with switch S2 and noForth skips the STARTUP program! Load program e4. Pair with the HC06/08 The initial password is usually 1234.Typeor press the reset key, and all communication will go through Bluetooth. Received characters will be shown on the leds.Just press reset together with switch S2 and noForth skips theprogram! ⇧

5

Relay control Relay control, with or without a delay Materials: 22 Ohm and 1K resistor, 1N4148 diode BC549C or N channel Mosfet, High power led. e05 noForth program A relay is a very useful device. It enables a small device, like a micro-controller, to switch currents or voltages which the device itself could not handle. This example shows how to control a relay and emulates the delay used for elevator doors.



Place a 5-Volt relay on the shield, as shown in the schematic and photo.



Please note that the driving transistor and the voltage powering the relay may need adaptation. The Egel kit already contains a mosfet to drive the relay. Just connect the relay to the PWR-output!



A relay is a very useful device. It enables a small device, like a micro-controller, to switch currents or voltages which the device itself could not handle. This example shows how to control a relay and emulates the delay used for elevator doors.Place a 5-Volt relay on the shield, as shown in the schematic and photo.Please note that the driving transistor and the voltage powering the relay may need adaptation. The Egel kit already contains a mosfet to drive the relay. Just connect the relay to the PWR-output!

Bit input comes from P1.3 (S2).

Bit output goes to P2.4.



Forth command: RELAY-CONTROL ( -- )

By default an off delay is performed here. Bit input comes from P1.3 (S2).Bit output goes to P2.4.Forth command:By default an off delay is performed here.



Try different kinds of delays by changing the lines in the word RELAY-CONTROL with the backslashes. Only select one option at a time! Try different kinds of delays by changing the lines in the wordwith the backslashes. Only select one option at a time! ⇧

6

Unipolar stepper motor Controlling a four phase unipolar stepper motor Materials: Stepper module & motor, Some wires. e06 noForth program Being able to control a stepper motor is very useful for robot- and other projects where something has to move. noForth on a MSP430 micro-controller makes it easy!



The used module has a



Launchpad - connections:



P2.0 .. P2.3 (output) with IN1 .. IN4 of the ULN2003 driver

+5 Volt and Gnd

Switch S2 to P1.3 if you do not use the Egel-kit or MSP430 starterkit

Being able to control a stepper motor is very useful for robot- and other projects where something has to move. noForth on a MSP430 micro-controller makes it easy!The used module has a ULN2003 driver on it. It only needs 5 wires to control a stepper-motor.Launchpad - connections: Forth command: STEPPER ( -- ) Change direction with S2‑switch.



The default method is a one-phase stepper. By editing the word ONE-STEP you may select single phase, two phase or half step driven stepper control. Only choose one method at a time.



About stepper motors Forth command:Change direction with S2‑switch.The default method is a one-phase stepper. By editing the wordyou may select single phase, two phase or half step driven stepper control. Only choose one method at a time. ⇧

7

Bipolar stepper motor Controlling a two phase bipolar stepper motor Materials: L9110 bridge driver module, Some wires, 5 Volt bipolar stepper motor. e07 noForth program

There are two usual kinds of stepper motors: unipolar and bipolar. This example shows control of a bipolar stepper motor, the unipolar motor is used in the previous chapter.





The used module has two



Launchpad - connections: P2.0 .. P2.3 (output) with A1-B, A1-A, B1-B and B1-A of the driver

+5 Volt and Gnd

Switch S2 to P1.3 ( if you do not use the Launchpad or Egel-kit ) There are two usual kinds of stepper motors: unipolar and bipolar. This example shows control of a bipolar stepper motor, the unipolar motor is used in the previous chapter.The used module has two L9110S drivers on it. It only takes 4 wires to control a bipolar stepper motor.Launchpad - connections:

Forth command: STEPPER ( -- ) Change direction with S2-switch.



The default method is a one-phase stepper, By editing the word ONE-STEP you may select single phase, two phase or half step driven stepper control. Only choose one method at a time!



About stepper motors Forth command:The default method is a one-phase stepper, By editing the wordyou may select single phase, two phase or half step driven stepper control. Only choose one method at a time! ⇧

8

Ultrasonic distance measurement Controlling a HC-SR04 ranging sensor Materials: 8 leds or Led module, HC-SR04, some wires, e08 noForth program

Measuring distances is useful in many applications. It can easily be done with an ultrasound sensor and a MSP430.

Connect the



P1.3 is the input bit. The length of the received pulse, in microseconds, is converted to the distance.

P1.4 is the output bit, a positive pulse starts a new measurement. Measuring distances is useful in many applications. It can easily be done with an ultrasound sensor and a MSP430.Connect the SR04 sensor with the MSP430 and place the led-board on the shield.P1.3 is the input bit. The length of the received pulse, in microseconds, is converted to the distance.P1.4 is the output bit, a positive pulse starts a new measurement.

This example is software timed, so the result very much depends on

1) The clock frequency

2) Active interrupts

3) The Forth implementation



Forth command: MEASURE - Show distance in steps of 2cm binary on leds

The usable range of the low-cost Chinese version of the HC-SR04 is around 2cm to 220cm.



About ultrasonic sensors. This example is software timed, so the result very much depends on1) The clock frequency2) Active interrupts3) The Forth implementationForth command:The usable range of the low-cost Chinese version of the HC-SR04 is around 2cm to 220cm. ⇧

9

PWM using compare unit Using pulse-width modulation to control a LED Materials: 2x 100 Ohm resistor, N channel mosfet, Powerled, 2x Switch. e09 noForth program Pulse-width modulation (PWM) is used to simulate an analogue output, for instance for controlling the brightness of a LED.



Connect two switches, a transistor and a power led using the schematic and photo.



The 'up' key is connected to P1.4,

The 'down' key is connected to P1.5.



The transistor is connected via resistor R2 to P2.4



Timer TA1 is used as a pulsewidth modulator, with a frequency of about 4KHz and a resolution of 1000 steps. Pulse-width modulation (PWM) is used to simulate an analogue output, for instance for controlling the brightness of a LED.Connect two switches, a transistor and a power led using the schematic and photo.The 'up' key is connected to P1.4,The 'down' key is connected to P1.5.The transistor is connected via resistor R2 to P2.4Timer TA1 is used as a pulsewidth modulator, with a frequency of about 4KHz and a resolution of 1000 steps.

Forth commands: CYCLUS ( -- ) Cycle once thru PWM range POWERCONTROL ( -- ) Set PWM value using two switches

The two switches control the brightness of the LED by varying the duty-cycle.



This program is so simple because it utilizes the intrinsic PWM-functionality of the MSP430. A software-only solution would use up all available CPU capacity.



A Video on PWM Forth commands:The two switches control the brightness of the LED by varying the duty-cycle.This program is so simple because it utilizes the intrinsic PWM-functionality of the MSP430. A software-only solution would use up all available CPU capacity. ⇧

10

RC-5 coder/transmitter RC-5-bitpatterns generated by software Materials: 1x 100 Ohm resistor, 1x Infrared led. noForth assembler e10 noForth program Load the assembler before the e10 noForth programs, some parts of the program are in assembler code. The RC-5 protocol is used by the remote-control of most televisions. This example shows how to emulate it.



For the Egel Kit: connect an IR-led to the LED connector P2.1. If you use a LaunchPad, add a resistor to the LED.



Timer A1 generates 36KHz pulses with 25% PWM at P2.1.

The S2‑switch activates the transmitter. The RC-5 protocol is used by the remote-control of most televisions. This example shows how to emulate it.For the Egel Kit: connect an IR-led to the LED connector P2.1. If you use a LaunchPad, add a resistor to the LED.Timer A1 generates 36KHz pulses with 25% PWM at P2.1.The S2‑switch activates the transmitter.

More info about timer-A1, in



Forth command: RC-TRANSMITTER ( -- ) Send the RC5 on/off command

This program will startup after every reset. If you do not want this, press reset while holding down S2.



About the RC-5 protocol More info about timer-A1, in SLAU144J.PDF on page 356ff. Configuration of the I/O-pins from page 50ff. in SLAS735J.PDF Forth command:This program will startup after every reset. If you do not want this, press reset while holding down S2. ⇧

11

7-segment display driver with CD4094 or 74HC595 Using a shift-register to drive a 7-segment display Materials: 8x 470 Ohm resistor, 1x 7 segment display, 1x 74HC4094 or 74HC595. e11a ca noForth program e11b cc noForth program A shift-register converts serial data to parallel data, this makes it possible to control a 7-segment display with 3 wires to the MSP430.



Connect a 74HC4094 to VCC and ground

Strobe 74HC4094 pin-1 to P2.0

Data 74HC4094 pin-2 to P2.1

Clock 74HC4094 pin-3 to P2.2 (N.B.)

Pin 15 to VCC too. A shift-register converts serial data to parallel data, this makes it possible to control a 7-segment display with 3 wires to the MSP430. Connect the eight output pins (4 to 11) of the Connect the eight output pins (4 to 11) of the 74HC4094 to a 7-segment display. See schematics.

Connect a 74HC595 to VCC and ground

Strobe 74HC595 pin-12 to P2.0

Data 74HC595 pin-14 to P2.1

Clock 74HC595 pin-11 to P2.2 (N.B.)

Pin 13 to ground & pin 10 to VCC too. Connect the eight output pins (15 and then 1 to 7) of the



If more digits are needed, it is possible to connect more 74HC4094s or 74HC595s to each other. The strobe and clock lines are connected in parallel, a separate data-line is needed for each display. See schematics.



Common-anode displays can also be used. In that case connect the ground connections of the display to VCC (see schematics) and use software e11a. Software e11b is for the shown common cathode displays. Connect the eight output pins (15 and then 1 to 7) of the 74HC595 to a 7-segment display. See schematics.If more digits are needed, it is possible to connect more 74HC4094s or 74HC595s to each other. The strobe and clock lines are connected in parallel, a separate data-line is needed for each display. See schematics.Common-anode displays can also be used. In that case connect the ground connections of the display to VCC (see schematics) and use software e11a. Software e11b is for the shown common cathode displays.



Forth commands: CHARACTERS ( -- ) Show all implemented characters COUNTER ( -- ) Show a decimal counter DICE ( -- ) Simulate a tumbling dice

A 3 cm. high common anode 7-segment module

Background on seven segment displays Forth commands: ⇧

12

Controlling a character LCD Using a 4-bit parallel interface & PWM-based contrast-control Materials: 2x bat48, 1x 100nF, 1x 220nF, some wires, 1x DIP LCD module. e12 noForth program A LCD-display with 2 lines of 16 characters is useful in a lot of projects. Only 6 connections are needed to show text on the display. One more connection controls the contrast of the display. In this example timer-A1 generates the needed PWM-signal.



The two capacitors and diodes are forming a



Connect a 3 Volt version of a 1602 LCD display with P2.0 .. P2.5 (see schematics) P1.6 is the contrast control output for the LCD.

Timer-A1 is used for contrast control of the LCD, see schematic.



When the text is not visible or legible, try adjusting the contrast-setting with >CONTRAST . Values between 0 and 16 are valid. A LCD-display with 2 lines of 16 characters is useful in a lot of projects. Only 6 connections are needed to show text on the display. One more connection controls the contrast of the display. In this example timer-A1 generates the needed PWM-signal.The two capacitors and diodes are forming a charge pump . This charge pump is used to generate the negative voltage for the contrast control of the LCD.Connect a 3 Volt version of a 1602 LCD display with P2.0 .. P2.5 (see schematics) P1.6 is the contrast control output for the LCD.Timer-A1 is used for contrast control of the LCD, see schematic.When the text is not visible or legible, try adjusting the contrast-setting with. Values between 0 and 16 are valid.

Forth commands: >CONTRAST ( +n -- ) Set contrast to +n (valid values: 0:16) DEMO1 ( -- ) Show text message 1 DEMO2 ( -- ) Show text message 2 Forth commands: ⇧

13

Hi-resolution US distance measurement Using timer-A0 for increased accuracy, with timeout Materials: 8 leds or Led module, HC-SR04, some wires. e13 noForth program

This chapter builds on chapter 8. Again ultrasound is used to measure distance, but better!



In this example both accuracy and resolution of the measurements are higher, by better use of the features of the MSP430 with better software.



Time is measured with timer-A0, with a microsecond resolution. An advantage of using a timer is that activated interrupts do not influence the result. If timer-A0 is already in use, change the register addresses of timer-A0 to addresses of a free, similar timer (



Connect the SR04 sensor or similar, with four wires to the MSP430 place a LED-board or connect individual LEDs (see schematics). This chapter builds on chapter 8. Again ultrasound is used to measure distance, but better!In this example both accuracy and resolution of the measurements are higher, by better use of the features of the MSP430 with better software.Time is measured with timer-A0, with a microsecond resolution. An advantage of using a timer is that activated interrupts do not influence the result. If timer-A0 is already in use, change the register addresses of timer-A0 to addresses of a free, similar timer ( see slas735J page 18 ). This variant times out after ~65 milliseconds, so it will not hang if nothing is measured.Connect the SR04 sensor or similar, with four wires to the MSP430 place a LED-board or connect individual LEDs (see schematics). The word DISTANCE starts the US-sensor, and returns a distance to the nearest object in centimeter. When in the source-code in the word DISTANCE , >CM is changed to >MM the distance is returned in millimeters.



The usable range of available US-sensors varies. The cheap Chinese HC-SR04 modules have a range of 2cm to 220cm. Other variants may have different ranges, sometimes up to 600 cm. The wordstarts the US-sensor, and returns a distance to the nearest object in centimeter. When in the source-code in the wordis changed tothe distance is returned in millimeters.The usable range of available US-sensors varies. The cheap Chinese HC-SR04 modules have a range of 2cm to 220cm. Other variants may have different ranges, sometimes up to 600 cm. The photo shows three pin-compatible replacements for the HC-SR04.



The US-015 is more stable and has more accurate readings

The RCW-0001 is much smaller and works from 3 Volt.

The US-100 works from 2.4 Volt and has an additional mode with an increased resolution. It also has built-in temperature-compensation resulting in solid-as-a-rock measurements. The distance is measured in millimeters. See chapter E17 for example code.

Forth commands: US-ON ( -- ) Activate ultrasonic hardware DISTANCE ( -- cm ) Show object distance in centimeter (or mm) MEASURE ( -- ) Show object distance on leds The photo shows three pin-compatible replacements for the HC-SR04.Forth commands: ⇧

14

Generating dual frequencies with 2 timers Frequency output using timer-A0 & timer-A1 Materials: 2x 50 Ohm speaker. e14a noForth program e14b noForth program The outputs are P1.6 and P2.1. The timers in the MSP430 are well suited to generate sounds of varying frequencies. By using two timers, two different frequencies can be generated at the same time. The frequency range is 61 Hz to 39000 Hz. In this example P1.6 and P2.1 are used as outputs.



Both ports must be wired to a 32 to 50 Ohm speaker, connect the other lead of the speaker to ground.



Program 14a plays simple music scores.

You have no support for audio!

Play the hunting horn

The outputs are P1.6 and P2.1.The timers in the MSP430 are well suited to generate sounds of varying frequencies. By using two timers, two different frequencies can be generated at the same time. The frequency range is 61 Hz to 39000 Hz. In this example P1.6 and P2.1 are used as outputs.Both ports must be wired to a 32 to 50 Ohm speaker, connect the other lead of the speaker to ground.Program 14a plays simple music scores.Play the hunting horn



Program 14b generates You have no support for audio!

Call the Forth users group Program 14b generates DTMF tones!Call the Forth users group

The forth commands for e14a: HONK ( -- ) Sound a heavy horn HUNTING ( -- ) Play the hunting horn BJOHN ( -- ) Play Brother John And for e14b: >DTMF ( addr u -- ) Convert string to DTMF tones WILLEMO ( -- ) Call the author FORTHGG ( -- ) Call Forth-gg chairman The forth commands for e14a:And for e14b:

⇧

15

MSP430 clocks Using the different system-clocks on the MSP430 Materials: Egel Kit or Launchpad, Some wires and a large elco, Multimeter. e15a noForth program e15b noForth program VLO noForth program 32kHz noForth program The MSP430 processor can use one of several system-clock sources. This example allows you to experiment with this feature.



The frequency of the clock-source strongly influences the power-consumption. By connecting an ampere-meter you can see this effect.





Programs e15a and e15b are the same except for the speed of communication. Program e15a connects at 9600 baud, and works with all noForth versions for the MSP430G2553 Launchpad. Program e15b only works on the Egel kit, but communicates at 38400 baud.



The MSP430 processor can use one of several system-clock sources. This example allows you to experiment with this feature.The frequency of the clock-source strongly influences the power-consumption. By connecting an ampere-meter you can see this effect.Programsandare the same except for the speed of communication. Programconnects at 9600 baud, and works with all noForth versions for the MSP430G2553 Launchpad. Programonly works on the Egel kit, but communicates at 38400 baud. The 12kHz and 32kHz noForth words activate the Very Low Frequency or 32kHz oscillator. At 12kHz serial communication is not possible, due to the low and inaccurate frequency of the VLO. At 32kHz communication is only possible at 9600 baud. The 12kHz and 32kHz noForth words activate the Very Low Frequency or 32kHz oscillator. At 12kHz serial communication is not possible, due to the low and inaccurate frequency of the VLO. At 32kHz communication is only possible at 9600 baud. To allow for a function-check with an oscilloscope or logic analyzer, two additional programs activate the 12kHz or 32kHz frequency on output P1.0. For more information about the built-in capacitors for the 32kHz oscillator, see SLAU144J.PDF page 274 and beyond. To allow for a function-check with an oscilloscope or logic analyzer, two additional programs activate the 12kHz or 32kHz frequency on output P1.0. For more information about the built-in capacitors for the 32kHz oscillator, see SLAU144J.PDF page 274 and beyond. The MSP430 can function with or without a crystal. To ensure good accuracy without a crystal, T.I. calibrates every individual MSP430. The calibration-data for the DCO starts at address 10F6 (within the info-flash segment A starting at 10C0) and both e15a and e15b make use of the calibration-data.



Please note that programming FLASH-memory is not possible if the MSP430 is running at 32 kHz, as the FLASH-memory clock must be in the range of 257-476 kHz.



The Forth commands for e15a & e15b: 12KHZ ( -- ) Use VLO oscillator 32KHZ ( -- ) 32kHz oscillator active 1MHZ ( -- ) Set DCO at 1 MHz 8MHZ ( -- ) Use DCO at 8MHz 16MHZ ( -- ) DCO on 16MHz BLINK ( ccc -- ) Run blinker at freq. 'ccc' Example of BLINK this is how: BLINK 32KHZ or one of the other frequencies. It demonstrates that the timing of the MSP430 is independent of the used system-clock by flashing both LEDs every 6 seconds. After the program is finished, the default MPU frequency is restored. The MSP430 can function with or without a crystal. To ensure good accuracy without a crystal, T.I. calibrates every individual MSP430. The calibration-data for the DCO starts at address 10F6 (within the info-flash segment A starting at 10C0) and bothandmake use of the calibration-data.Please note that programming FLASH-memory is not possible if the MSP430 is running at 32 kHz, as the FLASH-memory clock must be in the range of 257-476 kHz.Example ofthis is how:or one of the other frequencies. It demonstrates that the timing of the MSP430 is independent of the used system-clock by flashing both LEDs every 6 seconds. After the program is finished, the default MPU frequency is restored. ⇧

16

Half, 3/4 & full duplex software UART Bit input on P2.1 bit output to P2.0 Materials: Egel kit or Launchpad, USB serial cable . noForth assembler e16a Half duplex UART e16b 3/4 duplex UART e16c Full duplex UART Load the assembler before the e16 noForth programs, the software RS232 routines are in assembler code.

This example shows how to code half, ¾ and full duplex UART-connections using only software (=bitbang method). That is without using the specific UART hardware on the MSP430.



To use the examples, first make a second RS232 connection: connect the RX lead to P2.0 (logic level) and the TX lead to P2.1 and connect ground to ground. Then open a second terminal window for the new port. Load one of the programs and press the RESET-button. Output should now appear in the second terminal window.



The first variant (e16a) does not use an interrupt and is half duplex only. The second variant (e16b) reads incoming characters using a receive-interrupt based on timer-A0. This gives you about 3/4 duplex. The reception of characters is faultless, but the sending of characters is occasionally spoiled by the receive-interrupt. The third variant (e16c), in addition to the receive-interrupt, also uses a transmit-interrupt based on timer-A1. This is a full duplex connection, but uses all the timers on board of the MSP430G2553.



This example shows how to code half, ¾ and full duplex UART-connections using only software (=bitbang method). That is without using the specific UART hardware on the MSP430.To use the examples, first make a second RS232 connection: connect the RX lead to P2.0 (logic level) and the TX lead to P2.1 and connect ground to ground. Then open a second terminal window for the new port. Load one of the programs and press the RESET-button. Output should now appear in the second terminal window.The first variant () does not use an interrupt and is half duplex only. The second variant () reads incoming characters using a receive-interrupt based on timer-A0. This gives you about 3/4 duplex. The reception of characters is faultless, but the sending of characters is occasionally spoiled by the receive-interrupt. The third variant (), in addition to the receive-interrupt, also uses a transmit-interrupt based on timer-A1. This is a full duplex connection, but uses all the timers on board of the MSP430G2553. You can use the following commands to test your program in the old RS232 configuration (before pressing RESET):



Type: RS-ON To initialise software RS232.

Type: CH # RS-EMIT MANY To test RS232 output.



Type: COLD When these routines work.



Check the results on your screen in the terminal windows.



To go back to the old configuration hold S2 and then press the RESET-button. The newly added RS-ON routine is skipped and you're back in the original configuration. You can use the following commands to test your program in the old RS232 configuration (before pressing RESET):Type:To initialise software RS232.Type:To test RS232 output.Type:When these routines work.Check the results on your screen in the terminal windows.To go back to the old configuration hold S2 and then press the RESET-button. The newly addedroutine is skipped and you're back in the original configuration. ⇧

17

US-100 ultrasonic distance sensor Using timer-A0 for software RS232 - NOW with timeout! Materials: US-100 sensor, some wires. e17 noForth program



This example shows how to measure a distance with a US-100 sensor in serial mode using RS232.



Connect the US-100 sensor with four wires to the MSP430 as shown. In this example we use timer‑A0 for the RS232 connection (see previous chapter). When timer‑A0 is already in use, change the register addresses to those of a similar free timer. This example shows how to measure a distance with a US-100 sensor in serial mode using RS232.Connect the US-100 sensor with four wires to the MSP430 as shown. In this example we use timer‑A0 for the RS232 connection (see previous chapter). When timer‑A0 is already in use, change the register addresses to those of a similar free timer.

The word DISTANCE starts the US-sensor, and returns the distance to the nearest object in millimeters. The distance-measurement by the US-100 module is very stable due to the built-in temperature compensation. The range of the sensor is about 30mm to 4000mm and it works from 2.4 Volt to 5 Volt. The used serial mode has an increased resolution.



The wordstarts the US-sensor, and returns the distance to the nearest object in millimeters. The distance-measurement by the US-100 module is very stable due to the built-in temperature compensation. The range of the sensor is about 30mm to 4000mm and it works from 2.4 Volt to 5 Volt. The used serial mode has an increased resolution.

Forth commands: RS-ON ( -- ) Activate sofware serial interface DISTANCE ( -- mm ) Show object distance in millimeters MEASURE ( -- ) Show object distance on screen Forth commands: ⇧

18

Simple robotic sensor unit Reading touch sensors and a PIR motion detector Materials: robot sensor board, AM312 PIR sensor, N-channel mosfet, Screw clamp. e18 noForth program This chapter provides an interface to the Robotic sensor module Even if you do not own such a sensor-module, it might still be a useful example. For instance when you want to add a couple of DIY touch-sensors to a robot. Adapting the software for that is easy.





Print layout for the simple robotic sensor unit. On it two feelers, a PIR sensor and two LEDs.



This chapter provides an interface to the Robotic sensor module Even if you do not own such a sensor-module, it might still be a useful example. For instance when you want to add a couple of DIY touch-sensors to a robot. Adapting the software for that is easy. The internal schematic of the

The internal schematic of the SB312A smart PIR sensor unit. Note that the sensor has it's own 3 Volt voltage stabiliser. The sensor output already has a 10 kOhm resistor.

Forth commands: MOTION? ( -- fl ) True when PIR sensor senses motion TOUCH-LEFT? ( -- fl ) True when left feeler bend TOUCH-RIGHT? ( -- fl ) True when right feeler bend ?LED ( fl -- ) Leds on when fl is true SENSORS ( -- ) Test the sensor module Forth commands: ⇧

20

Timer A0 compare mode Flashing LEDS with a timer compare interrupt Materials: Just the kit. noForth assembler e20 noForth program This example shows how to use timer‑A0 in compare mode to generate timer interrupts. Both SMCLK (high frequency) or ACLK (low frequency) can be used to drive the timer. This example shows how to use timer‑A0 in compare mode to generate timer interrupts. Both SMCLK (high frequency) or ACLK (low frequency) can be used to drive the timer.

Load the assembler before the e20 noForth programs, the software RS232 routines are in assembler code.

More info about MSP430 clocks can be found in More info about MSP430 clocks can be found in chapter 15 . Compare mode 2 is used, so timer‑A0 counts up to FFFF.

Change the flash frequency of the LEDs by changing PERIOD . Higher means slower. The default content of PERIOD is 1.

Example: 5 TO PERIOD



The forth commands: SMCLK-ON ( -- ) Activate timer-A0 with SMCLK ACLK-ON ( -- ) Activate timer-A0 with ACLK TIMER-OFF ( -- ) Deactivate timer-A0 Change the flash frequency of the LEDs by changing. Higher means slower. The default content ofis 1.Example:The forth commands: ⇧

21

RC servo controller Using timer-A0 to control the pulsewidth of 2 servos, bit-output Materials: 2x small or standard size model servos. noForth assembler e21 noForth program Load the assembler before the e21 noForth program, the interrupt-routines are in assembler code.

This really is a fun example. It shows how to control two servos using timer-A0!



Connect P1.4 and P1.5 to the signal line of each servo, see the schematics and photo.



The position of a servo is set with the word SERVO ( pos srv -- ) where pos can have a value between 0 and 200. The word MOVE-SERVOS changes the position of each servo endlessly. This really is a fun example. It shows how to control two servos using timer-A0!Connect P1.4 and P1.5 to the signal line of each servo, see the schematics and photo.The position of a servo is set with the wordwhere pos can have a value between 0 and 200. The wordchanges the position of each servo endlessly. SERVO-ON ( -- ) Activate servo interrupt SERVO-OFF ( -- ) Deactivate servo interrupt SERVO ( pos srv -- ) Set servo 'srv' to 'pos' (0-200) MOVE-SERVOS ( -- ) Move both servos endlessly About RC servos ⇧

22

Low frequency PWM using a timer interrupt Software PWM (on timer‑A0) with three outputs Materials: 2x 100 Ohm resistor, BS170 or BUK954, Powerled. noForth assembler e22 noForth program This example implements Pulse Width Modulation on 3 outputs using timer-A0. It can be used to control items like lamps, electric motors or LEDs.



Load the assembler before the e22 noForth program. Connect a motor, lamp or power led to P2.4 using a MOSFET, see schematics. The outputs are on P2.2, P2.3 and P2.4, and the output-power can be changed in steps from 0 to 100. The frequency is 300 Hz, so there is a 3,3msec update rate. The demo-program SHOW-PWM changes all 3 outputs differently every 64 milliseconds. Connect a motor, lamp or power led to P2.4 using a MOSFET, see schematics. The outputs are on P2.2, P2.3 and P2.4, and the output-power can be changed in steps from 0 to 100. The frequency is 300 Hz, so there is a 3,3msec update rate. The demo-programchanges all 3 outputs differently every 64 milliseconds.

Due to the software structure, the PWM interrupt leaves small glitches when the power is zero. Here is a small challenge left for the programmer.



Due to the software structure, the PWM interrupt leaves small glitches when the power is zero. Here is a small challenge left for the programmer. Forth command: >POWER ( pow n  ) Set the power of output 'n' to 'pow' (pow between 0-100) SHOW-PWM ( -- ) Change all three PWM outputs endlessly

About PWM Forth command: ⇧

23

Hardware interrupt Hardware interrupt with bit input and output on P1 and p2 Materials: 100 Ohm, Led board, Switch. noForth assembler e23 noForth program Load the assembler before the e23 noForth program, the interrupt routine is in assembler code. Using the schematics, connect a toggle-switch (SW1) and a LED-board, or connect individual LEDs as explained in chapter 1. S2 and the green and red LED are already on the board.



The red LED is controlled by polling S2 in a high-level software loop and toggling the LED. The green LED by a hardware interrupt triggered by SW1. There is only simple debouncing in this example, the delay value in the polling loop is used for that.



Forth commands: LED ( -- ) starts the demo Using the schematics, connect a toggle-switch (SW1) and a LED-board, or connect individual LEDs as explained in chapter 1. S2 and the green and red LED are already on the board.The red LED is controlled by polling S2 in a high-level software loop and toggling the LED. The green LED by a hardware interrupt triggered by SW1. There is only simple debouncing in this example, the delay value in the polling loop is used for that.Forth commands: ⇧

24

Watchdog timer Watchdog initialisation and use Materials: Just the kit. e24 noForth program This example shows how to initialize and use the watchdog-timer.



The primary function of a watchdog timer is to perform a controlled system restart when a software problem occurs. For this the watchdog timer counts down from a starting-value to zero.



As soon as zero is reached, a system-restart occurs. This restart is avoided by having the software reset the counter so frequently that zero is never reached. If a serious problem occurs with the software, the watchdog timer reaches zero and a restart will happen.



The activating time of the watchdog can be changed. Either ACLK or SMCLK can be used, and a clock-divider can be set. In this example SMCLK is used. The lowest two bits of the WDTCL register set the clock divider. Here the divider is set to 00 = SMCLK/32768. More info on page 346 in SLAU144J.PDF



The value 'u' is a delay value for a simple software loop. When this loop takes longer than the activating time, the watchdog restarts the MPU. This example shows how to initialize and use the watchdog-timer.The primary function of a watchdog timer is to perform a controlled system restart when a software problem occurs. For this the watchdog timer counts down from a starting-value to zero.As soon as zero is reached, a system-restart occurs. This restart is avoided by having the software reset the counter so frequently that zero is never reached. If a serious problem occurs with the software, the watchdog timer reaches zero and a restart will happen.The activating time of the watchdog can be changed. Either ACLK or SMCLK can be used, and a clock-divider can be set. In this example SMCLK is used. The lowest two bits of the WDTCL register set the clock divider. Here the divider is set to 00 = SMCLK/32768. More info on page 346 in SLAU144J.PDFThe value 'u' is a delay value for a simple software loop. When this loop takes longer than the activating time, the watchdog restarts the MPU.

Forth command: WATCHDOG ( u -- ) Test watchdog trigger point to 'u' milliseconds. In steps of 160 millisec. Forth command:Test watchdog trigger point to 'u' milliseconds. In steps of 160 millisec. ⇧

25

Watchdog as interval timer Watchdog used as interval timer to implement an accurate MS routine Materials: Just the kit. e25 noForth program If there is no need for a watchdog timer, it can alternatively be used as an interval-timer. This example shows how. If there is no need for a watchdog timer, it can alternatively be used as an interval-timer. This example shows how. When used as an interval-timer, the watchdog again counts down to zero (see chapter 24). But, instead of a restart, triggers an interrupt. In this example, the watchdog interrupt lowers the value MS) to zero.



The lowest two bits of the WDTCL register set the clock divider, here the divider is set to 01 = SMCLK/8192. More info on page 344ff. in SLAU144J.PDF



Forth command: INTERVAL ( ms -- ) Switch red LED on when interval starts, green LED goes on when the interval is finished. When used as an interval-timer, the watchdog again counts down to zero (see chapter 24). But, instead of a restart, triggers an interrupt. In this example, the watchdog interrupt lowers the valueto zero.The lowest two bits of the WDTCL register set the clock divider, here the divider is set to 01 = SMCLK/8192. More info on page 344ff. in SLAU144J.PDFForth command:Switch red LED on when interval starts, green LED goes on when the interval is finished. ⇧

26

RC-5 decoder RC-5 remote control decoder and power control for MSP430 Launchpad Materials: 2x 100 Ohm resistor, N channel Mosfet, Powerled, RC-5 receiver, 6 leds or Led module. noForth assembler e26 noForth program This is a fun example. It shows how to make a egel-kit or launchpad react to a remote-control of a television! If you use a launchpad, there is a bit of fiddling with hardware, but the result is an excellent base for extensive remote-control functionality.



Interesting fact: the code is an example of two cooperating interrupt routines. This is a fun example. It shows how to make a egel-kit or launchpad react to a remote-control of a television! If you use a launchpad, there is a bit of fiddling with hardware, but the result is an excellent base for extensive remote-control functionality.Interesting fact: the code is an example of two cooperating interrupt routines.

Load the assembler before the e26 noForth program. The IR-receiver must be a 36 kHz, 3 Volt version, like



When you use an Egel kit, connect the infrared receiver to the RC5 connector. As output connect a power LED with a 47 Ohm series resistor to the LED connector or to the PWR connector (max. 2 Amp).



For the Launchpad follow the schematic. Either connect a power LED with a 47 Ohm series resistor to P2.1 directly. Or you could connect a MOSFET to P2.1 and use that to drive something more powerful.



For the example RC-TEST , connect 6 LEDs or a LED-module to P2.2 to P2.7. RC-TEST shows the received 6-bits key-code on the LEDs.



Forth commands: RC-LAMP ( -- ) Control output P2.1 using on/off key RC-POWER ( -- ) Control output P2.4 using on/off key RC-TEST ( -- ) Display RC-5 commands binary on LED-array

The IR-receiver must be a 36 kHz, 3 Volt version, like TSOP34536 When you use an Egel kit, connect the infrared receiver to the RC5 connector. As output connect a power LED with a 47 Ohm series resistor to the LED connector or to the PWR connector (max. 2 Amp).For the Launchpad follow the schematic. Either connect a power LED with a 47 Ohm series resistor to P2.1 directly. Or you could connect a MOSFET to P2.1 and use that to drive something more powerful.For the example, connect 6 LEDs or a LED-module to P2.2 to P2.7.shows the received 6-bits key-code on the LEDs.Forth commands: Above: Output from the RC-5 receiver; below: Toggle of the power led. Above: Output from the RC-5 receiver; below: Toggle of the power led. ⇧

27

Period time measurement Bit input on P1.3 to sample timer-A0 Materials: Egel kit or Launchpad. noForth assembler Change noForth configuration e27a noForth program e27b noForth program e27c noForth program Measuring is a standard task for a micro-controller. This example shows how to measure time-periods, frequency and rotational speed (in RPM = revolutions per minute).



Load the assembler before the e27 noForth programs, the interrupt routines are in assembler code. Measuring is a standard task for a micro-controller. This example shows how to measure time-periods, frequency and rotational speed (in RPM = revolutions per minute). About the three example programs: e27a Contains the low level routines and conversion to and printing of the period time in seconds.

e27b Conversion to and printing of frequency in Hz.

e27c Does conversion to and printing revolutions in RPM.

Type PERIOD to start the period-measurement. Pressing S2 twice toggles P1.3 twice and the time-interval between the two toggles is measured and printed. The length of an external pulse connected to p1.3 can also be measured. Please note that the pulse must be 3.3 Volt. Suitable conversion must be done when not. Add amplification when the signal is too small, add an attenuator-network when the signal is too large.



About the three example programs:Typeto start the period-measurement. Pressing S2 twice toggles P1.3 twice and the time-interval between the two toggles is measured and printed. The length of an external pulse connected to p1.3 can also be measured. Please note that the pulse must be 3.3 Volt. Suitable conversion must be done when not. Add amplification when the signal is too small, add an attenuator-network when the signal is too large. The code of example e27b can be tested with a second Egel kit or Launchpad. Run program e14 on the second Egel kit/launchpad and connect output P1.6 of the e14 example to input P1.3 of this example. Then type: 100HZ TONE0 in the E14 example, type FREQUENCY in the e27b example and see the results on your screen.



The code of example e27c can be tested as example e27b but with the word RPM .



Each example has one forth command: PERIOD ( -- ) \ File e27a, measure time-period FREQUENCY ( -- ) \ File e27b, measure frequency RPM ( -- ) \ File e27c, measure rotation speed The code of example e27b can be tested with a second Egel kit or Launchpad. Run program e14 on the second Egel kit/launchpad and connect output P1.6 of the e14 example to input P1.3 of this example. Then type:in the E14 example, typein the e27b example and see the results on your screen.The code of example e27c can be tested as example e27b but with the wordEach example has one forth command: ⇧

30

I2C input & output to PCF8574 Using I2C to connect two 8-bit parallel I/O-drivers Materials: I2C-print or other I2C-module with PCF8574. I2C-bitbang primitives e30 Bitbang noForth program e30 USCI noForth program

For program e30, the bit-bang version, it is necessary that the I2C-primitives are loaded first. This example shows how to connect two 8-bit IO-expanders (PCF8574) using the I2C-protocol. Although it is primarily focused on the I2C-board of the Dutch Forth users group, the example can also be helpful for other boards and DIY-builds.



Please do not try to understand the I2C-primitives. The complete and documented I2C-bitbang source code can be found in chapter 37. All I2C examples, apart from chapter 38, come in a USCI and bit-bang implementation. How to use the USCI to implement the I2C-protocol is described in SLAU144J.PDF on page 449ff., the register documentation on page 467ff.



If you use the I2C-print from the Dutch Forth users group, connect the power lines first, then P1.7 to SDA and P1.6 to SCL and do not forget to mount the two pull-up resistors.



If you build yourself, connect the



Please note: there are two versions of the PCF8574, the A-version has a different device address!





The forth commands: RUNNER1 ( -- ) Running light with output only RUNNER2 ( -- ) Running light with switch input too SHOW ( -- ) Show I2C input on outputs More: This example shows how to connect two 8-bit IO-expanders (PCF8574) using the I2C-protocol. Although it is primarily focused on the I2C-board of the Dutch Forth users group, the example can also be helpful for other boards and DIY-builds.Please do not try to understand the I2C-primitives. The complete and documented I2C-bitbang source code can be found in chapter 37. All I2C examples, apart from chapter 38, come in a USCI and bit-bang implementation. How to use the USCI to implement the I2C-protocol is described in SLAU144J.PDF on page 449ff., the register documentation on page 467ff.If you use the I2C-print from the Dutch Forth users group, connect the power lines first, then P1.7 to SDA and P1.6 to SCL and do not forget to mount the two pull-up resistors.If you build yourself, connect the PCF8574 and 8 LEDs according to the schematics. Please make sure that pins A1 and A2 of the PCF8574 are connected to ground, and PIN A0 to VCC. For RUNNER2 and SHOW a second PCF8574 is needed with eight switches. Connect as the first PCF8574, but connect the A0, A1 and A2-pins to ground. This ensures that the second PCF8574 uses a different I2C-address.The forth commands:More: Wikipedia on I2C and I2C.org ⇧

35

I2C character LCD using a PCF8574 I2C output to an LCD using an 8-bit parallel I/O-driver Materials: I2C-print or other, 2x16 LCD, I2C LCD adapter. I2C-bitbang primitives I2C USCI primitives e35 Bitbang noForth program e35 USCI noForth program For both versions it is necessary that the correct I2C-primitives are already loaded. Connect a 3 or 5 Volt version of an 1602 LCD display to an I2C adapter print. Only four wires are needed: VCC, GND, SDA=P1.7, & SCL=P1.6



Use the potmeter for contrast control, see schematic.



The forth commands: LCD-SETUP ( -- ) Initialise LCD LCD-EMIT ( ch -- ) Send character 'ch' to LCD LCD-TYPE ( adr u -- ) Type string 'a' 'u' to LCD DEMO ( -- ) Type a message on LCD Connect a 3 or 5 Volt version of an 1602 LCD display to an I2C adapter print. Only four wires are needed: VCC, GND, SDA=P1.7, & SCL=P1.6Use the potmeter for contrast control, see schematic.The forth commands: ⇧

36

I2C adc module YL-40 I2C analog input using a PCF8591 module YL-40, from AliExpress Materials: I2C-module with PCF8591. I2C-bitbang primitives I2C USCI primitives e36 Bitbang noForth program e36 USCI noForth program For both versions it is necessary that the correct I2C-primitives are already loaded.

Connect the I2C-module with PCF8591 to P1.7 to SDA and P1.6 to SCL.

090 = PCF8591 I2C-bus identification address 0.

The PCF8591 has four 8-bit ADC inputs and one 8-bit DAC output. The used module is wired as shown below.



0 ADC ( Read AIN0 = LDR )

1 ADC ( Read AIN1 = Thermistor )

2 ADC ( Read AIN2 = Free )

3 ADC ( Read AIN3 = Potmeter )

DAC is connected to an output and a green led.



Forth commands: ADC ( +n -- byte ) Read ADC input '+n' leaving 'byte' DAC ( byte -- ) Write 'byte' to DAC output ANALOG ( +n -- ) Read input '+n' send to screen & DAC The PCF8591 has four 8-bit ADC inputs and one 8-bit DAC output. The used module is wired as shown below.( Read AIN0 = LDR )( Read AIN1 = Thermistor )( Read AIN2 = Free )( Read AIN3 = Potmeter )is connected to an output and a green led.Forth commands: ⇧

37

I2C basics at P1 Primitives for the bitbang & USCI versions of I2C Materials: I2C specification. noForth assembler e37 Bitbang master program e37 USCI I2C master program e37 USCI I2C slave program The files can be used to construct either bitbang or USCI applications. The files can be used to construct either bitbang or USCI applications. Connect for example the I2C-print from the Forth users group or any other module with I2C compatible chip(s).

Connect VCC, GND, P1.7 to SDA and P1.6 to SCL.

Do not forget that two pullup resistors have te be mounted.



Note that the bitbang implementation does not use clockbit stretching.



Connect for example the I2C-print from the Forth users group or any other module with I2C compatible chip(s).Connect VCC, GND, P1.7 to SDA and P1.6 to SCL.Do not forget that two pullup resistors have te be mounted. For the USCI implementation:



The most hard to find data, are those for the selection registers. To find the data for the selection register of Port-1 here 026 and 041 you have to go to the "Port Schematics". For P1.6 and P1.7 these are page 48 and 49 of SLAS735J.PDF These tables say which function will be on each I/O-bit, at a specific setting of the registers.



Address 026 - P1SEL, port-1 selection register

Address 041 - P1SEL2, port-1 selection register 2



A description of USCI as I2C can be found in SLAU144J.PDF from page 449 to page 473, the register description starts at page 468. The UCB0CTL0 register selects the SPI- or I2C-mode we are in.



More: More: Wikipedia on I2C and I2C.org ⇧

38

I2C USCI master and slave implementation I2C slave input and output Materials: 2x 10kOhm, 8 leds or Led board, 2x Launchpad or Egel Kit, I2C slave function. noForth assembler e38a USCI I2C master e38b USCI I2C slave Load the assembler before the e38a/b noForth programs, the software RS232 routines are in assembler code. The bitrate values are for an 8 MHz DCO, for 16 MHz they should be doubled.



This code is improved, the routines work very solid, >SLAVE and SLAVE> give an error mesage when the addressed device does not respond. The bitrate values are for an 8 MHz DCO, for 16 MHz they should be doubled.This code is improved, the routines work very solid,andgive an error mesage when the addressed device does not respond. Program e38a implements the I2C master. The program e38b implements the I2C slave. For both versions there are output- and input-examples. See the list below. Program e38a implements the I2C master. The program e38b implements the I2C slave. For both versions there are output- and input-examples. See the list below.

Connect one ore more MSP-EXP430G2 Launchpads. You may also use Egel Kits (from the Forth users group). Add 6 or 8 leds and connect VCC, GND, P1.7 to SDA and P1.6 to SCL.

Don't forget the two pullup resistors of 10k and two line protection resistors of 220 Ohm. See schematics.



The I2C-slave examples must be used in pairs, one MPU executes a word from the first table, the other has to execute the word on the second table.

The master command MASTER-TRIO implements a master with two slaves!



Forth commands e38um: MASTER-OUT ( -- ) Show a running light on leds & slave 1 MASTER-IN ( -- ) Change flash speed with data from slave MASTER-IO ( -- ) Running light, delay with S2 from slave MASTER-TRIO ( -- ) Count on slave 1, running light slave 2 Change speed with S2 from slave 1 Forth commands e38us: SLAVE-IN1 ( -- ) Display data from master SLAVE-OUT ( -- ) Send S2 to master, flash leds SLAVE-IO ( -- ) Get & send data from/to master SLAVE-IN2 ( -- ) Display data in slave 2 Connect one ore more MSP-EXP430G2 Launchpads. You may also use Egel Kits (from the Forth users group). Add 6 or 8 leds and connect VCC, GND, P1.7 to SDA and P1.6 to SCL.Don't forget the two pullup resistors of 10k and two line protection resistors of 220 Ohm. See schematics.The I2C-slave examples must be used in pairs, one MPU executes a word from the first table, the other has to execute the word on the second table.The master commandimplements a master with two slaves!Forth commands e38um:Forth commands e38us: Start the I2C-slave before you start the I2C-master! The slave controller always waits for the master to claim the slave.

The second example file contains a master with two slaves.





A video introduction to I2C master/slave I2C Start the I2C-slave before you start the I2C-master! The slave controller always waits for the master to claim the slave.The second example file contains a master with two slaves. ⇧

40

3-wire USCI SPI doing I/O Hardware SPI master & slave Materials: Two Egel Kits or Launchpads, ledboard or 8 leds, 100 Ohm resistor. e40u USCI noForth program Connect the SPI lines of USCI-B0 P1.5, P1.6 & P1.7 to the same pins on the other board. Connect 6 leds to P2 and start the slave on the unit with the led board. Connect the SPI lines of USCI-B0 P1.5, P1.6 & P1.7 to the same pins on the other board. Connect 6 leds to P2 and start the slave on the unit with the led board. More info on page 445 of SLAU144J.PDF.

Configuration of the pins on page 49 of SLAS735J.PDF.



The forth commands: SPI-MASTER ( -- ) Send binary counter, display answer SPI-SLAVE1 ( -- ) Display received data & sent it back SPI-SLAVE2 ( -- ) Translation of TI-example

More info on page 445 of SLAU144J.PDF.Configuration of the pins on page 49 of SLAS735J.PDF.The forth commands: About SPI ⇧

41

3-wire USCI SPI sending analog data ADC & hardware SPI I/O Materials: Two Egel Kits or Launchpads, ledboardor 8 leds, 100 Ohm resistor. e41u USCI noForth program Connect the SPI lines of USCI-B0 P1.5, P1.6 & P1.7 to the same pins on the other board.

Connect 6 leds to P2 and start the slave on the unit with the led board. Connect the SPI lines of USCI-B0 P1.5, P1.6 & P1.7 to the same pins on the other board.Connect 6 leds to P2 and start the slave on the unit with the led board. P1.3 on the MASTER is used as analog input, it is wired to a 4k7 potmeter to 3,3 Volt and ground.



More info on page 445 of SLAU144J.PDF.

Pin configuration on page 49 of SLAS735J.PDF



The forth commands: MASTER ( -- ) Send ADC to slave, receive dat from slave SLAVE ( -- ) Display ADC, sent counter back P1.3 on the MASTER is used as analog input, it is wired to a 4k7 potmeter to 3,3 Volt and ground.More info on page 445 of SLAU144J.PDF.Pin configuration on page 49 of SLAS735J.PDFThe forth commands: About SPI ⇧

42

4-digit 7-segment tube Using 3-wire bitbang SPI Materials: 4-digit 7-segm. led display. noForth assembler e42 Bitbang noForth program The program uses a compare timer interrupt with machine code to control a seven segment LED-display with 4-digits. The program uses a compare timer interrupt with machine code to control a seven segment LED-display with 4-digits.

The display module has two

It takes 4x39=156 microseconds every 12388 microseconds to fill the tube display, that is about 1.26% of the MSP430 cpu time. The display module has two 74HC595 shiftregister chips as drivers.It takes 4x39=156 microseconds every 12388 microseconds to fill the tube display, that is about 1.26% of the MSP430 cpu time. Load the assembler before the e42 noForth programs, the software RS232 routines are in assembler code. Connect a 74HC595 display module:

Pin-1 = VCC,

Pin-2 = P2.2 (SCLK),

Pin-3 = P2.0 (RCLK),

Pin-4 = P2.1 (DIO),

Pin-5 = Ground. Connect a 74HC595 display module:Pin-1 = VCC,Pin-2 = P2.2 (SCLK),Pin-3 = P2.0 (RCLK),Pin-4 = P2.1 (DIO),Pin-5 = Ground. All outputs are connected to a 7-segment display module. See schematic.



On the 74HC595:

OE\ = Low (when OE\ is high the outputs are disabled),

MR = High (when MR=low the shiftregister is reset),

DS = The data input,

SHCP = The clock input,

STCP = Strobe and acts on a positive transition.



Forth commands: COUNTER ( -- ) Run counter on tube display TU. ( u -- ) Print number on tube TCLR ( -- ) Clear tube display TDASH ( -- ) Print dashes on tube TMESSAGE ( -- ) Print message on tube All outputs are connected to a 7-segment display module. See schematic.On the 74HC595:OE\ = Low (when OE\ is high the outputs are disabled),MR = High (when MR=low the shiftregister is reset),DS = The data input,SHCP = The clock input,STCP = Strobe and acts on a positive transition.Forth commands: ⇧

43

nRF24L01+ send/receive Using 4-wire USCI & bitbang SPI Materials: Two Egel Kits or Launchpads, LDR, nRF24L01 module. e43a Bitbang noForth program e43b USCI noForth program Program 43a and 43b do the same, the a-version using a bitbang interface. The b-version uses the USCI interface from the MSP430.



Interfacing a Program 43a and 43b do the same, the a-version using a bitbang interface. The b-version uses the USCI interface from the MSP430.Interfacing a nRF24L01+ thru SPI with two Launchpad boards and/or Egel Kits. Carefully connect the SPI lines of USCI-B0 with the nRF24L01+ using Launchpad:



P1.5 = CLOCKPULSE,

P1.6 = DATA-IN,

P1.7 = DATA-OUT

P1.4 = CSN,

P2.3 = CE. Carefully connect the SPI lines of USCI-B0 with the nRF24L01+ using Launchpad:P1.5 = CLOCKPULSE,P1.6 = DATA-IN,P1.7 = DATA-OUTP1.4 = CSN,P2.3 = CE. On the Egel Kit you can simply put the module on the connector marked nRF24L01. Do the same with the other board. Connect a powerled & 47 Ohm resistor, and a LDR & 2k2 resistor for the remote control examples.

Note that, a good power supply and decoupling right near the nRF24L01+ module are very important. On theyou can simply put the module on the connector marked nRF24L01. Do the same with the other board. Connect a powerled & 47 Ohm resistor, and a LDR & 2k2 resistor for the remote control examples.Note that, a good power supply and decoupling right near the nRF24L01+ module are very important.

The Egel Kit vsn-2 has an extra 22μF near the nRF24L01+ power connections. Both the Launchpad and the Egel Kit vsn-1 may need an extra 10μF to 22μF for decoupling!



SPI reg: SLAU144J.PDF page 445.

SPI pins: SLAS735J.PDF page 49.



nRF24L01+ background

nRF24L01+ antenna modification





nRF24L01+ module connections The Egel Kit vsn-2 has an extra 22μF near the nRF24L01+ power connections. Both the Launchpad and the Egel Kit vsn-1 may need an extra 10μF to 22μF for decoupling!SPI reg: SLAU144J.PDF page 445.SPI pins: SLAS735J.PDF page 49.

Forth commands (these words are all stack neutral):



CHECK ( -- ) Control disturbance on the selected RF-channel (channel 112 or 128). CONTROL & LAMP Simple one way remote control. NRF-SEND & NRF-REC A counter demo, displayed on both boards (bi-directional communication). REMOTE & RECEIVER Remote controlled lamp, with lamp status feedback. Forth commands (these words are all stack neutral):

An nRF24L01 introduction ⇧

44

WS2812 RGB-led controller Using 1-wire USCI SPI for bit output Materials: 2 or more WS2812(B) leds, 5 Volt power supply 10A, or at Reichelt 5V-10A, Some wires. Change noForth configuration e44a noForth program e44b noForth program Program e44a is a slighty more easy to understand version of the



Connect a WS2812 ledstrip with 4 to 1000 leds to P1.7, +5 Volt and ground. Note that this code runs on a 16MHz clock! Program e44a is a slighty more easy to understand version of the WS2812 led controller. The program e44b has a virtual field length as extra for longer strings of leds. With this field function, longer led strings can be addressed in smaller chunks that are repeated to the end of the led string.Connect a WS2812 ledstrip with 4 to 1000 leds to P1.7, +5 Volt and ground. Note that this code runs on a 16MHz clock! USCI B0 is used to generate the bit pulses. The pulse timing is a little over the maximum frequency of 800kHz, but the WS2812 has no problems with that. All the demo's are just within WS2812 timing parameters (see drawings), sometimes the low part of the bit-pulses are streched to 4700 nanosec. Note also, that the maximum is 5000 nanosec. Longer low pulses are seen as strobe!



It is possible to control over a 1000 leds using this code. It takes about 33 millisec. to address this much leds. Just type dm 1000 >leds or the actual number of leds connected.

The time to address one led is about 0.033 millisec.

Take care 30 leds take about 9 Watt, that is almost 2 Ampere!









A few of the Forth user commands for e44a: >LEDS ( +n -- ) - Set number of leds connected ALL ( dc -- ) - Set all leds to color (double number) from the stack S1 S2 S3 ( -- ) - Three colorful shiftreg. examples S4 S5 ( -- ) - Two multidot shiftregister examples RAINBOW ( -- ) - Set a rainbow divided over all leds A few of the Forth user commands for e44b: >FIELD ( +n -- ) - Set led field length MSHIFT ( -- ) - Multidot shiftregister example VOLUME ( -- ) - Volume effect example BOUNCE ( -- ) - Bouncing dot example RAINBOW> ( -- ) - Shift a rainbow divided over all leds MSP430 & WS2812 demo USCI B0 is used to generate the bit pulses. The pulse timing is a little over the maximum frequency of 800kHz, but the WS2812 has no problems with that. All the demo's are just within WS2812 timing parameters (see drawings), sometimes the low part of the bit-pulses are streched to 4700 nanosec. Note also, that the maximum is 5000 nanosec. Longer low pulses are seen as strobe!It is possible to control over a 1000 leds using this code. It takes about 33 millisec. to address this much leds. Just typeor the actual number of leds connected.The time to address one led is about 0.033 millisec.Take care 30 leds take about 9 Watt, that is almost 2 Ampere!A few of the Forth user commands for e44a:A few of the Forth user commands for e44b: ⇧

50

Use of Low Power modes (LPM) Wake on hardware interrupt Materials: multimeter, ledboard. noForth assembler e50 noForth program The assembler must be loaded before the e50 noForth program. Connect a ledboard, see schematics, and ampere meter to check the current used in different modes.







The S2‑switch triggers the hardware-interrupt. This interrupt wakes up the MSP430 and activates a running light once. The MSP430 goes to a low power mode right after that.



The settings for P1.3 can be found from page 327 and beyond in SLAU144J.PDF



When you are using the Egel Kit, the jumper named ON/OFF may be used, to measure the current taken by the MSP430. Thus it is easy to see how the low power modes work out. Use on the launchpad, the jumper named VCC. This can be found on jumper strip J3.



Forth commands: SLEEP0 ( -- ) Test LPM mode 0 SLEEP2 ( -- ) Test LPM mode 2 SLEEP3 ( -- ) Test LPM mode 3 SLEEP4 ( -- ) Test LPM mode 4 (the sleep numbers indicate the low power mode ) Connect a ledboard, see schematics, and ampere meter to check the current used in different modes. Low Power Modes examples, using bit-input and bit-output. A hardware interrupt with machine code is used to wakeup, using Port-1 and Port-2.The S2‑switch triggers the hardware-interrupt. This interrupt wakes up the MSP430 and activates a running light once. The MSP430 goes to a low power mode right after that.The settings for P1.3 can be found from page 327 and beyond in SLAU144J.PDFWhen you are using the Egel Kit, the jumper named ON/OFF may be used, to measure the current taken by the MSP430. Thus it is easy to see how the low power modes work out. Use on the launchpad, the jumper named VCC. This can be found on jumper strip J3.Forth commands:(the sleep numbers indicate the low power mode )

A lecture on Low Power Modes and about Launchpad power usage ⇧

51

Using Low Power Modes (LPM) Wakeup using the watchdog interval timer Materials: multimeter, Egel Kit or Launchpad. noForth assembler e51 noForth program The assembler must be loaded before the e51 noForth program.

Connect an ampere meter to check the current used in different modes.



Watchdog as interval timer using LPM0, without use of LPM0 the CPU uses about 2,56mA (green led on ~10mA) with LPM0 it is ~0,45mA.

The lowest two bits of the WDTCL register do set the clock divider, here it is set to 01 = SMCLK/8192. The watchdog interrupt routine lowers the value MS) to zero.





The forth commands: MS ( ms -- ) Wait in LPM0 INTERVAL ( ms -- ) Idem Connect an ampere meter to check the current used in different modes.Watchdog as interval timer using LPM0, without use of LPM0 the CPU uses about 2,56mA (green led on ~10mA) with LPM0 it is ~0,45mA.The lowest two bits of the WDTCL register do set the clock divider, here it is set to 01 = SMCLK/8192. The watchdog interrupt routine lowers the valueto zero.The forth commands: ⇧

52

Low power switching clocks 32KHz interval timer & 8MHz DCO clock on wakeup Materials: multimeter, ledboard, noForth assembler e52 noForth program Load the assembler before the e52 noForth program.

Connect a ledboard, see schematics, and ampere meter to check the current used in different modes. In this example we use Low Power Modes, bit output, watchdog interrupt and machine code. When the program enters a low power mode, it runs on the 32kHz crystal. When active it uses the 8MHz DCO. The watchdog is used as interval timer, in steps of one second. Each time when it runs out, a running light is activated.



Current while full running!



The forth commands: SLEEP0 ( -- ) Test LPM mode 0 SLEEP2 ( -- ) Test LPM mode 2 SLEEP3 ( -- ) Test LPM mode 3 In this example we use Low Power Modes, bit output, watchdog interrupt and machine code. When the program enters a low power mode, it runs on the 32kHz crystal. When active it uses the 8MHz DCO. The watchdog is used as interval timer, in steps of one second. Each time when it runs out, a running light is activated.Current while full running!The forth commands: The number in name of the forth commands, indicates the low power mode that is used. The number in name of the forth commands, indicates the low power mode that is used. ⇧

53

Low power RC-5 decoder Consuming only 1/6 of the current Materials: 2x 100 Ohm resistor, N channel mosfet, Powerled, RC-5 receiver, 6 leds or Led module. noForth assembler e53 noForth program The assembler must be loaded before the e53 noForth program.

Put a 36 KHz infrared receiver on the RC5 connector. It must be a 3 Volt version like

Put a power led on the LED connector (with a 47 Ohm series resistor), or on the PWR connector (max. 2 Amp).



Put a 36 KHz infrared receiver on the RC5 connector. It must be a 3 Volt version like TSOP34536 Put a power led on the LED connector (with a 47 Ohm series resistor), or on the PWR connector (max. 2 Amp). Connect 6 leds or a led-module with P2.2 to P2.7.

Use the schematic and build a shield Connect 6 leds or a led-module with P2.2 to P2.7.Use the schematic and build a shield (see general intro.) when you have a Launchpad board. RC-TEST puts the received 6-bits key-code on leds. This is an example of two cooperating interrupt routines. Note that the only changes in the code, to make this routine low power, is the addition of the word LPM4 and the code on the lines marked with *** !



This low power version uses only 1/6 of the original version. This could be less, by using an even more low power version of the infrared receiver, or by using more clever tricks!



Forth commands: RC-LAMP ( -- ) Control output P2.1 RC-POWER ( -- ) Control output P2.4 RC-TEST ( -- ) Display RC-5 commands on leds puts the received 6-bits key-code on leds. This is an example of two cooperating interrupt routines. Note that the only changes in the code, to make this routine low power, is the addition of the wordand the code on the lines marked with *** !This low power version uses only 1/6 of the original version. This could be less, by using an even more low power version of the infrared receiver, or by using more clever tricks!Forth commands: ⇧

54

Low power noForth Without loss of functionality Materials: Egel Kit or Launchpad. noForth assembler e54 noForth program

Load the assembler before you load the e54 noForth program.

The code for this version shows all the functions needed to build a low power version of noForth. It uses an unused bit in the OK register to add a switch. This switch selects the depth of the used sleep mode. The word SLEEP must be implemented at the beginning of the forth word ACCEPT .



The word MS1 always uses LMP0 . Bit-3 in the OK register holds the sleep mode for this example.



A zero means minimal use of sleep modes, in this example it uses LPM0 , while waiting for a key. Most clocks keep on running in LPM0.



When bit-3 is set, this example uses deeper sleep modes. Like going into LPM4 in SLEEP and using LPM2 to further save power, while waiting for a key.



Connect an ampere meter to check the current used in different modes. Note that most used current meters are not accurate when measuring short current bursts. This can be rectified by adding a large capacitor.



8 ADR OK **BIS \ set bit 3 8 ADR OK **BIC \ clear bit 3 About the average current use.



Standard 8MHz noForth uses about 10mA, without leds that is ~2,6mA. The first number is the current while the system waits for a key, the second number is the average current while running. DCO freq. LPM4-sleep LPM2 LPM0 1 MHz 0.0007mA 0.020mA/0.18mA 0.070mA/0.18mA 8 MHz 0.0007mA 0.025mA/0.50mA 0.346mA/0.50mA 16 MHz 0.0007mA 0.033mA/0.83mA 0.682mA/0.83mA Forth commands: 1MHZ ( -- ) DCO on 1 MHz 16MHZ ( -- ) DCO on 16 MHz SLEEP-ON ( -- ) Install LPM version of noForth SLEEP-OFF ( -- ) Back to normal noForth version MS1 ( ms -- ) LPM version of MS SLEEP ( -- ) Go to LPM mode 4 The code for this version shows all the functions needed to build a low power version of noForth. It uses an unused bit in theregister to add a switch. This switch selects the depth of the used sleep mode. The wordmust be implemented at the beginning of the forth wordThe wordalways uses. Bit-3 in theregister holds the sleep mode for this example.A zero means minimal use of sleep modes, in this example it uses, while waiting for a key. Most clocks keep on running in LPM0.When bit-3 is set, this example uses deeper sleep modes. Like going intoinand usingto further save power, while waiting for a key.Connect an ampere meter to check the current used in different modes. Note that most used current meters are not accurate when measuring short current bursts. This can be rectified by adding a large capacitor.About the average current use.Standard 8MHz noForth uses about 10mA, without leds that is ~2,6mA. The first number is the current while the system waits for a key, the second number is the average current while running.Forth commands: ⇧

60

128x64 bits graphics display SSD1306 I2C display driver Materials: Egel kit or Launchpad, .96" OLED display. USCI I2C master e60a noForth program e60b noForth program e60c noForth program e60d noForth program e60e noForth program e60f noForth program Graphics & 8x14 characters Load the USCI I2C master before the e60 noForth programs. The software for SSD1306 driver is based on it.

Fat 8x14 characters



Connect VCC to VDD on the display, Ground to GND, P1.7 to SDA and P1.6 to SCL. The display works without external pullupps but in case it does'nt work add a 4K7 pullup to SDA and SCL! The software is divided in several cooperating modules shown below. Connect VCC to VDD on the display, Ground to GND, P1.7 to SDA and P1.6 to SCL. The display works without external pullupps but in case it does'nt work add a 4K7 pullup to SDA and SCL! The software is divided in several cooperating modules shown below.

Files needed for small characters example usci i2c master.f

e60a - ssd1306-setup.f

e60b - ssd1306-small-chars.f

Forth commands: SMALL ( -- ) Show small 5x8 characterset

Files needed for big fat characters example usci i2c master.f

e60a - ssd1306-setup.f

e60c - ssd1306-fat-chars.f

Forth commands: FAT ( -- ) Show big fat 8x14 character set

Thin 7x16 characters











Forth commands:Forth commands:

Files needed for big thin characters example usci i2c master.f

e60a - ssd1306-setup.f

e60d - ssd1306-thin-chars.f

Forth commands: THIN ( -- ) Show big thin 7x16 character set

Forth commands:

Files needed for graphic characters example usci i2c master.f

e60a - ssd1306-setup.f

e60c - ssd1306-fat-chars.f

e60e - ssd1306-graphic.f

e60f - ssd1306-hedgehog.f

Forth commands: GRAPHIC ( -- ) Show graphic and custom character set SHOW ( -- ) Animated view of the hedgehog Forth commands:

Your browser does not support MP4 video

Animated hedgehog demo ⇧

80

MSP430FR5xxx hardware multiply Hardware multiply versions of the basic noForth multiply routines Materials: MSP-EXP430FR5739 or MSP-EXP430FR5969. noForth assembler e80 noForth program Hardware multiply versions of the noForth basic multiply routines. Forth commands: * ( x y -- x*y ) M* ( x1 x2 -- dx3 ) UM* ( u1 u2 -- du3 ) DU*S ( du1 u2 -- du3 ) Hardware multiply versions of the noForth basic multiply routines. Forth commands: Load the assembler before the e80 noForth programs, the software RS232 routines are in assembler code. ⇧

90

MSP430F149 hardware multiply Hardware multiply versions of the basic noForth multiply routines Materials: MSP430F149 Mini-V3 boardor MSP430F149 Dupont board. noForth assembler e90 noForth program Forth commands: * ( x y -- x*y ) M* ( x1 x2 -- dx3 ) UM* ( u1 u2 -- du3 ) DU*S ( du1 u2 -- du3 ) Forth commands: Load the assembler before the e90 noForth programs, the software RS232 routines are in assembler code. ⇧

100

Wireless analog datalogger Gathering data from a distance Materials: 8 leds or Led module, 100 Ohm and 12K resistor, LDR, HC08 Bluetooth module, a 3V to 3,6V battery. e100 noForth program

Connect all materials used in the first four chapters to the shield, see schematics. Connect all materials used in the first four chapters to the shield, see schematics. The first 4 chapters taken as a whole describe in fact a wireless analog datalogger.



The sensor is sampled 10 times every second, but only every tenth value is stored. After 20 samples are gathered, they are sent back to the receiving device.



The forth command DATALOGGER starts automatically after a reset.

To quit the program press 'reset' while S2 is held down. The first 4 chapters taken as a whole describe in fact a wireless analog datalogger. HC08 datasheet . An LDR is used as an analog sensor.The sensor is sampled 10 times every second, but only every tenth value is stored. After 20 samples are gathered, they are sent back to the receiving device.The forth commandstarts automatically after a reset.To quit the program press 'reset' while S2 is held down. ⇧

101

Walking biped Simple walking robot Materials: e101 Biped BOM Info on a standard servo, and HC08 Bluetooth module. noForth assembler e101a noForth program e101b noForth program e101s servo tester program Biped building plan as PDF

The small walking robot has two legs, using four servos. It is wireless controlled thru The small walking robot has two legs, using four servos. It is wireless controlled thru bluetooth . The code comes from the first eight chapters. The result is a cute walking robot. Load the assembler before the e101 noForth programs.

The e101a version has very simple code, in just a few lines the robot really does something.



The e101a version has very simple code, in just a few lines the robot really does something.

Version e101b implements a more sophisticated version. This version has smoother motion control, more movements. Finally a key interpreter was added for easy remote control using bluetooth.



Version e101b implements a more sophisticated version. This version has smoother motion control, more movements. Finally a key interpreter was added for easy remote control using bluetooth.

The servos are connected to P1.4 to P1.7, the TX/RX of the HC08 are wired to P1.1 and P1.2, see also chapter E04! The servos are connected to P1.4 to P1.7, the TX/RX of the HC08 are wired to P1.1 and P1.2, see also chapter E04! Program e101s implements a servo tester. With this tester, it is easy to determine the pulse range of a servo. The main word is TESTER .

A potmeter on P1.7 changes the servo position. When S2 is pressed the current position of the servo is printed in microseconds. The pulse range is .6 ms to 2.7 ms. Program e101s implements a servo tester. With this tester, it is easy to determine the pulse range of a servo. The main word isA potmeter on P1.7 changes the servo position. When S2 is pressed the current position of the servo is printed in microseconds. The pulse range is .6 ms to 2.7 ms.

The Forth commands are: BIPED-ON ( -- ) - Activate Biped BIPED-OFF ( -- ) - Deactivate Biped WOBBLE ( u -- ) - Wobble u times WALK ( u -- ) - Walk forward u steps HELLO ( -- ) - Wave hello Basic Biped Forth commands, all stack neutral: REST RIGHT-UP LEFT-UP RIGHT-FORW LEFT-FORW DOWN WAVE TOES REST These words can be used to build more complex functions. The code is kept very simple, so there is plenty room for improvement! The Forth commands are:Basic Biped Forth commands, all stack neutral:These words can be used to build more complex functions. The code is kept very simple, so there is plenty room for improvement! Simple Biped walking and saying hello

The second program, e101b, has one main words named DEMO . This starts the remote control DEMO and boots automatically after a reset. The second program, e101b, has one main words named. This starts the remote controland boots automatically after a reset. ⇧

111

Cloning noForth Using built-in BSL to copy noForth Materials: Egel kit or Launchpad, 20 pin ziff socket, 32 kHz xtal. noForth assembler e111a noForth program e111b noForth program More info about the built-in BSL in SLAU319L.PDF

Read the pages 5 to 12, it contains the core of the BSL.



More info about the built-in BSL in SLAU319L.PDFRead the pages 5 to 12, it contains the core of the BSL. Place an 20-pin ziff-socket on the Egel kit as shown on the photo on top. Add a green and red led connect them using the schematic. Then connect the six wires for the programmer to the ziff socket. Finally connect a 32kHz crystal to pin 18 & 19 of the ziff socket. Information about the built-in capacitators see SLAU144J.PDF page 274 and beyond. The programmer now is ready to clone itself to an other MSP430G2553.



Load the assembler before the e111 noForth program, there are several routines in assembler code.



The APP -vector is filled with the DCO restoration program. The CLONE -program ends with a reset of the "clone". When the DCO constants where erased, they are restored immediatly by executing the APP -vector. Place an 20-pin ziff-socket on the Egel kit as shown on the photo on top. Add a green and red led connect them using the schematic. Then connect the six wires for the programmer to the ziff socket. Finally connect a 32kHz crystal to pin 18 & 19 of the ziff socket. Information about the built-in capacitators see SLAU144J.PDF page 274 and beyond. The programmer now is ready to clone itself to an other MSP430G2553.The-vector is filled with the DCO restoration program. The-program ends with a reset of the "clone". When the DCO constants where erased, they are restored immediatly by executing the-vector.

What does the BSL-programmer do:

Enter the BSL programmer on the target MPU Send password. When a password error occurs the target device is completely erased, including the DCO-constants! Erase info-B and main Flash memory Program info-B and main memory Give target a reset pulse The target MPU then starts the noForth clone. This will restore the DCO-constants. But only when they were erased using an incorrect password.

After restoring calibration values you may use the chip like a new one. With or without the xtal. What does the BSL-programmer do:

Forth commands: EMPTY-PASS ( -- ) Set password to all $FF MODIFY-PASS ( a -- ) Set password, 'a' is reset vector CLONE ( -- ) Copy yourself to another MSP430G2553 Forth commands: ⇧

*