Fixed incorrect pin assignment
This commit is contained in:
parent
ba82497c8e
commit
7780c499a1
2 changed files with 31 additions and 31 deletions
|
@ -6,7 +6,7 @@ Module::Module(int rx, int tx) {
|
|||
_tx = tx;
|
||||
_int0 = -1;
|
||||
_int1 = -1;
|
||||
|
||||
|
||||
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,14 @@ Module::Module(int cs, int int0, int int1, SPIClass& spi) {
|
|||
_spi = &spi;
|
||||
}
|
||||
|
||||
Module::Module(int cs, int rx, int tx, int int0, int int1, SPIClass& spi) {
|
||||
Module::Module(int cs, int int0, int int1, int rx, int tx, SPIClass& spi) {
|
||||
_cs = cs;
|
||||
_rx = rx;
|
||||
_tx = tx;
|
||||
_int0 = int0;
|
||||
_int1 = int1;
|
||||
_spi = &spi;
|
||||
|
||||
|
||||
ModuleSerial = new SoftwareSerial(_rx, _tx);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ void Module::init(uint8_t interface, uint8_t gpio) {
|
|||
case USE_I2C:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// select GPIO
|
||||
switch(gpio) {
|
||||
case INT_NONE:
|
||||
|
@ -85,21 +85,21 @@ bool Module::ATsendData(uint8_t* data, uint32_t len) {
|
|||
for(uint32_t i = 0; i < len; i++) {
|
||||
ModuleSerial->write(data[i]);
|
||||
}
|
||||
|
||||
|
||||
ModuleSerial->print(AtLineFeed);
|
||||
return(ATgetResponse());
|
||||
}
|
||||
|
||||
bool Module::ATgetResponse() {
|
||||
String data = "";
|
||||
uint32_t start = millis();
|
||||
uint32_t start = millis();
|
||||
while (millis() - start < _ATtimeout) {
|
||||
while(ModuleSerial->available() > 0) {
|
||||
char c = ModuleSerial->read();
|
||||
DEBUG_PRINT(c);
|
||||
data += c;
|
||||
}
|
||||
|
||||
|
||||
if(data.indexOf("OK") != -1) {
|
||||
DEBUG_PRINTLN();
|
||||
return(true);
|
||||
|
@ -107,7 +107,7 @@ bool Module::ATgetResponse() {
|
|||
DEBUG_PRINTLN();
|
||||
return(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
DEBUG_PRINTLN();
|
||||
return(false);
|
||||
|
@ -117,7 +117,7 @@ int16_t Module::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) {
|
|||
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
||||
return(ERR_INVALID_BIT_RANGE);
|
||||
}
|
||||
|
||||
|
||||
uint8_t rawValue = SPIreadRegister(reg);
|
||||
uint8_t maskedValue = rawValue & ((0b11111111 << lsb) & (0b11111111 >> (7 - msb)));
|
||||
return(maskedValue);
|
||||
|
@ -127,12 +127,12 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
|
|||
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
|
||||
return(ERR_INVALID_BIT_RANGE);
|
||||
}
|
||||
|
||||
|
||||
uint8_t currentValue = SPIreadRegister(reg);
|
||||
uint8_t mask = ~((0b11111111 << (msb + 1)) | (0b11111111 >> (8 - lsb)));
|
||||
uint8_t newValue = (currentValue & ~mask) | (value & mask);
|
||||
SPIwriteRegister(reg, newValue);
|
||||
|
||||
|
||||
// check register value each millisecond until check interval is reached
|
||||
// some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE)
|
||||
uint32_t start = micros();
|
||||
|
@ -144,7 +144,7 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
|
|||
return(ERR_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check failed, print debug info
|
||||
DEBUG_PRINTLN();
|
||||
DEBUG_PRINT(F("address:\t0x"));
|
||||
|
@ -164,7 +164,7 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
|
|||
DEBUG_PRINT(F("read:\t\t0b"));
|
||||
DEBUG_PRINTLN(readValue, BIN);
|
||||
DEBUG_PRINTLN();
|
||||
|
||||
|
||||
return(ERR_SPI_WRITE_FAILED);
|
||||
}
|
||||
|
||||
|
@ -189,13 +189,13 @@ void Module::SPIwriteRegister(uint8_t reg, uint8_t data) {
|
|||
void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
|
||||
// start SPI transaction
|
||||
_spi->beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
|
||||
|
||||
|
||||
// pull CS low
|
||||
digitalWrite(_cs, LOW);
|
||||
|
||||
|
||||
// send SPI register address with access command
|
||||
_spi->transfer(reg | cmd);
|
||||
|
||||
|
||||
// send data or get response
|
||||
if(cmd == SPIwriteCommand) {
|
||||
for(size_t n = 0; n < numBytes; n++) {
|
||||
|
@ -206,10 +206,10 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da
|
|||
dataIn[n] = _spi->transfer(0x00);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// release CS
|
||||
digitalWrite(_cs, HIGH);
|
||||
|
||||
|
||||
// end SPI transaction
|
||||
_spi->endTransaction();
|
||||
}
|
||||
|
|
26
src/Module.h
26
src/Module.h
|
@ -12,50 +12,50 @@ class Module {
|
|||
Module(int tx, int rx);
|
||||
Module(int cs, int int0, int int1, SPIClass& spi = SPI);
|
||||
Module(int cs, int int0, int int1, int rx, int tx, SPIClass& spi = SPI);
|
||||
|
||||
|
||||
SoftwareSerial* ModuleSerial;
|
||||
|
||||
|
||||
uint32_t baudrate = 9600;
|
||||
const char* AtLineFeed = "\r\n";
|
||||
|
||||
|
||||
uint8_t SPIreadCommand = 0b00000000;
|
||||
uint8_t SPIwriteCommand = 0b10000000;
|
||||
|
||||
|
||||
void init(uint8_t interface, uint8_t gpio);
|
||||
void term();
|
||||
|
||||
|
||||
void ATemptyBuffer();
|
||||
bool ATgetResponse();
|
||||
bool ATsendCommand(const char* cmd);
|
||||
bool ATsendData(uint8_t* data, uint32_t len);
|
||||
|
||||
|
||||
int16_t SPIgetRegValue(uint8_t reg, uint8_t msb = 7, uint8_t lsb = 0);
|
||||
int16_t SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2);
|
||||
|
||||
|
||||
void SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes);
|
||||
uint8_t SPIreadRegister(uint8_t reg);
|
||||
|
||||
|
||||
void SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, uint8_t numBytes);
|
||||
void SPIwriteRegister(uint8_t reg, uint8_t data);
|
||||
|
||||
|
||||
void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes);
|
||||
|
||||
|
||||
int getCs() const { return(_cs); }
|
||||
int getInt0() const { return(_int0); }
|
||||
int getInt1() const { return(_int1); }
|
||||
int getRx() const { return(_rx); }
|
||||
int getTx() const { return(_tx); }
|
||||
SPIClass* getSpi() const { return(_spi); }
|
||||
|
||||
|
||||
private:
|
||||
int _cs;
|
||||
int _tx;
|
||||
int _rx;
|
||||
int _int0;
|
||||
int _int1;
|
||||
|
||||
|
||||
SPIClass* _spi;
|
||||
|
||||
|
||||
uint32_t _ATtimeout = 15000;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue