Pages: 1 2 [3] 4   Go Down
Author Topic: Library for RAM chip  (Read 4088 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is what i have, what should i change?
Code:
int AM9111::read(unsigned int address)
{
  int rv = 0;
  _read() = rv;
  _setAddress(address);
  return rv;
}
Code:
int AM9111::_read()
{
  int rv = 0;
  digitalWrite(_odp,0);
  digitalWrite(_wep,1);
  bitWrite(rv,0,digitalRead(_IO[0]));
  bitWrite(rv,1,digitalRead(_IO[1]));
  bitWrite(rv,2,digitalRead(_IO[2]));
  bitWrite(rv,3,digitalRead(_IO[3]));
  _read() = rv;
}

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
_read() = rv;
I thought we'd already decided that this was a no-no?

Code:
int AM9111::read(unsigned int address)
{
  int rv = 0;
  _read() = rv;
  _setAddress(address);
  return rv;
}
Is that really the correct order of events?
« Last Edit: April 22, 2011, 05:26:02 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
int AM9111::_read()
{
  digitalWrite(_odp,0);
  digitalWrite(_wep,1);
  int rv = 0;
  bitWrite(_rbits,0,digitalRead(_IO[0]));
  bitWrite(_rbits,1,digitalRead(_IO[1]));
  bitWrite(_rbits,2,digitalRead(_IO[2]));
  bitWrite(_rbits,3,digitalRead(_IO[3]));
  _read() = _rbits;
  return rv;
}


Someone's been doing too much Visual Basic. smiley-wink

Instead of:

Code:
 _read() = _rbits;
  return rv;

You want:

Code:
 return _rbits;

Although I'm not sure what rv does. Did you put it there to make compiler errors go away?
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
int AM9111::_read()
{
  digitalWrite(_odp,0);
  digitalWrite(_wep,1);
  int rv = 0;
  bitWrite(_rbits,0,digitalRead(_IO[0]));
  bitWrite(_rbits,1,digitalRead(_IO[1]));
  bitWrite(_rbits,2,digitalRead(_IO[2]));
  bitWrite(_rbits,3,digitalRead(_IO[3]));
  _read() = _rbits;
  return rv;
}


I still don't totally get this. Are you trying to change _rbits? In which case why return anything from the function? In that case you want:

Code:
void AM9111::_read()
{
  digitalWrite(_odp,0);
  digitalWrite(_wep,1);
  _rbits = 0;
  bitWrite(_rbits,0,digitalRead(_IO[0]));
  bitWrite(_rbits,1,digitalRead(_IO[1]));
  bitWrite(_rbits,2,digitalRead(_IO[2]));
  bitWrite(_rbits,3,digitalRead(_IO[3]));
}

But if you want to return stuff, and not affect things such as _rbits (have side-effects) then you actually want:

Code:
int AM9111::_read()
{
  digitalWrite(_odp,0);
  digitalWrite(_wep,1);
  int rv = 0;
  bitWrite(rv,0,digitalRead(_IO[0]));
  bitWrite(rv,1,digitalRead(_IO[1]));
  bitWrite(rv,2,digitalRead(_IO[2]));
  bitWrite(rv,3,digitalRead(_IO[3]));
  return rv;
}
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, ill try it
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes! It finally compiled! I will upload it tomorrow morning and try it.

Thanks for all your help smiley

And what do you mean by "Someone's been doing too much Visual Basic"?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, have you done Visual Basic?

In VB, a function returns its results by assigning to the function name. For example:

Code:
function foo (a, b)
  foo = a + b   ' return result of adding a to b
end function

So when I saw you write:

Code:
_read() = _rbits;

I thought you might have thought this was how you returned the function value.
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well i have done a little visual basic, but not much, i did more visual c++.

and i have made an arduino sketch thad did, for example:
Code:
boolean yn(int pin)
{
  yn = digitalRead(pin);
}
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18720
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not one that compiled, right?

Code:
sketch_apr23c.cpp: In function 'boolean yn(int)':
sketch_apr23c:2: error: assignment of function 'boolean yn(int)'
sketch_apr23c:2: error: cannot convert 'int' to 'boolean ()(int)' in assignment
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hmm, well i know it was something like that, mabey i used if statements or something, i don't know. it was a while ago. Well ill test the lib tomorrow...
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now the _read() always returns 0

here is the code:
Code:

#include "AM9111.h"
#include "WProgram.h"

/////////////////////////////////////////
//
// PUBLIC
//
AM9111::AM9111(uint8_t outputDisablePin, uint8_t writeEnablePin)
{
  _odp = outputDisablePin;
  _wep = writeEnablePin;
}

int AM9111::setIO(uint8_t IO0, uint8_t IO1, uint8_t IO2, uint8_t IO3)
{
  _IO[0] = IO0;
  _IO[1] = IO1;
  _IO[2] = IO2;
  _IO[3] = IO3;
}
 

int AM9111::read(unsigned int address)
{
  int rv = 0;
  _setAddress(address);
  return rv;
}

int AM9111::write(unsigned int address, uint8_t value)
{
  int rv = 0;
  _setAddress(address);
  rv = _write(value);
  return rv;
}

/////////////////////////////////////////
//
// PRIVATE
//
void AM9111::_setAddress(unsigned int address)
{
for(int p=0; p<8; p++)
{
  pinMode(p, OUTPUT);
  digitalWrite(p, bitRead(address, p));
}
}


int AM9111::_read()
{
  digitalWrite(_odp,0);
  digitalWrite(_wep,1);
  int rv = 0;
  bitWrite(rv,0,digitalRead(_IO[0]));
  bitWrite(rv,1,digitalRead(_IO[1]));
  bitWrite(rv,2,digitalRead(_IO[2]));
  bitWrite(rv,3,digitalRead(_IO[3]));
  return rv;
}


int AM9111::_write(uint8_t value)
{
  digitalWrite(_odp,1);
  digitalWrite(_wep,0);
  int  rv = 0;
  digitalWrite(_IO[0],bitRead(0,value));
  digitalWrite(_IO[1],bitRead(1,value));
  digitalWrite(_IO[2],bitRead(2,value));
  digitalWrite(_IO[3],bitRead(3,value));
  return rv;
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

is it because of the first read statement rv = 0?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes.
That, and the fact that you don't call _read from read.
« Last Edit: April 23, 2011, 02:34:46 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Intermediate Arduino user
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how do you call _read from read?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In your own reply #30, you very nearly did.
You just got it the wrong way round.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: 1 2 [3] 4   Go Up
Jump to: