我为Aduino写了一个类,用于阅读ads124x,我遇到一个主要问题,我无法调用该类定义的函数。以下是它的结构:
到目前为止,.ino正在成功调用.cpp中的函数,但是当同一个函数在.cpp中调用另一个函数时,它无法调用。
.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++;
}
}
答案 0 :(得分:1)
这不对......
Serial.println(RESET); // println expects a null terminated string
// you are sending a char.
您应该将dataToSend定义为以null结尾的char数组。
void ADS124X::reset(void)
{
char dataToSend[] = { RESET, 0 };
// ...
serial.println(dataToSend); // maybe println "reset" would be better?
SPI_Write(dataToSend, 1);
//...
}
不要期望在串口显示器上看到一个不错的0x06
,因为它不是可打印的字符。