hi
i am using IO expander keypad with lx4f232 and transmitting port values through I2c i have gone through the datasheet of TCA6408A(IO expander ).i am facing some problem with reading data form the port.here is my code can you suggest me with your valuable solution .........
void keypadIntHandler()
{
GPIOPinIntClear(GPIO_PORTJ_BASE, GPIO_PIN_2);
//GPIOPinIntDisable(GPIO_PORTJ_BASE, GPIO_PIN_2);
sh=I2C_read_ON();
ROM_UARTCharPutNonBlocking(UART7_BASE,sh); // Write the next character to the UART.
UARTSend((unsigned char *)" shyam ", 7); // Prompt for text to be entere
delay(100);
//GPIOPinIntEnable(GPIO_PORTJ_BASE, GPIO_PIN_2); // Enable the pin interrupts.
}
//************************************* main() ********************************************************/
int main(void)
{
FPUEnable();
FPULazyStackingEnable();
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
/*******************************I2C INITIALISATION************************************/
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
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);
/***********************************END OF I2C INITIALISATION******************************/
I2CGPIOPinConfig(); // I2C configure
uart7_init();
/***************************Interrupt enable for GPIO PORTJ PIN**************************/
/*********************************GPIO PORT ENABLING**********************/
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_2);
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIOIntTypeSet(GPIO_PORTJ_BASE, GPIO_PIN_2,GPIO_FALLING_EDGE);
GPIOPinIntEnable(GPIO_PORTJ_BASE, GPIO_PIN_2);
ROM_IntEnable(INT_GPIOJ);
ROM_IntMasterEnable();
UARTSend((unsigned char *)" IO EXP KEYPAD ", 15); // Prompt for text to be entere
delay(1000);
while(1)
{
//I2C_Write();
}
}
void I2CGPIOPinConfig(void)
{
ROM_I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, false);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
Temp2 = ROM_I2CMasterErr(I2C0_MASTER_BASE);
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0x03);
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
ROM_I2CMasterDataPut(I2C0_MASTER_BASE, 0xF0);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
// W0ait for the first write/transaction to complete
while(ROM_I2CMasterBusy(I2C0_MASTER_BASE))
{
}
}
/*************************************WRITE FUNCTION*******************/
void
I2C_Write(void)
{
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, false);
Temp2 = I2CMasterErr(I2C0_MASTER_BASE);
I2CMasterDataPut(I2C0_MASTER_BASE, 0x01);
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_START);
Temp2 = I2CMasterErr(I2C0_MASTER_BASE);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
I2CMasterDataPut(I2C0_MASTER_BASE, 0x01);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
// Wait for the first write/transaction to complete
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
delay(10);
}
/************************* i2c read for ON **************************************/
unsigned long I2C_read_ON()
{
unsigned long value;
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, true); // write Start
/*I2CMasterDataPut(I2C0_MASTER_BASE, 0x01); // sub address
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS1, true); // Read Start*/
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
value=I2CMasterDataGet(I2C0_MASTER_BASE); //Receive data byte
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusy(I2C0_MASTER_BASE))
{
}
//ROM_UARTCharPutNonBlocking(UART7_BASE, value);
return value;
}
if i check by sending data from I2c write read function is occuring fine but when i am trying with interrupt its not working.................some where i am missing logic suggest me with some solution....
regards,
shyam.