Hi,
I have good experience with arduino and C++ but still there are times when things confuses me.
In the following code I want to read two bytes in the uint8_t array type called temo[2].
I am not sure for the syntex and kind of error I am getting.
supoose if I remove the [] from the declaration of the readbytes function like following
void readbytes(uint8_t reg, int count, uint8_t temp)
I get invalid type conversion error from uint8_t* to uint8_t. I am not sure where I have used pointer types in here?
Is it because the arrays are stored in memory with pointer to first element?
"invalid conversion from 'uint8_t*' {aka 'unsigned char*'} to 'uint8_t' {aka 'unsigned char'}"
Then I tried to change function call inside a loop() function like the following. Explicitly specifying array type readbytes(Configuration, 2, temp[]);
then the error is
""error: expected primary-expression before ']' token"
void loop() {
// put your main code here, to run repeatedly:
uint8_t data[2];
uint8_t temp[2];
readbytes(Configuration, 2, temp);
delay(1000);
}
void readbytes(uint8_t reg, int count, uint8_t temp[]){
Wire.beginTransmission(address);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(address, count);
for(int i=0; i< count; i++){
temp[i] = Wire.read();
Serial.println(temp[i]);
}
}
Could you rename the function 'readbytes()' to something else ?
There is already a 'Wire.readBytes()' because the Wire library is part of the Stream class. See Stream.readBytes().
There is a undocumented 'Wire.requestFrom()' that first sets the register and then calls the normal 'Wire.requestFrom()'. On some platforms it is normally used, but for the Arduino Uno it is still undocumented.
Thank you for your replies.
Actually code was always working but some explanation was required. like I have mentioned regarding unsupported type conversion etc.
Of couse, I have changed the names of the functions..