Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Read Procedure for PCF8574A

Status
Not open for further replies.

Sherif8

Newbie level 5
Newbie level 5
Joined
May 3, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,361
Hello Everyone,

I'm on a project that uses PCF8574A for I/O Expansion.

The controller is LM3S6918, the interface is BitBanging I2C.

I've succeeded in the write part, stuck in the read part.

will paste the code used for the read..

Code:
int main(void)
{
 	IOX_Init(0);                              //Board Initializations
	StartCondition();
//	WriteByteToIOX(0x62);              //The writing commands which have been successful
//	halMcuWaitUs(30);
	WriteIntoPortB();                      //Got a free port on the controller, connected it with the outputs of the PCF8574A
	ReadByteFromIOX();                  //The problematic scheme
	StopCondition();

	while(1);
}

void IOX_Init(S_DB_Interface_t *interface)
{
        //Whatever
}

void StartCondition(void)
{
        //Whatever
}

void StopCondition(void)
{
        //Whatever
}

void WriteIntoPortB(void)
{
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_PIN_1);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_PIN_3);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, 0);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_4, 0);
	GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_6, 0);
}


void ReadByteFromIOX(void)
{
	static unsigned char NewByte;
	unsigned char x;
	char i;
	for(i = 0; i < 8; i++)
	{
		WriteBitToIOX(ReadSlaveAdd & 0x80);    //Send the read add, 0x79, the A2 is one, Both A1 and A0 are zeros
		ReadSlaveAdd <<= 1;
	}

	//Drive SCL LOW
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, 0);

	halMcuWaitUs(10);

	//Drive SDA HIGH
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3);

	halMcuWaitUs(30);

	//Drive SCL HIGH
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_PIN_6);
	halMcuWaitUs(30);

        //Change the direction of SDA pin into input
	GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_DIR_MODE_IN);

	for (i = 0; i < 8; i++)
	{
		x = ReadBitFromIOX();
		if(x)
		{
			NewByte <<= 1;
			NewByte |= 0x01;
		}
		else
			NewByte <<= 1;
	}

	//Drive SCL LOW
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, 0);

	halMcuWaitUs(10);

	//Drive SDA LOW
        //As a receiver, the master should pull the SDA LOW to inform the ack
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0);

	halMcuWaitUs(30);

	//Drive SCL HIGH
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_PIN_6);

	halMcuWaitUs(30);
}

unsigned char ReadBitFromIOX(void)
{
	unsigned char NewBit;
	
        //Drive SCL LOW        
        GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, 0);

        halMcuWaitUs(30);

	NewBit = GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_3) & 0x08;

         halMcuWaitUs(60);

        //Drive SCL HIGH
	GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_6, GPIO_PIN_6);

	return NewBit;
}


Please note that i use the same ack scheme in the write and read and it works for the write.
The NewByte char is always zeros

Thanks a lot,
Sherif
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top