To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 739
738  |  740
Subject: 
Re: pbLua PCF8574 SOLVED
Newsgroups: 
lugnet.robotics.nxt, lugnet.robotics.nxt.nxthacking
Date: 
Mon, 21 May 2007 09:39:24 GMT
Viewed: 
36349 times
  
In lugnet.robotics.nxt, Christian Mock wrote:
> In lugnet.robotics.nxt, Ralph Hempel wrote:
> > Christian Mock wrote:
> > > Hi,
> > > has anybody successfully tried to read ports from I2C connected PCF8574 with
> > > pbLua (Beta-8) ?
> > > Writing and setting ports is no problem, but reading ports fails. The return
> > > value is every times 0 (not NIL)
> > 
> > No ideas yet, Christian. I do have a Mindsensors kit here to look
> > at over the weekend. Are you SURE you are sending the correct string
> > to read the registers?
> > 
> > Can you post the code you're using for the test here?
> > 
> > Cheers, Ralph
> 
> Hi Ralph,
> 
> we are using this code:
> 
> collectgarbage( "setpause", 110 );
> function setupI2C(port)
>   nxt.InputSetType(port,2)
>   nxt.InputSetDir(port,1,1)
>   nxt.InputSetState(port,1,1)
>   nxt.I2CTimer(3)
>   nxt.I2CInitPins(port)
> end
> 
> function ReadPCF(port)
>  nxt.I2CSendData( port, string.char(0x73),1, 1 )
>   while( 0 ~= nxt.I2CGetStatus(port)) do
>   end
>   s = nxt.I2CRecvData( port, 1 )
>   print( "Daten " .. s )
> end
> 
> setupI2C(4)
> ReadPCF(4);
> 
> Do you think, we have to read I2C address more often ? Like ultrasonic sensor ?
> The first read result of ultrasonic is allways 0.
> 
> Thanks for more :D
> Bye
> Christian
> 
> 
> ---

Hi,
we solved the problem... Lego-Firmware has own brain and handle read/write
with own mechanisms ;-( The last read/write bit is handled automatically by
lowlevel routines.
Reading the same address like writing solves the problem.


collectgarbage( "setpause", 110 );
function setupI2C(port)
  nxt.InputSetType(port,2)
  nxt.InputSetDir(port,1,1)
  nxt.InputSetState(port,1,1)
  nxt.I2CTimer(3)
  nxt.I2CInitPins(port)
end

function ReadPCF(port)
nxt.I2CSendData( port, string.char(118),1, 1 ) -- hier wird Geschrieben um zu
Lesen
while( 0 ~= nxt.I2CGetStatus(port)) do
end
  s = nxt.I2CRecvData( port, 1 )
  print( "Daten " . s )
  c1 = string.byte(s,1,1)
  print( string.format( "Result: %3i", c1 ) )
end

---

setupI2C(4);

ReadPCF(4);

Hmmm, why this ?

Bye
Christian



Message has 1 Reply:
  Re: pbLua PCF8574 SOLVED ?
 
(...) Hi, or was it a quirk at my brain to address the i2c-read-address and hope to receive usefull data ? Currently it works for me when using allways the i2c-write address... Are the any demos or samples for NXC, using the PCF8574 ? 1. setting (...) (19 years ago, 21-May-07, to lugnet.robotics.nxt, lugnet.robotics.nxt.nxthacking)

Message is in Reply To:
  Re: pbLua PCF8574
 
(...) Hi Ralph, we are using this code: collectgarbage( "setpause", 110 ); function setupI2C(port) nxt.InputSetType(port,2) nxt.InputSetDir(port,1,1) nxt.InputSetState(port,1,1) nxt.I2CTimer(3) nxt.I2CInitPins(port) end function ReadPCF(port) (...) (19 years ago, 19-May-07, to lugnet.robotics.nxt, lugnet.robotics.nxt.nxthacking)

8 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR