Skip to content

Commit d16ca2c

Browse files
committed
Protected the config register writes.
1 parent 7212493 commit d16ca2c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,4 @@ pip-log.txt
190190

191191
# Mac crap
192192
.DS_Store
193+
*.cpp~

src/SparkFun_MiniGen.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ void MiniGen::setMode(MODE newMode)
7777
configReg |=0x0000;
7878
break;
7979
}
80+
81+
// Make sure to clear the top two bit to make sure we're writing the config register:
82+
configReg &= ~0xC000;
83+
8084
SPIWrite(configReg); // Now write our shadow copy to the part.
8185
}
8286

@@ -90,6 +94,10 @@ void MiniGen::selectFreqReg(FREQREG reg)
9094
if (reg == FREQ0) configReg &= ~0x0800;
9195
// Otherwise, set bit 11.
9296
else configReg |= 0x0800;
97+
98+
// Make sure to clear the top two bit to make sure we're writing the config register:
99+
configReg &= ~0xC000;
100+
93101
SPIWrite(configReg);
94102
}
95103

@@ -99,6 +107,10 @@ void MiniGen::selectPhaseReg(PHASEREG reg)
99107
{
100108
if (reg == PHASE0) configReg &= ~0x0400;
101109
else configReg |= 0x0400;
110+
111+
// Make sure to clear the top two bit to make sure we're writing the config register:
112+
configReg &= ~0xC000;
113+
102114
SPIWrite(configReg);
103115
}
104116

@@ -128,6 +140,10 @@ void MiniGen::setFreqAdjustMode(FREQADJUSTMODE newMode)
128140
configReg |= 0x2000;
129141
break;
130142
}
143+
144+
// Make sure to clear the top two bit to make sure we're writing the config register:
145+
configReg &= ~0xC000;
146+
131147
SPIWrite(configReg);
132148
}
133149

0 commit comments

Comments
 (0)