problem in my c-syntax, thank you

15 Mar 2013

hi, im getting faults in my c-syntax and i dont know why. what i want to do: im sending a command (1) to ctrl register (0), this will start a measure, after this measure is finished the ic will automatically reset the ctrl register, i only want to wait the time needed to wait, so im waiting till the ctrl register is 0 again:


code

void startmeting() we zetten het ctrl register (0) op 1 zodat er een meting uitgevoerd wordt deze 1 wordt na de meting automatisch terug gereset { char sendstartsample[2]={0,1}; sturen eerst 0(register) en dan een 1 (weg te schrijven waarde)

i2c.write(addr, sendstartsample, 2, 0); 0 en 1 worden naar slave geschreven

while(leesregister(0x00) != '0');

pc.printf("\n\r meting is gedaan");

}

void leesregister(char adres)

{

char terugstuurwaarde;

i2c.write(addr, adres, 1, 0);

i2c.read(addr, *terugstuurwaarde, 1, 0);

return terugstuurwaarde;

}
thnx in advance

the faults i get when i try to compile:

"expression must have arithmetic, enum, or pointer type" in file "/main.cpp", || while(leesregister(0x00) != '0');

"no instance of overloaded function "mbed::I2C::write" matches the argument list" in file "/main.cpp", Line: 65, Col: 34 || i2c.write(addr, adres, 1, 0);

"operand of "*" must be a pointer" in file "/main.cpp", Line: 66, Col: 16 || i2c.read(addr, *terugstuurwaarde, 1, 0);

"return value type does not match the function type" in file "/main.cpp", Line: 67, Col: 7 || return terugstuurwaarde;

thnx in advance

09 May 2013

Hi,

I think I can help. I apologize if I misunderstand your code. I'm not familiar with your native language.

First error:

"expression must have arithmetic, enum, or pointer type" in file "/main.cpp", || while(leesregister(0x00) != '0');

This is because your function "leesregister" is declared as void, but you are trying to read it's return value.

Change this:

void leesregister(char adres)

To this:

char leesregister(char adres)

This should also fix the last error:

"return value type does not match the function type" in file "/main.cpp", Line: 67, Col: 7 || return terugstuurwaarde;

The middle two errors are a bit more difficult to explain. Basically, the member functions "write" and "read" accept pointers as one of their arguments. You aren't providing pointers. I would suggest reading up on pointers as they are an essential concept in C.

For now, you should be able to do this to fix your problem:

Change this:

i2c.write(addr, adres, 1, 0);
i2c.read(addr, *terugstuurwaarde, 1, 0);

To this:

i2c.write(addr, &adres, 1, 0);
i2c.read(addr, &terugstuurwaarde, 1, 0);

I would suggest reading this to help with pointers: http://www.cplusplus.com/doc/tutorial/pointers/

17 May 2013

This issue can be resolved only if you visit this link http://www.papersville.co.uk/Custom-assignment-writing/