82.1k views
5 votes
How to interface 20X4 sparkfun SerLCD with tiva C TM4C123 and c
code to control?

1 Answer

3 votes

Final answer:

To interface the 20X4 SparkFun SerLCD with the Tiva C TM4C123 microcontroller, you will need to connect the appropriate wires between the two devices. Once the physical connections are made, you can use C code to control the SerLCD module by configuring the I2C module on the TM4C123 and sending commands and data to the SerLCD using code.

Step-by-step explanation:

To interface the 20X4 SparkFun SerLCD with the Tiva C TM4C123 microcontroller, you will need to connect the appropriate wires between the two devices. The SerLCD module has a built-in I2C interface, so you'll need to connect the SDA and SCL pins between the SerLCD and the TM4C123. You'll also need to connect the power and ground pins.

Once the physical connections are made, you can use C code to control the SerLCD module. The Tiva C TM4C123 microcontroller has built-in I2C peripheral hardware that can be used to communicate with the SerLCD. You will need to configure the I2C module on the TM4C123 and write code to send commands and data to the SerLCD.

Here's a sample C code snippet that demonstrates how to initialize the I2C module on the TM4C123 and send a command to the SerLCD:

#include <stdint.h>

#include "inc/hw_memmap.h"

#include "driverlib/gpio.h"

#include "driverlib/i2c.h"

#include "driverlib/pin_map.h"

#include "driverlib/sysctl.h"

#include "driverlib/uart.h"

#include "utils/uartstdio.h"



void InitI2C(void)

{

SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);

SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOB);

GPIOPinConfigure(GPIO_PA6_I2C0SCL);

GPIOPinConfigure(GPIO_PA7_I2C0SDA);

GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);

GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);

I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);

I2CMasterEnable(I2C0_BASE);

}



void I2CSendCommand(uint8_t command)

{

I2CMasterSlaveAddrSet(I2C0_BASE, 0x72, false);

I2CMasterDataPut(I2C0_BASE, command);

I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);

while(I2CMasterBusy(I2C0_BASE));

}



int main(void)

SYSCTL_OSC_MAIN

User Balaji Katika
by
8.8k points