PortInOut Problem

16 Feb 2011

Hi everyone, I am trying to use a simple BusInOut application with Bus width of 8-bits. When used BusInOut mode, I am able to write and read the data accurately. But for faster speed I used PortInOut, I am able to write the data properly but while reading I get unexpected result. My code is below.

/*
Connections:
D0-p26
D1-p25
D2-p24
D3-p23
D4-p22
D5-p21
D6-p19
D7-p20

*/

//code:

PortInOut LCD_PORT1(Port2,0x3F);
PortInOut LCD_PORT2(Port1,0xC0000000);

DigitalOut CS(p28);
DigitalOut RS(p27);
DigitalOut WR(p30);
DigitalOut RD(p29);

DigitalOut LOWBUF_DIR(p11);
DigitalOut LOWBUF_OE(p12);
DigitalOut LATCH_OE(p13);
DigitalOut LATCH_E(p14);


#define  LCD_CS_H()              CS=1
#define  LCD_CS_L()              CS=0
#define  LCD_RS_H()              RS=1
#define  LCD_RS_L()              RS=0
#define  LCD_WR_H()              WR=1
#define  LCD_WR_L()              WR=0
#define  LCD_RD_H()              RD=1
#define  LCD_RD_L()              RD=0

#define  LOWBUF_DIR_H()          LOWBUF_DIR=1
#define  LOWBUF_DIR_L()          LOWBUF_DIR=0
#define  LOWBUF_OE_H()           LOWBUF_OE=1
#define  LOWBUF_OE_L()           LOWBUF_OE=0
#define  LATCH_OE_H()            LATCH_OE=1
#define  LATCH_OE_L()            LATCH_OE=0
#define  LATCH_E_H()             LATCH_E=1
#define  LATCH_E_L()             LATCH_E=0




void LCD_WR_START(void) {
    LCD_PORT1.output();
    LCD_PORT2.output();
    LCD_CS_L();
    LCD_RD_H();
    LOWBUF_DIR_L();
    LOWBUF_OE_L();
    LATCH_OE_L();
}

void LCD_WR_DATA16(unsigned int data) {
    LCD_RS_H();
    LATCH_E_H();

    LCD_PORT1=(data>>8)&0x3F;
    LCD_PORT2=((data)&0xC000)<<16;

    LATCH_E_L();

    LCD_PORT1=(data)&0x3F;
    LCD_PORT2=(data<<24)&0xC0000000;
    LCD_WR_L();
    LCD_WR_H();

}
void LCD_WR_REG16(unsigned int index) {
    LCD_RS_L();
    LATCH_OE_L();
    LATCH_E_H();

    LCD_PORT1=0x00;
    LCD_PORT2=0x00;

    LATCH_E_L();

    LCD_PORT1=(index)&0x3F;
    LCD_PORT2=(index<<24)&0xC0000000;
    LCD_WR_L();
    LCD_WR_H();
}

unsigned int LCD_RD(unsigned int index) {

    unsigned short ret=0;
    LCD_WR_START();
    LCD_WR_REG16(index);


    LCD_PORT1.input();
    LCD_PORT2.input();
    //LCD_PORT1.mode(PullUp);
    //LCD_PORT2.mode(PullUp);
    LCD_RS_H();
    LCD_WR_H();
    LATCH_OE_H();
    LOWBUF_DIR_H();
    LOWBUF_OE_H();

    LCD_RD_L();
    LCD_RD_H();

    LCD_RD_L();
    ret=((LCD_PORT1.read()&0x3F) | ((LCD_PORT2.read()>>24)&0xC0))<<8;

    LOWBUF_OE_L();

    ret+=((LCD_PORT1.read()&0x3F) | ((LCD_PORT2.read()>>24)&0xC0));
    LCD_RD_H();
    return ret;
}

Actually I tried debugging, I encountered problem when I am trying to read "LCD_PORT2"(I get wrong data when read).

Please help me

Thanks and Regards Nitin

17 Feb 2011

Can someone help me please!!!!!

Nitin

18 Feb 2011

Hellllllllllloooooooooooooooooooo!!!!!!!!!!!!!!!!!!!! Please someone help!!!!!!!!

Nitin

18 Feb 2011

Hi Nitin,

Could you perhaps produce a simpler but complete version of your program that shows just the behaviour you are having problems with. I'm sure you'll get someone helping you track this down if you make it a little more edible!

The general problem with long but incomplete snippits is that it is quite a lot of effort for people to reproduce the problem, and that'll limit the amount of effort left over for finding a solution. Make it easy to reproduce the problem by providing a concise and complete program, and all the effort can then be on finding a solution!

I'm sure we can get this working for you...

Simon