View unanswered posts | View active topics It is currently Mon Sep 22, 2014 10:37 pm






Reply to topic  [ 3 posts ] 
PCF8574A coding reality check 
Author Message
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post PCF8574A coding reality check
I'm trying to help someone with the following bit of code.

It needs to set pin 0 to high, the low and set pins 1 to 7 to high for input.
Then read pins 0 through 7

Code:
typedef struct{
byte i2cMessageSize;
byte i2cDeviceAddress;
byte i2cWriteMessage;
} i2c_mess;



task main()
{
unsigned byte value[1];
int cnt=0; //****** just a counter, not needed

SensorType[S1] = sensorI2CCustomFast;

i2c_mess ledArray;
ledArray.i2cMessageSize = 1;
ledArray.i2cDeviceAddress = 0x70;
ledArray.i2cWriteMessage = 0xFF;

while(1)
{
  cnt++; //****** just a counter, not needed

  nI2CBytesReady[S1] = 0;

  ledArray.i2cWriteMessage = 0xFF;
  if (nI2CStatus[S1] == NO_ERR)
    sendI2CMsg(S1,ledArray.i2cMessageSize,1);

  wait1Msec(50);

  ledArray.i2cWriteMessage = 0xFE;
  if (nI2CStatus[S1] == NO_ERR)
    sendI2CMsg(S1,ledArray.i2cMessageSize,1);

  wait1Msec(50);

  while (nI2CStatus[S1] == STAT_COMM_PENDING)
    wait1Msec(2);

  if (nI2CStatus[S1] == NO_ERR)
    readI2CReply(S1, value[0], 1);


  nxtDisplayTextLine(2, "value %d", (int) value[0]);
  nxtDisplayTextLine(3, "cnt %d", cnt);
}
}



this is working perfectly for me, but not my friend.

Im seeing a nice 0 to 5v square wave on pin 0 and pins a through 7 are working as inputs.

Is there something Im missing?


Thu Mar 13, 2008 2:45 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
Are you both using identical hardware? Is it homebrew or a commercial "sensor".

If custom design then ensure you have the proper termination on the device as recommended in the LEGO SDK.

Are you using LEGO cables or homebrew. If homebrew, how long are they (i.e. a foot or so vs many feet long)?

Try using "slow" instead of "fast" communication. "sensorI2CCustom" vs "sensorI2CCustomFast". This helps compensate for bad termination or long cables.


Sat Mar 15, 2008 11:00 pm
Profile
Rookie

Joined: Fri Apr 20, 2007 3:22 am
Posts: 36
Post 
we're both using the mindsorms board.

I think what's happening is that he has voltage coming back to the PCF8574A from another source and it's causing bad signals to be sent.

He's basically trying to couple a parellel adc to the PCF8574A by directly connecting the io pins form to the other using pin 0 to request a read from the adc then 6 of the pin on the PCF8574A to recive the information.

Pin 0 is probaly ok, but the other pins should probably be isolated from the ADC with transiters or something. I've asked him to disconnect the PCF8574A from the circuit to make sure that it's working properly, but he's only disconnected pin 0. So there's probably voltage coming from the adc back to the PCF8574A.


Sun Mar 16, 2008 1:20 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.