This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

hi

Other Parts Discussed in Thread: TCA6408A

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. 

  • Hi shyam,

    Have you added void keypadIntHandler() to the I2C0 location in your vector table?  You need to replace the IntDefaultHandler call, if you haven't already.

  • Hi ,

    i added it already now interrupt is occuring but it is not reading the data from port i'm getting 0x00 for all the port.if it is not reading the data then there is a problem in reading function.but i didnt done any thing in read function just getting it .can you tell me where will the exact problem if it is not reading properly......i'm new to this controller and wanted to know what are all the problems may occur using I2C and IO expander(keypad)....

    regards,

    shyam.

  • shyam reddy said:
    can you suggest me with your valuable solution .........

    Might you mean, "Suggest a valuable solution - again?"

    /*******************************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******************************/

    Past - on the earlier existing forum - we suggested that your single GPIOPinTypeI2C() function was insufficient.  And then "hinted" that GPIOPinTypeI2CSCL() was the type required for these M4 devices.

    And that suggestion - known by many to be good - reveals yet again to have "escaped" your code.

    Confounding your attempt still further - you have now directed PB2 as, "GPIOPinTypePWM()!  At some point you must decide which use is appropriate. 

    And - "valuable solution" continues to discourage the added complexity of I2C - to scan, debounce & decode your keypad.  Use of far more normal/customary Keypad solution via GPIO - sure to build your knowledge/understanding - so that once I2C is mastered - you have "some" chance of meeting keypad challenge.

    Adding complexity has not proved especially fruitful...  Your near duplicate posts land/scatter across this plain - valuable solutions not withstanding...

  • hi,

     my i2c is working fine i used GPIOPinTypePWM() because of some open drain problem.the problem i am facing here is when  reading the data from port(io expander).Its not reading any thing .........

  • Hi,

    GPIOPinTypePWM will not solve the problem with open drain - better describe this problem than making some other configurations without knowing the further implications. Other problems with your device: seems the slave address is 0x21 for read operations and 0x20 for write operations (and I cannot find these in your code). Also, you do not configure the pins of your device: use CONFIG register and set 1 for pins to be inputs and 0 for pins to be outputs - default value is not specified if I remember well. Check carefully the data sheet - rushing to coding phase do not solve anything, by contrary, is unproductive.

    Petrei 

  • @Petrei,

    In this rare (and particular case) the "unseemly" use of that PWM call does work!  This was past discovered and posted here.  (not by you nor I - I checked the PWM.c source file - confirmed that pin set-up/config was identical to I2CSCL call...) 

    That said - the use is counter-intuitive - and missed by I2C "mavens" (both you/I).  And surely will come back and "bite" later - when another (or poster) reviews the code...  Our far more "normal/customary" I2CSCL usage suggestion - although deemed "valuable" - finds poster's trash can...

    I2C traffic sure to be constant as our friend attempts to regularly/repeatedly scan, debounce and finally decode his keypad.  And - as I2C often has data-line errata (i.e. glitch filter) any hiccup in I2C will render keypad "silent." 

  • @cb1-mobile,

    Thanks for this info - never thought to be such relation between I2C and PWM - but surprises may appear from time to time. I will read/check myself this.

    Petrei

  • Petrei said:
    never thought to be such relation between I2C and PWM

    Indeed - however the impact is solely upon the "pintype - input set-up/config" - and by "accident/fortune" - the functions overlap.  Still though - discovering poster should be applauded for his/her diligence - and sharing w/ the group...

    Still - wildly confusing/unexpected - and bit "krazed" in light of proper function's availability.  i.e. GPIOPinTypeI2CSCL()

    That said - this "unwitting" PWM function "did make it into ROM" - while proper I2CSCL did not - thus condemns entire I2C code block to Flash residency... (should one use the proper GPIOPinTypeI2CSCL()...)

    Poster may be wise to locate his radio far from I2C clock line - as incessant activity demanded by I2C's keypad: scan, debounce & decode - likely will prove neat radiator...  (yet very marginal keypad, "resolver.")

    Update: Dawns - that addition of one GPIO input - fed by "And" gate connected to ea. keypad "input" - may reduce constant/chronic keypad scan.  (all keypad "outputs" initially driven low via I2C - then upon keypress - And gate announces - and the interrupted MCU starts the scan, debounce, decode activity...)  Eyes cross, attention deficits - just thinking about time/effort required - and for what?