[CC1101] Added method to read version register

This commit is contained in:
jgromes 2020-11-20 17:52:32 +01:00
parent ff520e2a15
commit b4701c370b
2 changed files with 14 additions and 2 deletions

View file

@ -16,7 +16,7 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po
uint8_t i = 0; uint8_t i = 0;
bool flagFound = false; bool flagFound = false;
while((i < 10) && !flagFound) { while((i < 10) && !flagFound) {
uint8_t version = SPIreadRegister(CC1101_REG_VERSION); int16_t version = getChipVersion();
if((version == CC1101_VERSION_CURRENT) || (version == CC1101_VERSION_LEGACY)) { if((version == CC1101_VERSION_CURRENT) || (version == CC1101_VERSION_LEGACY)) {
flagFound = true; flagFound = true;
} else { } else {
@ -28,7 +28,7 @@ int16_t CC1101::begin(float freq, float br, float freqDev, float rxBw, int8_t po
char buffHex[7]; char buffHex[7];
sprintf(buffHex, "0x%04X", version); sprintf(buffHex, "0x%04X", version);
RADIOLIB_DEBUG_PRINT(buffHex); RADIOLIB_DEBUG_PRINT(buffHex);
RADIOLIB_DEBUG_PRINT(F(", expected 0x0014")); RADIOLIB_DEBUG_PRINT(F(", expected 0x0004/0x0014"));
RADIOLIB_DEBUG_PRINTLN(); RADIOLIB_DEBUG_PRINTLN();
#endif #endif
Module::delay(10); Module::delay(10);
@ -751,6 +751,11 @@ uint8_t CC1101::random() {
return(randByte); return(randByte);
} }
int16_t CC1101::getChipVersion() {
return(_mod->SPIgetRegValue(CC1101_REG_VERSION));
}
int16_t CC1101::config() { int16_t CC1101::config() {
// Reset the radio. Registers may be dirty from previous usage. // Reset the radio. Registers may be dirty from previous usage.
SPIsendCommand(CC1101_CMD_RESET); SPIsendCommand(CC1101_CMD_RESET);

View file

@ -882,6 +882,13 @@ class CC1101: public PhysicalLayer {
*/ */
uint8_t random(); uint8_t random();
/*!
\brief Read version SPI register. Should return CC1101_VERSION_LEGACY (0x04) or CC1101_VERSION_CURRENT (0x14) if CC1101 is connected and working.
\returns Version register contents or \ref status_codes
*/
int16_t getChipVersion();
#ifndef RADIOLIB_GODMODE #ifndef RADIOLIB_GODMODE
private: private:
#endif #endif