Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:07b9f0e0424c, committed 2020-04-14
- Comitter:
- jack1930
- Date:
- Tue Apr 14 12:49:03 2020 +0000
- Parent:
- 3:e15fb8277f9b
- Commit message:
- wait_us ersetzt
Changed in this revision
| SoftwareI2C.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SoftwareI2C.h Wed Mar 04 18:29:47 2020 +0000
+++ b/SoftwareI2C.h Tue Apr 14 12:49:03 2020 +0000
@@ -44,7 +44,7 @@
_sda = 1;
_scl = 0;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
for ( int n = 0; n <= 3; ++n ) {
stop();
@@ -52,35 +52,44 @@
}
private:
+ void warte(int zeit)
+ {
+ for (int i=0;i<zeit*5;i++)
+ {
+ asm(
+ "nop\n\t"
+ );
+ }
+ }
inline void start() {
_sda.output();
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_scl = 1;
_sda = 1;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_sda = 0;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_scl = 0;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
}
inline void stop() {
_sda.output();
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_sda = 0;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_scl = 1;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_sda = 1;
}
inline void putByte(uint8_t byte) {
_sda.output();
for ( int n = 8; n > 0; --n) {
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_sda = byte & (1 << (n-1));
_scl = 1;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_scl = 0;
}
_sda = 1;
@@ -92,15 +101,15 @@
_sda.input(); //release the data line
_sda.mode(OpenDrain);
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
for ( int n = 8; n > 0; --n ) {
_scl=1; //set clock high
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
byte |= _sda << (n-1); //read the bit
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_scl=0; //set clock low
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
}
_sda.output(); //take data line back
@@ -110,10 +119,10 @@
inline void giveAck() {
_sda.output();
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_sda = 0;
_scl = 1;
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_scl = 0;
_sda = 1;
@@ -125,12 +134,12 @@
_scl = 1;
_sda.input();
_sda.mode(OpenDrain);
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
_scl = 0;
if(_sda != 0){return false;}
- wait_us(_frequency_delay);
+ warte(_frequency_delay);
return true;
}