projects
/
cortex-from-scratch
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
HSE usage
[cortex-from-scratch]
/
drivers
/
tm1637.c
diff --git
a/drivers/tm1637.c
b/drivers/tm1637.c
index
517e0cf
..
a2889fd
100644
(file)
--- a/
drivers/tm1637.c
+++ b/
drivers/tm1637.c
@@
-28,7
+28,7
@@
#include <drivers/tm1637.h>
#include <drivers/tm1637.h>
-#define TIMEOUT
1
000
+#define TIMEOUT
5
000
#define DATASET 0x40
#define CONTROL 0x80
#define DATASET 0x40
#define CONTROL 0x80
@@
-79,7
+79,7
@@
static void stop_condition() {
int ack_recv() {
int cnt = 0;
int ack_recv() {
int cnt = 0;
- while(!(*I2C_SR1 & 0x
1
)) {
+ while(!(*I2C_SR1 & 0x
2
)) {
cnt++;
if (cnt > TIMEOUT)
return 0;
cnt++;
if (cnt > TIMEOUT)
return 0;
@@
-89,6
+89,17
@@
int ack_recv() {
}
}
+int buf_empty() {
+ int cnt = 0;
+ while(!(*I2C_SR1 & 0x80)) {
+ cnt++;
+ if (cnt > TIMEOUT)
+ return 0;
+ }
+
+ return 1;
+}
+
int delay() {
int a = 0;
int delay() {
int a = 0;
@@
-127,18
+138,18
@@
void tm1637_start() {
//statusr = *I2C_SR1;
//statusr = *I2C_SR2;
regw_u32(I2C_DR, 0x7D, 0, OWRITE);
//statusr = *I2C_SR1;
//statusr = *I2C_SR2;
regw_u32(I2C_DR, 0x7D, 0, OWRITE);
- if(!
ack_recv
())
+ if(!
buf_empty
())
cputs("TIMEOUT3!");
stop_condition();
cputs("TIMEOUT3!");
stop_condition();
-
delay();
+
/*
delay();
start_condition();
statusr = *I2C_SR1;
regw_u32(I2C_DR, DISPLAY_ON, 0, OWRITE);
if(!ack_recv())
cputs("TIMEOUT4!");
start_condition();
statusr = *I2C_SR1;
regw_u32(I2C_DR, DISPLAY_ON, 0, OWRITE);
if(!ack_recv())
cputs("TIMEOUT4!");
- stop_condition();
+ stop_condition();
*/
/* regw_u32(I2C_CR1, 0x1, 8, SETBIT); //start
/* regw_u32(I2C_CR1, 0x1, 8, SETBIT); //start