SAKURA Internet IoT Alpha Communication Module Library for mbed
Dependents: SakuraAlpha_SPI SakuraAlpha_I2C
Revision 1:b31d9bb6e65f, committed 2016-06-03
- Comitter:
- sakurafan
- Date:
- Fri Jun 03 09:15:25 2016 +0000
- Parent:
- 0:38f4d6047886
- Commit message:
- bug fix: i2c receive
Changed in this revision
| SakuraAlpha.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SakuraAlpha.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SakuraAlpha.cpp Tue May 31 13:36:07 2016 +0000
+++ b/SakuraAlpha.cpp Fri Jun 03 09:15:25 2016 +0000
@@ -272,13 +272,20 @@
}
void SakuraAlphaI2C::startReceiving(uint16_t num_recieve){
+ _num_recieve = num_recieve;
_i2c.start();
_i2c.write(SAKURACC_SLAVE_ADDR | 1);
}
uint8_t SakuraAlphaI2C::receiveByte(){
- return _i2c.read(1);
+ if (_num_recieve <= 0) return 0;
+ _num_recieve --;
+ return _i2c.read(_num_recieve > 0 ? 1 : 0);
}
void SakuraAlphaI2C::finishReceiving(){
+ while (_num_recieve > 0) {
+ _num_recieve --;
+ _i2c.read(_num_recieve > 0 ? 1 : 0);
+ }
_i2c.stop();
}
--- a/SakuraAlpha.h Tue May 31 13:36:07 2016 +0000
+++ b/SakuraAlpha.h Fri Jun 03 09:15:25 2016 +0000
@@ -95,6 +95,7 @@
protected:
I2C _i2c;
+ int _num_recieve;
virtual void begin();
virtual void end();