Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
f352fe82
Commit
f352fe82
authored
Sep 09, 2015
by
Daniel Campora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests/wipy: Add I2C tests.
parent
d265df58
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
296 additions
and
55 deletions
+296
-55
cc3200/mods/pybi2c.c
cc3200/mods/pybi2c.c
+82
-54
cc3200/mods/pybuart.c
cc3200/mods/pybuart.c
+1
-1
tests/wipy/i2c.py
tests/wipy/i2c.py
+165
-0
tests/wipy/i2c.py.exp
tests/wipy/i2c.py.exp
+48
-0
No files found.
cc3200/mods/pybi2c.c
View file @
f352fe82
This diff is collapsed.
Click to expand it.
cc3200/mods/pybuart.c
View file @
f352fe82
...
...
@@ -401,7 +401,7 @@ STATIC mp_obj_t pyb_uart_init_helper(pyb_uart_obj_t *self, mp_uint_t n_args, con
uint
flowcontrol
=
UART_FLOWCONTROL_NONE
;
if
(
pins_o
!=
mp_const_none
)
{
mp_obj_t
*
pins
;
mp_uint_t
n_pins
;
mp_uint_t
n_pins
=
2
;
if
(
pins_o
==
MP_OBJ_NULL
)
{
// use the default pins
pins
=
(
mp_obj_t
*
)
pyb_uart_def_pin
[
self
->
uart_id
];
...
...
tests/wipy/i2c.py
0 → 100644
View file @
f352fe82
'''
I2C test for the CC3200 based boards.
A MPU-9150 sensor must be connected to the I2C bus.
'''
from
pyb
import
I2C
from
pyb
import
Pin
import
os
import
pyb
machine
=
os
.
uname
().
machine
if
'LaunchPad'
in
machine
:
i2c_pins
=
(
'GP11'
,
'GP10'
)
elif
'WiPy'
in
machine
:
i2c_pins
=
(
'GP15'
,
'GP10'
)
else
:
raise
Exception
(
'Board not supported!'
)
i2c
=
I2C
(
0
,
I2C
.
MASTER
,
baudrate
=
100000
)
print
(
i2c
)
i2c
=
I2C
(
0
,
mode
=
I2C
.
MASTER
,
baudrate
=
400000
)
print
(
i2c
)
i2c
=
I2C
(
0
,
mode
=
I2C
.
MASTER
,
baudrate
=
400000
,
pins
=
i2c_pins
)
print
(
i2c
)
addr
=
i2c
.
scan
()[
0
]
print
(
addr
)
reg
=
bytearray
(
1
)
reg2
=
bytearray
(
2
)
reg2_r
=
bytearray
(
2
)
# reset the sensor
reg
[
0
]
|=
0x80
print
(
1
==
i2c
.
writeto_mem
(
addr
,
107
,
reg
))
pyb
.
delay
(
100
)
# wait for the sensor to reset...
print
(
1
==
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg
))
# read the power management register 1
print
(
0x40
==
reg
[
0
])
# now just read one byte
data
=
i2c
.
readfrom_mem
(
addr
,
117
,
1
)
# read the "who am I?" register
print
(
0x68
==
data
[
0
])
print
(
len
(
data
)
==
1
)
print
(
1
==
i2c
.
readfrom_mem_into
(
addr
,
117
,
reg
))
# read the "who am I?" register again
print
(
0x68
==
reg
[
0
])
# now try reading two bytes
data
=
i2c
.
readfrom_mem
(
addr
,
116
,
2
)
# read the "who am I?" register
print
(
0x68
==
data
[
1
])
print
(
data
==
b'
\x00\x68
'
)
print
(
len
(
data
)
==
2
)
print
(
2
==
i2c
.
readfrom_mem_into
(
addr
,
116
,
reg2
))
# read the "who am I?" register again
print
(
0x68
==
reg2
[
1
])
print
(
reg2
==
b'
\x00\x68
'
)
print
(
1
==
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg
))
# read the power management register 1
print
(
0x40
==
reg
[
0
])
# clear the sleep bit
reg
[
0
]
=
0
print
(
1
==
i2c
.
writeto_mem
(
addr
,
107
,
reg
))
# read it back
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg
)
print
(
0
==
reg
[
0
])
# set the sleep bit
reg
[
0
]
=
0x40
print
(
1
==
i2c
.
writeto_mem
(
addr
,
107
,
reg
))
# read it back
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg
)
print
(
0x40
==
reg
[
0
])
# reset the sensor
reg
[
0
]
|=
0x80
print
(
1
==
i2c
.
writeto_mem
(
addr
,
107
,
reg
))
pyb
.
delay
(
100
)
# wait for the sensor to reset...
# now read and write two register at a time
print
(
2
==
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg2
))
print
(
0x40
==
reg2
[
0
])
print
(
0x00
==
reg2
[
1
])
# clear the sleep bit
reg2
[
0
]
=
0
# set some other bits
reg2
[
1
]
|=
0x03
print
(
2
==
i2c
.
writeto_mem
(
addr
,
107
,
reg2
))
# read it back
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg2_r
)
print
(
reg2
==
reg2_r
)
# reset the sensor
reg
[
0
]
=
0x80
print
(
1
==
i2c
.
writeto_mem
(
addr
,
107
,
reg
))
pyb
.
delay
(
100
)
# wait for the sensor to reset...
# try some raw read and writes
reg
[
0
]
=
117
# register address
print
(
1
==
i2c
.
writeto
(
addr
,
reg
,
stop
=
False
))
# just write the register address
# now read
print
(
1
==
i2c
.
readfrom_into
(
addr
,
reg
))
print
(
reg
[
0
]
==
0x68
)
reg
[
0
]
=
117
# register address
print
(
1
==
i2c
.
writeto
(
addr
,
reg
,
stop
=
False
))
# just write the register address
# now read
print
(
0x68
==
i2c
.
readfrom
(
addr
,
1
)[
0
])
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg2
)
print
(
0x40
==
reg2
[
0
])
print
(
0x00
==
reg2
[
1
])
reg2
[
0
]
=
107
# register address
reg2
[
1
]
=
0
print
(
2
==
i2c
.
writeto
(
addr
,
reg2
,
stop
=
True
))
# write the register address and the data
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg
)
# check it back
print
(
reg
[
0
]
==
0
)
# check for memory leaks...
for
i
in
range
(
0
,
1000
):
i2c
=
I2C
(
0
,
I2C
.
MASTER
,
baudrate
=
100000
)
# test deinit
i2c
=
I2C
(
0
,
I2C
.
MASTER
,
baudrate
=
100000
)
i2c
.
deinit
()
print
(
i2c
)
# next ones should raise
try
:
i2c
.
scan
()
except
Exception
:
print
(
"Exception"
)
try
:
i2c
.
readfrom
(
addr
,
1
)
except
Exception
:
print
(
"Exception"
)
try
:
i2c
.
readfrom_into
(
addr
,
reg
)
except
Exception
:
print
(
"Exception"
)
try
:
i2c
.
readfrom_mem_into
(
addr
,
107
,
reg
)
except
Exception
:
print
(
"Exception"
)
try
:
i2c
.
writeto
(
addr
,
reg
,
stop
=
False
)
except
Exception
:
print
(
"Exception"
)
try
:
i2c
.
writeto_mem
(
addr
,
107
,
reg
)
except
Exception
:
print
(
"Exception"
)
try
:
i2c
.
readfrom_mem
(
addr
,
116
,
2
)
except
Exception
:
print
(
"Exception"
)
# reinitialization must work
i2c
.
init
(
baudrate
=
400000
)
print
(
i2c
)
tests/wipy/i2c.py.exp
0 → 100644
View file @
f352fe82
I2C(0, I2C.MASTER, baudrate=100000)
I2C(0, I2C.MASTER, baudrate=400000)
I2C(0, I2C.MASTER, baudrate=400000)
104
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
True
I2C(0)
Exception
Exception
Exception
Exception
Exception
Exception
Exception
I2C(0, I2C.MASTER, baudrate=400000)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment