Hardware Reference
In-Depth Information
Example 8-6. Code for copying P8_16 to P9_31 using the PRU (pruSpeak.py)
#!/usr/bin/env python
from pru_speak import pru_speak
# Copy the signal on pin P8_16 to P9_31
code
=
'''
\
SCRIPT
SET var1
,
DIO
[
14
]
SET DIO
[
0
],
var1
GOTO
0
ENDSCRIPT
RUN
'''
halt
=
'''
\
HALT
'''
ret
=
pru_speak
.
execute_instruction
(
code
)
print ret
Then run the code by using the following command:
bone#
./pruSpeak.py
Generating LALR tables
Initializing PRU Speak
0 0x110000FF SET var1, DIO[14]
1 0x01400000 SET DIO[0], var1
2 0x15000000 GOTO 0
3 0x7F000000 ENDSCRIPT
[285212927, 20971520, 352321536, 2130706432]
[]
PRU Speak object deleted
The code will return immediately, but the PRU will continue to run.
The PRU has quick access to only a subset of GPIO pins. This example reads GPIO
P8_16
and writes to
P9_31
, so you have to wire up the pushbutton and LED as shown
in
Figure 8-4
.