View unanswered posts | View active topics It is currently Sat Aug 23, 2014 4:17 pm






Reply to topic  [ 7 posts ] 
help understanding read and write code for PCF8574AP 
Author Message
Rookie

Joined: Tue Mar 11, 2008 7:12 pm
Posts: 5
Post help understanding read and write code for PCF8574AP
Hello

I am a new to this forum so plz bare with me. thanks

i am having trouble understanding the read or write message when using the mindsensors interface - PCF8574AP

here is some of the code

.
.
.
byte value[2];
int outputNumber;


SensorType[S1] = sensorI2CCustomFast;
while (1)
{
i2c_mess ledArray;
ledArray.i2cMessageSize = 2;
ledArray.i2cDeviceAddress = 0x70;
ledArray.i2cWriteMessage = 0xFE;


sendI2CMsg(S1,ledArray.i2cMessageSize,1); // set pins high for input
//readI2CReply(S1, value[0],1); //read pins
.
.
.

What i want to know is that when i change
sendI2CMsg(S1,ledArray.i2cMessageSize,1); to
sendI2CMsg(S1,ledArray.i2cMessageSize,0);

or the other way round what change would i expect etc by the way i have tried changing the value from 1 to 0 or 0 to 1 but the NXT and the interface do not respond to the change even if i switch the NXT off an ON again.

I dont understand what this "...,1); or ...0);" represent or what they mean or do etc I am tryin to read from the pins what is this 0 or 1 doing and what is it about?

I now the above may sound rather dumb but my programming skill are quite poor and i dont seem to understand this problem

can anyone help?

thanks

_________________
Ghat


Tue Mar 11, 2008 7:27 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Hi Ghat,

The 1 at the end of an I2C command is the number of bytes the sensor is expected to reply back to the NXT. If it is 0, the sensor assumes you sent a command that does not need a reply.

Let me know if this helps B-)
Scott

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Tue Mar 11, 2008 7:49 pm
Profile WWW
Rookie

Joined: Tue Mar 11, 2008 7:12 pm
Posts: 5
Post 
Hello Scott
thanks for the reply

ok so if i have

ledArray.i2cMessageSize = 2;

i should write

sendI2CMsg(S1,ledArray.i2cMessageSize,2);

is that correct??????

_________________
Ghat


Tue Mar 11, 2008 8:02 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Close, but not quite.

After the sensor receives a message, you can tell the sensor to send you back information, and how much. that is what the 1 or 0 means. The i2cMessageSize is how many bytes your sending to the sensor, not how much the sensor is sending back to you.

Different applications will use 1 or 0

A motor multiplexer that you tell to turn on and off would probably have a 0 at the end, you tell the multiplexer what to do and don't need any data back.

A compass sensor however would be different. You would send a command to the senor an say you want the compass current heading. You would use a 1 to specify you want 1 byte of data returned to you. The sensor would then return whatever value the sensor had in 1 byte.

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Tue Mar 11, 2008 8:22 pm
Profile WWW
Rookie

Joined: Tue Mar 11, 2008 7:12 pm
Posts: 5
Post 
ok i kinda understand

so what would i expect if i was using a thermistor voltage divider circuit with an ADC to recieve the digital output across the pins

_________________
Ghat


Wed Mar 12, 2008 5:31 pm
Profile
Rookie

Joined: Tue Mar 11, 2008 7:12 pm
Posts: 5
Post 
Also
my programming skills are rather poor could anyone explain what the two different codes below mean and what they do plzzzz



if (nI2CStatus[S1] == NO_ERR)

while (nI2CStatus[S1] == STAT_COMM_PENDING)

thanks

_________________
Ghat


Wed Mar 12, 2008 8:13 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post 
The PCF8574 is different from most of the available I2C sensors for the NXT. It has a single byte of data that you write; most of the sensors have multiple bytes.

When you write to a I2c device, the first byte is the address of the device on the I2C bus. By "convention" most of the NXT sensors are given address 2 (hex). There can be several devices on a I2C bus and each should be assigned a unique address.

By convention (but not specified in the I2C standard on devices with multiple internal locations the next byte is the internal address pointer. This byte is used to set the "index pointer" within the device. If you want to write to the device, then subsequent bytes are written to the current index pointer location which is then auto incremented for the next byte. If you were reading from the device then this is the first location that is being read and if you wre reading multiple bytes then the index pointer is auto-incremented after each byte.

The PCF8574 device has only one internal byte that is read/written so the "internal address pointer is not read. Writing "02 7F" (hex) for this assumes the I2C address is "02" and you're writing value "7F'. If you read back 1 byte it should hopefully give you value "7F'>

Hope above helps.


Sat Mar 15, 2008 11:21 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.