-
Notifications
You must be signed in to change notification settings - Fork 0
/
i2cClock.spin
66 lines (46 loc) · 1.35 KB
/
i2cClock.spin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{I2C Clock object on pin SCL_pin}
CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
Tlow = 108
Thigh = 90
SCL_pin = 17
VAR
long stack[10] 'Cog stack space
byte cog
OBJ
PUB Start 'Cog start method
Stop
cog := cognew(@_entry, @stack) + 1
PUB Stop 'Cog stop method
if cog
cogstop(cog~ - 1)
DAT
DAT
org 0
_entry
rdlong sfreq, #0
mov delay, cnt
add delay, sfreq
waitcnt delay, sfreq 'Start delay of 1s
or dira, clk_pin 'Set data and clock to output
i2c_clk or outa, clk_pin
call#highdlay
andn outa, clk_pin
call #lowdlay
jmp #i2c_clk
highdlay mov time, cnt 'Get current system clock time
add time, t_high
waitcnt time, t_high
highdlay_ret ret
lowdlay mov time, cnt 'Get current system clock time
add time, t_low
waitcnt time, t_low
lowdlay_ret ret
clk_pin long |<SCL_pin
delay long 0
t_high long Thigh
t_low long Tlow
time long 0
sfreq long 0
fit