Skip to content

Instantly share code, notes, and snippets.

@fvdnabee
Created March 17, 2016 11:28
Show Gist options
  • Save fvdnabee/26f14275c8f95701b292 to your computer and use it in GitHub Desktop.
Save fvdnabee/26f14275c8f95701b292 to your computer and use it in GitHub Desktop.
diff --git a/dev/sht11/sht11.c b/dev/sht11/sht11.c
index f6780d0..5b81099 100644
--- a/dev/sht11/sht11.c
+++ b/dev/sht11/sht11.c
@@ -65,6 +65,7 @@
/* This can probably be reduced to 250ns according to data sheet. */
#ifndef delay_400ns
#define delay_400ns() _NOP()
+//#define delay_400ns() __delay_cycles(4); // 500 ns @ 8MHz
#endif
/*---------------------------------------------------------------------------*/
static void
@@ -106,9 +107,9 @@ sreset(void)
static int
swrite(unsigned _c)
{
- unsigned char c = _c;
+ volatile unsigned char c = _c;
int i;
- int ret;
+ volatile int ret;
for(i = 0; i < 8; i++, c <<= 1) {
if(c & 0x80) {
@@ -136,7 +137,7 @@ static unsigned
sread(int send_ack)
{
int i;
- unsigned char c = 0x00;
+ volatile unsigned char c = 0x00;
SDA_1();
for(i = 0; i < 8; i++) {
@@ -262,9 +263,10 @@ scmd(unsigned cmd)
goto fail;
}
- for(n = 0; n < 20000; n++) {
+ watchdog_stop();
+ for(n = 0; n < 1000; n++) {
if(!SDA_IS_1) {
- unsigned t0, t1, rcrc;
+ volatile unsigned t0, t1, rcrc;
t0 = sread(1);
t1 = sread(1);
rcrc = sread(0);
@@ -282,12 +284,15 @@ scmd(unsigned cmd)
}
}
#endif
+ watchdog_start();
return (t0 << 8) | t1;
}
/* short wait before next loop */
clock_wait(1);
+ //__delay_cycles(8000); // 1 ms
}
fail:
+ watchdog_start();
sreset();
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment