Hello,
am interfacing keypad to lm4f232 with i/o expander and am new to this interfacing. have tried with the below code but its not working can any one help out
//*****************************************************************************/
// Project : Split Revolving Display
// Board Name : SRDC
// Description : This Test Routine is used to test the Inputs and Outputs of SRDC board & Daughter Board.
// Inputs IP0 to IP15 is mapped to Output pins of PCF8575.
//
//
//*****************************************************************************/
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_i2c.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/rom.h"
#include "grlib/grlib.h"
#include "inc/hw_ints.h"
#include "driverlib/i2c.h"
#include "driverlib/pin_map.h"
#include "driverlib/UART.h"
//
// Set the address for slave module. This is a 7-bit address sent in the
// following format:
// [0:1:0:0:0:0:0:RS]
//
// A zero in the "RS" position of the first byte means that the master
// transmits (sends) data to the selected slave, and a one in this position
// means that the master receives data from the slave.
//
//*****************************************************************************
#define SLAVE_ADDRESS2 0x19
#define SLAVE_ADDRESS1 0x20
void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount);
unsigned long Hour = 0x00, Min = 0x00, Sec = 0x00, temp1,Temp2;
unsigned short iVal, Temp;
unsigned char Time[6], Byte1,Byte2;
unsigned int Temp3=0,Temp4;
void
column1(int);
void
column2(int);
void
column3(int);
void
column4(int);
void
KeypadIntHandler(void)
{
UARTSend((unsigned char *)"key pressed is 3", 18);
GPIOPinIntClear(GPIO_PORTJ_BASE, GPIO_PIN_2);
GPIOPinIntDisable(GPIO_PORTJ_BASE, GPIO_PIN_2);
/************** clearing o/p pins **********************/
ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, false);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0x01);
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0x00);
// I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
// Wait for the first write/transaction to complete
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
/*********************reading input pins************************/
ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, false);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
Temp3=ROM_I2CMasterDataGet(I2C0_MASTER_BASE);
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
Temp4=Temp3;
/***********************scanning columns******************************/
if((Temp3 & 0x00001000) == 0)
{
column4(Temp4);
}
else if ((Temp3 & 0x00000100) == 0)
{
column3(Temp4);
}
else if ((Temp3 & 0x00000010) == 0)
{
column2(Temp4);
}
else
{
column1(Temp4);
}
}
void column1(int Temp5)
{
if((Temp5 & 0x00010000) == 0)
{
UARTSend((unsigned char *)"key pressed is one", 18);
}
else if ((Temp5 & 0x00100000) == 0)
{
UARTSend((unsigned char *)"key pressed is 5", 18);
}
else if ((Temp5 & 0x01000000) == 0)
{
UARTSend((unsigned char *)"key pressed is 9", 18);
}
else
{
UARTSend((unsigned char *)"key pressed is c", 18);
}
}
void column2(int Temp5)
{
if((Temp5 & 0x00010000) == 0)
{
UARTSend((unsigned char *)"key pressed is 2", 18);
}
else if ((Temp5 & 0x00100000) == 0)
{
UARTSend((unsigned char *)"key pressed is 6", 18);
}
else if ((Temp5 & 0x01000000) == 0)
{
UARTSend((unsigned char *)"key pressed is 10", 18);
}
else
{
UARTSend((unsigned char *)"key pressed is D", 18);
}
}
void column3(int Temp5)
{
if((Temp5 & 0x00010000) == 0)
{
UARTSend((unsigned char *)"key pressed is 3", 18);
}
else if ((Temp5 & 0x00100000) == 0)
{
UARTSend((unsigned char *)"key pressed is 7", 18);
}
else if ((Temp5 & 0x01000000) == 0)
{
UARTSend((unsigned char *)"key pressed is A", 18);
}
else
{
UARTSend((unsigned char *)"key pressed is E", 18);
}
}
void column4(int Temp5)
{
if((Temp5 & 0x00010000) == 0)
{
UARTSend((unsigned char *)"key pressed is 4", 18);
}
else if ((Temp5 & 0x00100000) == 0)
{
UARTSend((unsigned char *)"key pressed is 8", 18);
}
else if ((Temp5 & 0x01000000) == 0)
{
UARTSend((unsigned char *)"key pressed is B", 18);
}
else
{
UARTSend((unsigned char *)"key pressed is F", 18);
}
}
void
UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
//
// Loop while there are more characters to send.
//
while(ulCount--)
{
//
// Write the next character to the UART.
ROM_UARTCharPutNonBlocking(UART7_BASE, *pucBuffer++);
}
}
int
main(void)
{
unsigned long i,j;
//
// Set the clocking to run directly from the external crystal/oscillator.
// TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
// crystal on your board.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
/*******************************sumanth************************************/
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
ROM_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_2);
ROM_I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);
/***********************************sumanth******************************/
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
ROM_GPIOPinConfigure(GPIO_PE1_U7TX);
ROM_GPIOPinConfigure(GPIO_PE0_U7RX);
ROM_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_UARTConfigSetExpClk(UART7_BASE, ROM_SysCtlClockGet(), 115200,UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE);
ROM_IntEnable(INT_UART7);
ROM_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT | UART_INT_TX);
/*Interrupt enable for GPIO PORTJ PIN*/
ROM_IntMasterEnable();
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_2);
GPIOIntTypeSet(GPIO_PORTJ_BASE, GPIO_PIN_2,GPIO_FALLING_EDGE);
GPIOPinIntEnable(GPIO_PORTJ_BASE, GPIO_PIN_2);
/* Configure the Port pins as OUTPUT by writing 0x00 to Configuration register */
ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, false);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0x03);
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0x0F);
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, false);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0x01);
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0xF0);
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
while(1)
{
//UARTSend((unsigned char *)"key pressed is 3", 18);
}
}