16 by 2 I2C Lcd Interfacing RA
by gauravnemade552 in Circuits > Microcontrollers
57 Views, 0 Favorites, 0 Comments
16 by 2 I2C Lcd Interfacing RA
Welcome — in this project you’ll learn how to drive a common 16×2 HD44780 character LCD from a Renesas RA6M4 microcontroller using a small I²C GPIO expander (the popular PCF8574-style backpack). Instead of wiring the LCD with many data pins, we use I²C to reduce wiring, simplify your prototype, and keep your MCU pins free for other peripherals. This guide walks you through a reliable, easy-to-follow implementation: initialization, sending text, positioning the cursor, and simple error handling so the display behaves consistently across power-cycles and resets.
This tutorial is written for makers and embedded developers who are comfortable with basic C programming and have a Renesas FSP project set up (or are willing to follow the short setup steps). By the end you’ll have a compact, reusable driver you can drop into other projects — perfect for user interfaces, status panels, or simple readouts. The instructions include wiring, full working code, and practical tips to avoid the common pitfalls beginners hit when moving HD44780 displays to I²C.
Supplies
Electronics
- Renesas RA6M4 development board (or any RA evk board just the pin configurations need to change).
- 16×2 HD44780 character LCD with I²C PCF8574-style backpack (commonly sold as a combined module).
- Jumper wires — female-to-female or female-to-male depending on your boards (4 wires: VCC, GND, SDA, SCL).
- Optional pull-up resistors — 4.7 kΩ × 2 (only if your board/module lacks I²C pull-ups).
- Power supply — 3.3 V or 5 V depending on your LCD/backpack (check backpack voltage tolerance).
Tools
- PC with Renesas e2studio (or your preferred toolchain) and FSP configured for the RA6M4.
- USB cable to connect the board for programming/power.
- Basic multimeter (for continuity/power checks).
- Small breadboard or prototyping wires (optional).
Optional but helpful
- Logic analyzer (Saleae or clone) for debugging I²C traffic — useful but not required for the tutorial.
- Small screwdriver for contrast potentiometer on the LCD.
Hardware Setup & Wiring
Prepare the physical parts and wire the LCD to your RA6M4 before you flash any code.
- Power & safety (do this first)
- Power off your board while wiring.
- Check your LCD/backpack voltage — many PCF8574 backpacks are 5 V tolerant but confirm. If your MCU is 3.3 V only, use a 3.3 V backpack or ensure level compatibility.
- Connect the four main signals
- VCC → 5 V (or 3.3 V if your backpack requires it).
- GND → MCU GND.
- SDA → RA6M4 SDA pin to P101.
- SCL → RA6M4 SCL pin TO P100.
- Use short jumper wires and solid connections.
- Pull-ups
- If your board or backpack does not already have I²C pull-ups, add two 4.7 kΩ resistors: SDA→VCC and SCL→VCC.
- Contrast/backlight
- Adjust the contrast potentiometer on the LCD while powering up to ensure characters are visible.
- If the backlight has a separate jumper or pin, set it appropriately.
- Quick checks before power-up
- Re-check VCC/GND polarity.
- Confirm SDA/SCL are not swapped.
- Make sure the backpack address jumpers (if present) are set to your chosen address (commonly 0x27 or 0x3F). for us the address is 0x27.
After wiring, power up the board and verify the LCD shows at least the contrast-adjusted blank row or a blinking cursor. If nothing appears, re-check wiring and pull-ups before moving to Step 2 (software setup).
Software Setup & Flash the Code
Now that the hardware is wired, it’s time to load the firmware into your RA6M4. You can directly import the ready-made project provided in the link below:
🔗 Project Download (ZIP):
https://drive.google.com/file/d/1c09ZZTZCDxrNMeyEg2weKCRuCrnsJ_1E/view?usp=sharing
Import the ready-made project into e2studio
This is the easiest and fastest way to get the LCD running.
1. Download and extract the ZIP
- Download the project from the link above.
- Extract the ZIP to a folder on your PC (e.g., Desktop or Documents).
2. Open e2studio
Launch Renesas e2studio.
3. Import the project
- Go to
- File → Import → Existing Projects into Workspace
- Click Browse…, select the extracted project folder.
- Ensure the project appears in the list.
- Click Finish.
4. Resolve toolchain/FSP version prompts
If e2studio asks:
- "Would you like to migrate to the latest FSP version?"
- → Click Yes or Migrate.
5. Clean and build
Go to:
Project → Build Project
Your project should compile without errors.
6. Configure the debugger
- Connect your debugger (J-Link / E2 Lite).
- Go to Run → Debug Configurations.
- Select Renesas GDB Hardware Debugging.
- Choose the proper project & MCU (RA6M4).
- Apply → Debug.
7. Flash the code
e2studio will:
- download the firmware
- reset the board
- start execution
After flashing, your LCD should initialize and display the text.
Understanding the Main Application Code (hal_entry)
Once the project builds successfully and the LCD driver files are added, it’s time to understand the heart of the application: the hal_entry() function. This is where the RA6M4 initializes the I²C peripheral, sets up the LCD, and continuously updates the display.
Code Overview
What This Code Does
- Open I²C Driver
- The line R_SCI_I2C_Open() initializes the SCI_I2C hardware using the configuration you set in FSP (pins, speed, callback, etc.).
- If anything fails, the CPU halts using __BKPT(0).
- Small Delay
- A 10 ms delay allows the I²C bus and LCD module to stabilize before communication starts.
- Initialize the LCD
- lcd_init() sends the sequence required to switch the LCD into 4-bit mode and prepare it for commands.
- Main Loop
- The program enters an infinite loop where:
- Cursor is positioned to column 3, row 0.
- The text "Getck@552" is printed.
- After 1 second, the second line displays "Renesas EK_RA6M4".
- This repeats continuously.
This step confirms that the LCD is working and that the RA6M4 is communicating reliably through I²C.
Migration Guide (Use This Code on Any RA Evaluation Kit)
The best part of this project is that the same LCD driver code works on any Renesas RA evaluation board. You only need to update a few settings in the Smart Configurator to match the board you are using.
Follow these simple steps to migrate the project:
1. Change the Board in Smart Configurator
- Open your project in e2studio.
- Go to Configuration.xml (FSP Configurator).
- At the top-right corner, change the Board to the RA EVK you are using in the BSP tab
- (Example: EK-RA2L1, EK-RA4M3, EK-RA6E2, etc.)
- Regenerate the project.
2. Set the Correct I²C (SCI) Channel
Every RA board has different SCI/I2C channels available.
To match your board:
- Open Stacks tab
- → Locate g_i2c0 (SCI_I2C Master)
- → In Properties, select the correct Channel (SCI0, SCI1, SCI2, etc.)
3. Configure the SDA/SCL Pins
- Go to Pins tab
- Find the SCI_I2C peripheral
- Enable the pins and assign:
- SDA Pin
- SCL Pin
Make sure the pins match your hardware wiring.
4. Generate the Code
- Click Generate Project
- Build the project and flash it onto your new RA board.
That's it!
The driver code does not change — only the FSP configuration (board, pins, and channel).
Troubleshooting
If your LCD is not responding, showing garbage characters, or the I²C bus is unstable, use these checks:
1. Check for Double Pull-Ups
Many Renesas RA evaluation boards already have on-board pull-up resistors on the I²C pins.
Your LCD backpack (PCF8574) also includes pull-ups.
This can lead to double pull-up condition → causing:
- Distorted signal shape
- I²C not acknowledging
- Random LCD behavior
Fix:
Use I²C pins on the RA board that do NOT have onboard pull-ups.
2. How to Verify Pull-Ups
To check whether your selected pins have built-in pull-ups:
- Download the RA board schematic from the Renesas website.
- Open the PDF and locate the pins.
- Look for resistors labeled Rxxx connected between the SDA/SCL line and VCC (3.3V).
- If present → these are pull-ups.
Choose pins that do not include these resistors.
3. Check Wiring Again
- Ensure SDA ↔ SDA, SCL ↔ SCL (not swapped)
- GND common between MCU and LCD
- VCC matches the backpack (3.3V or 5V)
4. Confirm I²C Address
Most PCF8574 modules use: this can be configured from the stack properties slave address
- 0x27 or
- 0x3F
If your LCD shows nothing, try changing the address in code.
5. Re-generate FSP Config
If you modified channels or pins:
- Open Smart Configurator → Generate Project
- Clean + build before flashing.
Conclusion
With just a few components and a simple I²C interface, you can easily connect a 16×2 LCD to any Renesas RA board and display characters, messages, or sensor values. The RA6M4’s flexible SCI_I2C peripheral makes communication reliable and fast, and the same code can be migrated to other RA boards by changing only the pins and channel settings in the Smart Configurator.
This project is a great starting point for building dashboards, debugging displays, menu systems, or data loggers using the RA family. Once you get the basic LCD functions working, you can expand it to show live sensor data, dynamic menus, or animations.
If you followed along, you should now have a fully working LCD connected to your RA6M4 — happy hacking, and feel free to enhance the project furthe. for any douts and error fell free to add comment or can email me gauravnemade552@gmail.com.