I wrote a class for Aduino, for reading an ads124x, and I am having one major problem, I can't call a function defined by the class. Here is how it is structured:
- .ino calls functions using . operator
- .h contains register map and class definition
- .cpp contains all functions of the class
so far here is what is happening the .ino is successfully calling a function in .cpp, but when that same function calles another in .cpp it fails to call.
.ino:
#include "ADS124X.h"
void setup(){
ADS124X ADS124X(1,2,3,4);
Serial.begin(9600);
ADS124X.setUP(0x20, 0x20);}
.h:
class ADS124X{
public:
void reset(void);
void setUP(unsigned char* mux1, unsigned char* sys0);
private:
void SPI_Write(unsigned char* data, unsigned char size);
}
.cpp:
void ADS124X::setUP(unsigned char * mux1, unsigned char * sys0)
{
Serial.println("hi"); //prints this
delay(1);
reset(); // stops here
Serial.println("hi"); // doesn't print this
delay(1);
stopDataCont();
delay(210);
setREG(MUX1, mux1, 1);
setREG(SYS0, 0x01, 1);
delay(1);
}
void ADS124X::reset(void)
{
unsigned char dataToSend[] = { RESET };
START_HIGH;
CS_LOW;
Serial.println(RESET); // prints this as 0x06 (correct value)
SPI_Write(dataToSend, 1); // Seems to stop here
START_LOW;
CS_HIGH;
}
void ADS124X::SPI_Write(unsigned char * data, unsigned char size)
{
Serial.println("SPI_Write"); //prints this
for (unsigned int i = 0; i < size; i++) {
Serial.println("SPI_Write"); //prints this
Serial.println(* data); //prints this as 126 (if RESET is 3 * data becomes 189...)
SPI.transfer(*data);
Serial.println("SPI_Write");
data++;
}
}