@@ -88,6 +88,10 @@ void SPIClass::beginTransaction(SPISettings mySettings) {
88
88
#ifdef SPI_DEBUG
89
89
debugf (" SPIhw::beginTransaction(SPISettings mySettings)" );
90
90
#endif
91
+
92
+ // store SPI user register
93
+ _userReg = READ_PERI_REG (SPI_USER (SPI_NO));
94
+
91
95
// check if we need to change settings
92
96
if (this ->_SPISettings == mySettings)
93
97
return ;
@@ -108,6 +112,10 @@ void SPIClass::endTransaction() {
108
112
#ifdef SPI_DEBUG
109
113
debugf (" SPIhw::endTransaction()" );
110
114
#endif
115
+
116
+ // restore SPI user register
117
+ WRITE_PERI_REG (SPI_USER (SPI_NO), _userReg);
118
+ _userReg = 0 ;
111
119
};
112
120
113
121
/* @defgroup SPI hardware implementation
@@ -125,7 +133,7 @@ void SPIClass::endTransaction() {
125
133
uint32 SPIClass::transfer32 (uint32 data, uint8 bits)
126
134
{
127
135
// restore inital SPI_USER register
128
- uint32_t regvalue = _SPISettings. _user_regvalue ;
136
+ uint32_t regvalue = READ_PERI_REG ( SPI_USER (SPI_NO)) ;
129
137
130
138
while (READ_PERI_REG (SPI_CMD (SPI_NO))&SPI_USR);
131
139
@@ -193,7 +201,7 @@ void SPIClass::transfer(uint8 *buffer, size_t numberBytes) {
193
201
num_bits = bufLenght * 8 ;
194
202
195
203
// restore inital SPI_USER register
196
- uint32_t regvalue = _SPISettings. _user_regvalue ;
204
+ uint32_t regvalue = READ_PERI_REG ( SPI_USER (SPI_NO)) ;
197
205
198
206
while (READ_PERI_REG (SPI_CMD (SPI_NO))&SPI_USR);
199
207
@@ -242,9 +250,9 @@ void SPIClass::prepare(SPISettings mySettings) {
242
250
debugf (" SPIClass::prepare(SPISettings mySettings)" );
243
251
mySettings.print (" mySettings" );
244
252
#endif
245
-
253
+
246
254
// check if we need to change settings
247
- if (_init & _SPISettings == mySettings)
255
+ if (_init && _SPISettings == mySettings)
248
256
return ;
249
257
250
258
// setup clock
@@ -261,7 +269,6 @@ void SPIClass::prepare(SPISettings mySettings) {
261
269
#endif
262
270
263
271
_SPISettings = mySettings;
264
- mySettings._user_regvalue = SPI_USER (SPI_NO);
265
272
_init = true ;
266
273
};
267
274
@@ -441,7 +448,7 @@ void SPIClass::setFrequency(int freq) {
441
448
int _CPU_freq = system_get_cpu_freq () * 10000000UL ;
442
449
443
450
// dont run code if there are no changes
444
- if (_init & freq == _SPISettings._speed ) return ;
451
+ if (_init && freq == _SPISettings._speed ) return ;
445
452
446
453
// run full speed -> do not use any dividers
447
454
if (freq == _CPU_freq) {
0 commit comments