View unanswered posts | View active topics It is currently Mon Dec 22, 2014 1:51 am






Reply to topic  [ 3 posts ] 
Problem with the PCF8574 
Author Message
Rookie

Joined: Sat Apr 18, 2009 10:54 am
Posts: 1
Post Problem with the PCF8574
I have used the PCF8574 driver that was provided here: viewtopic.php?f=41&t=916

Writing to the PCF8574 is no problem at all. But if I read a button the application crashes most of the time.

what I do is quite simple and straight forward:
- connecting 4 LED's to P0 - P3
- connecting a button between Pin 9 (P4) and ground

Code:
PCF8574Initialise(PCF8574_PORT);

while (true) {
  if (PCF8574PinRead(S1, 5) == 5) {
    PCF8574PinOn(S1, 1);
  } else {
    PCF8574PinOff(S1, 1);
  }
}


That should do the job, one would think. But it crashes quite often. Adding a Wait1Msec(1500); or so doesn't help either.

It seems that if I modify the code to this is seems to work better:
I have used the PCF8574 driver that was provided here: viewtopic.php?f=41&t=916
Writing to the PCF8574 is no problem at all. But if I read a button the application crashes most of the time.

what I do is quite simple and straight forward:
- connecting 4 LED's to P0 - P3
- connecting a button between Pin 9 (P4) and ground

Code:
PCF8574Initialise(PCF8574_PORT);

while (true) {
  if (PCF8574PinRead(S1, 5) == 5) {
    wait1Msec(1500);
    PCF8574PinOn(S1, 1);
    wait1Msec(1500);
    PCF8574PinOff(S1, 1);
    wait1Msec(1500);
  }
}


It seems to be that the latter code works better, but still crashes if I keep the button pushed. What is the cause of this behaviour?!


Sat Apr 18, 2009 11:05 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: Problem with the PCF8574
Hi JopieK,

Sorry its been a long time since I have logged in, I will take a look at the code and see what I can do. I'm surprised it is crashing when reading the button. Ill see what I can do B-)

Scott B-)

_________________
Mmmm Legos B-)

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


Thu Jul 02, 2009 4:55 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: Problem with the PCF8574
Quick Question, when the application crashes, does the NXT freeze or does it print an error to the screen?

If it prints an error to the screen I know whats going on. I wrote a error function that checks the hardware pins to make sure the hardware pins are the same as the message sent. However I didn't think if one of the pins is hooked to a switch, it could be a 1 or 0, which would make the hardware check fail lol. I suggest deleting the function code in PCF8574Error, and leaving it an empty function. This should fix your problem B-)

Also, I took a look at my driver and remembered that PCF8574PinRead returns a 1 if the pin is high, and a 0 if the pin is low. You are comparing this to 5, It still works because 5 != 0 making it true, but just fyi.

Sorry for all the problems, and good luck with your project B-)
Scott

_________________
Mmmm Legos B-)

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


Fri Jul 03, 2009 4:02 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.