OMRON D6T

Hi there,

Im new to C++ Programming and trying following c++ code.

#include
// I2C communication functions
extern void I2C_start();
extern void I2C_repeatstart();
extern void I2C_stop();
extern void I2C_send1( char addr8 , char cmd );
extern void I2C_getx( char addr8 , char buff[] , int length );
extern int D6T_checkPEC( char buff[] , int tPEC );

// Global var.
extern char readbuff[35]; extern int tPTAT;
extern int tP[16];
extern int tPEC;
extern int status;
int LOOPLIMIT = 5000;

int D6T_getvalue() {
I2C_start();
I2C_send1( 0x14 , 0x4C ); // 14h = { 0Ah(Addr7) : Write(0b) }
I2C_repeatstart();
I2C_getx( 0x15 , readbuff , 35 ); // 15h
I2C_stop();

if(!D6T_checkPEC(readbuff,34)){
return -1; // error
}
tPTAT = 256*readbuff[1] + readbuff[0];
tP[0] = 256*readbuff[3] + readbuff[2];
tP[1] = 256*readbuff[5] + readbuff[4];
tP[2] = 256*readbuff[7] + readbuff[6];
tP[3] = 256*readbuff[9] + readbuff[8];
tP[4] = 256*readbuff[11] + readbuff[10];
tP[5] = 256*readbuff[13] + readbuff[12];
tP[6] = 256*readbuff[15] + readbuff[14];
tP[7] = 256*readbuff[17] + readbuff[16];
tP[8] = 256*readbuff[19] + readbuff[18];
tP[9] = 256*readbuff[21] + readbuff[20];
tP[10] = 256*readbuff[23] + readbuff[22];
tP[11] = 256*readbuff[25] + readbuff[24];
tP[12] = 256*readbuff[27] + readbuff[26];
tP[13] = 256*readbuff[29] + readbuff[28];
tP[14] = 256*readbuff[31] + readbuff[30];
tP[15] = 256*readbuff[33] + readbuff[32];
tPEC = readbuff[34];
return 1;
}


Im getting following error after compilation.

Compiler: Default compiler
main.cpp: In function `int D6T_getvalue()':
main.cpp:20: error: invalid conversion from `char*' to `char'
main.cpp:20: error: initializing argument 1 of `int D6T_checkPEC(char, int)'

main.cpp:20: error: `If' undeclared (first use this function)
main.cpp:20: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:21: error: expected `;' before '{' token
main.cpp: At global scope:
main.cpp:46: error: ISO C++ forbids declaration of `measure' with no type
main.cpp: In function `int measure()':
main.cpp:47: error: `n' undeclared (first use this function)
main.cpp:49: error: `status' undeclared (first use this function)
main.cpp:51: error: `LOOPLIMIT' undeclared (first use this function)
main.cpp:52: error: `If' undeclared (first use this function)

main.cpp:52: error: expected `;' before '{' token
main.cpp:56: error: `print' undeclared (first use this function)
main.cpp:56: error: expected `;' before "f"
main.cpp:56: error: stray '\147' in program
main.cpp:58: error: stray '\148' in program
main.cpp:60: error: expected `}' at end of input

Any Help would be highly appreciated.

Many thanks


















Last edited on
Post code in code tags.

The #include statement is incomplete, also the code doesn't look like the complete code. For example the error "main.cpp:46: error: ISO C++ forbids declaration of `measure' with no type
main.cpp: In function `int measure()':" I see no "measure" in the code
I get no errors compiling this in Visual Studio.
What compiler are you using?

The first error you report is at line 20. Assuming your line numbers line up (can't tell without code tags), line 20 is:
 
    I2C_send1( 0x14 , 0x4C ); 


There does not appear to be anything wrong with that function call. The function prototype for I2C_send1 expects two chars and that is what you're passing.

You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
I will not respond further until you apply code tags.

Edit: Your second error message refers to D6T_checkPEC() at line 20, which is really line 24 of your code snippet.
 
if (! D6T_checkPEC(readbuff,34))

Again, there doesn't appear to be anything wrong with that call. D6T_checkPEC is expecting a char array and an int, and that is what you are passing.

You posted errors messages from lines 46-60, however, you only posted 46 lines of code.
Last edited on
Topic archived. No new replies allowed.