12 years, 5 months ago.

fault in my c-syntax

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:

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

If you surround your code in <<code>> and <</code>> it makes it much easier to read.

posted by Stephen Paulger 15 Mar 2013

3 Answers

12 years, 5 months ago.

Please use English variable names and comments. Your first problem is that leesregister returns void while you mean char, this is also your fourth problem. Your third problem is that you try to dereference a char while you can only dereference pointers. Your second problem is that the arguments of write do not match the prototype.

Accepted Answer
12 years, 5 months ago.

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

12 years, 5 months ago.

Hi adriaan

  • in the first error your function leesregister is void, is not returning nothing to compare in the while condition
  • in the second error, if you check this:

http://mbed.org/handbook/I2C

you will see that the one of the write functions receive the following parameters: (int, cons char *, int, bool) not (int, char, int, int) as you use in your code

  • for the third error, you put a return statement in your function leesregister but the type of return of the function is void

I hope this points will help you

Greetings