ARM M4 – TM4C123G-ENERGIA

Photo of author

By Jackson Taylor

Home » Examples » Open Cv » ARM M4 – TM4C123G-ENERGIA

As an Amazon Associate we earn from qualifying purchases.

The TM4C123G is a Texas Instruments microcontroller built around the ARM Cortex-M4F core. It is sold on the Tiva C Series LaunchPad, a low-cost development board that works well for learning embedded programming. Energia, an Arduino-style programming environment, lets you write sketches for it with simple functions such as pinMode, digitalWrite and analogRead.

This page is an index of ARM M4 examples written for the TM4C123G LaunchPad and Energia. The projects go from a basic LED to interrupts, PWM, sensors and an LCD. If you want background on the chip first, read our overview of the ARM M4 Tiva C Series TM4C123G.

Why use the TM4C123G with Energia?

A typical 8-bit board is fine for blinking an LED. Many real projects need more speed, more memory or hardware floating point, and the Cortex-M4F core provides them. The LaunchPad’s TM4C123GH6PM chip runs at up to 80 MHz and has 256 KB of flash and 32 KB of SRAM. It also has many hardware peripherals, including several UARTs, PWM outputs, ADC channels and timers.

Hardware Hack

Stop Buying New Batteries for Your Tech

Electronics are expensive, but their power sources don't have to be. Discover the simple engineering trick to recondition dead batteries and bring your gadgets back to 100% capacity.

Watch the Free Video

Energia hides most of the low-level register work. That makes it a good first step before you move to vendor libraries or bare-metal C. You can learn the basic ideas (digital I/O, serial, timing, analog) and then dig deeper when you need to.

What you need to get started

One point to remember: the TM4C123G pins work at 3.3 V logic. Do not connect 5 V signals directly to its inputs unless the pin is documented as 5 V tolerant. Use a level shifter or a voltage divider when in doubt.

See also
CUK CONVERTER

ARM M4 TM4C123G Energia examples

Work through the examples roughly in this order. Each one adds a single new idea to the previous one.

1. Digital output and LEDs

Start with digital output. You set a pin as an output, then switch it high and low. The LaunchPad has an RGB LED on board, so you can test your first sketch without wiring anything. Our digital output tutorial explains the steps, and the fun with LED walkthrough covers flashing patterns and external LEDs.

2. Push buttons and digital input

The board has two user push buttons. Reading a button teaches you about input pins, pull-up resistors and why a button press needs debouncing. Our ARM M4 digital input guide covers these points in more detail. The push button and LED example combines input and output in one small sketch.

3. Serial communication

Serial lets the board talk to your computer, which is the quickest way to debug a sketch. The multiple serial events example shows how to handle more than one serial port, a feature the TM4C123G has because it includes several hardware UARTs. The ARM-based SCADA example builds on this idea to monitor and control hardware from a PC.

4. Interrupts

Polling a pin in a loop wastes time and can miss short events. An interrupt runs a small function as soon as something happens, such as a button press. Keep interrupt routines short, and set a flag that the main loop checks later.

5. PWM with an LED

Pulse width modulation switches a pin on and off quickly and changes the share of time it stays on. With an LED this gives you smooth dimming. The same technique drives motors and servos, and it is the base for many robotics projects.

See also
CHIP ENABLE ERROR IN AT89S52 FOR USBASP

6. ADC with the LM35 sensor

The LM35 outputs about 10 mV per degree Celsius. Read it with an analog input and convert the reading to voltage, then to temperature. Because the ADC reference on this board is 3.3 V, check the scaling in your code rather than copying a formula written for a 5 V board. Averaging several readings reduces noise.

7. Ultrasonic distance sensor

An ultrasonic module sends a sound pulse and measures how long the echo takes to return. Sound travels at roughly 340 m/s in air, so the distance is half of the travel time multiplied by that speed. The ultrasonic sensor example works through the calculation.

Sustainable Tech

Keep Toxic E-Waste Out of Landfills

Don't throw away your failing laptop, phone, or car batteries. Learn how to recondition them at home in just a few hours. It's better for the planet—and your wallet.

Learn How It Works

8. Interfacing an LCD

A character LCD gives your project its own display, so you no longer need a computer to see values. Check the LCD’s supply voltage and logic levels first, because many modules are designed for 5 V.

Tips for fewer problems

  • Select the right board and port in Energia before you upload.
  • If uploads fail, try another USB cable. Some cables only carry power.
  • Use current-limiting resistors with every external LED.
  • Change one thing at a time and test after each change.
  • Keep a note of which pin each part is connected to, since LaunchPad pin names differ from Arduino numbering.

Where to go next

Once these basics feel comfortable, a structured course helps. Our low cost embedded system workshop article describes a hands-on workshop based on an ARM M4 board from Texas Instruments. After that, you can try larger projects that combine several of the examples above, such as a sensor logger with an LCD or a PC-controlled system.

FAQ

Is the TM4C123G the same as the Tiva C LaunchPad?

The TM4C123G is the microcontroller family, and the Tiva C Series LaunchPad is the development board that carries a TM4C123G chip. In these tutorials the two names refer to the same hardware.

See also
Composite Energy Storage System with Photovoltaic Power Generation and UPS Function

Can I program the TM4C123G with Energia instead of Code Composer Studio?

Yes. Energia supports the LaunchPad and is easier for beginners. Code Composer Studio or other ARM toolchains give you full control of the chip once you need more than Energia exposes.

Do Arduino sketches run on this board?

Many simple sketches run with little or no change, since Energia follows the Arduino programming style. Libraries and pin numbers often differ, so check them first.

Is the TM4C123G 5 V tolerant?

Do not assume so. The board uses 3.3 V logic, and only some pins tolerate 5 V. Check the datasheet or use a level shifter.

Revive Your Dead Electronics

Got a drawer full of dead gadgets or a failing car battery? Instead of paying a premium for replacements, use this simple trick to easily recondition them right from home.

See How It Works