Hello everyone! 

Our new lesson will be much more difficult than the previous ones. We will learn how to work with two types of LCD displays: the HD44780 parallel interface and the I2C serial interface, the real-time clock (RTC), and the CC1101 radio interface integrated into the CC430F5137 on which the TiTAN and TiTAN-I boards are based. 

As a result we will get this stand 

At the bottom of the stand, we can see the TiTAN-I Board with an I2C LCD display and an antenna. The firmware starts the real-time clock, sets the “alarm” mode to 23: 59: 00, displays the date and time on the display, and transmits this information over the radio. 

In the upper part of the stand, the TiTAN Board receives the time information from the TITAN-I via radio, displays the received information on the LCD display connected via a parallel interface, and, if the alarm mode is triggered, turns on the buzzer. 

Let’s do it one step at a time. In this lesson, we will build the bottom part of the stand. 

Visually, it looks simple. But this is not quite the case. Shall we start? 

Let’s start by learning how to run a real-time clock. Here is a small feature that is described in the list of errors from Texas Instruments under the number 5438. The essence of this error is that when writing to the RTC registers, the internal cycles of the microcontroller are disrupted. This problem is resolved by using a special library written in the Assembler. Unfortunately, these libraries are adapted to other processors, so we will do it differently. Our goal is to understand how it works. 

So, we will write the necessary values twice in the RTC registers and maintain a small pause between entries in the registers. 

Let’s look at what’s going on here. 

Everything is simple here: 

  • prohibit interrupts; 
  • stop the RTC; 
  • enable the following modes: calendar, alarm, and event interrupts; 
  • set the year, day, month, hour, minutes and seconds in turn; 
  • set the alarm for 59 minutes; 
  • launch the RTC. 

That’s it, from now on, our RTC is running. 

How do we get the current time now? Again, let’s use the interrupts. Creating an interrupt handler for the RTC events.  

Every second and every minute we will take data from the registers of the date and time, every minute we will reset the “alarm” state, and for the “alarm” event we will set the alarm sign. 

This concludes our work with the real-time clock. 

It is not that complicated, is it? So let’s move on. 

Now we need to launch the I2C interface. We will connect the TIC107 LCD display with the PCF2119x controller to it. 

To do this, we need to create several functions. In the future, you will use HAL libraries. But now our task is to learn how to control the microcontroller. For this reason, we will create these functions ourselves and they will not use the interrupts. Here they are. 

The function of initialization of the I2C interface. Port P1.2 will act as SCL, and port P1.3 will act as SDA.  

Functions for transmitting data, generating a start and stop signal for the I2C interface. 

On the I2C interface, it has the address of 0x74. 

Declare it in the definitions. 

We also need functions for displaying data on the LCD display. 

This is what the cursor movement function looks like. 

And so the text output function. 

Please note how data transmission over the I2C interface looks like. 

First, a start signal is transmitted with the address of the data receiver, then a command is passed, then data, and at the end a stop signal is formed. 

Be patient, there’s not much left. We need to add the necessary variables. 

And write the initialization of the LCD display in the main() function and output the time and date to it. 

All these “magic” commands are described in the PCF2119x documentation. 

What do we have left that hasn’t been described yet? Of course! It remains to present the information on the LCD display and transmit it over the radio. We’ll do it this way. First, we will wait for the RTC event. 

And we will display it like this. 

An important note is needed here. By default, the printf function is enabled with minimal support in Code composer Studio projects. And the “%02” or “%4 ” modifiers will not work. You need to change the linker parameters as shown in the image. 

All that remains is to transmit the data over the radio. Shall we continue? 

We will need an example from the web-site https://titan-project.com in the “software” section. 

This example has the necessary RF1A library to work with the transceiver. Let’s add it to our project. In the same library, you will find an array of rfSettings with radio settings that were obtained using the SmartRF Studio by Texas Instruments. 

By the way, we use the functions necessary for the operation of the LCD display in the example  

Let’s determine the size of the transmitted data. 

And organize data transmit. We’ll do it like this. 

We fill the TXBuff array with the transmitted data and send it. For normal radio operation, add an empty interrupt handler for radio events. 

Let’s sum up. We have created functions and interrupt handlers for working with the real-time clock, the I2C interface, the LCD display, and the transceiver. 

The main() function will look like this. 

It remains to build our project and run it on the TiTAN-I Board. 

Congratulations! 

You have mastered 5 very important functions. The Real-time clock, the I2C interface, the LCD display on the PCF2119x controller, the CC1101 transceiver integrated in the  CC430F5137 microcontroller, the advanced printf function. 

In the next lesson, we will create a receiving part of our stand and analyze some hidden moments. 

Video Tutorial