Skip to content

Commit 51813d9

Browse files
committed
Add clock phase and polarity argument to smartpin SPI object
Followed Rev 5 06-11-2020 Jon Titus, Page 56 of 63 Verified with logic analyser.
1 parent 1468c8b commit 51813d9

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libraries/community/p2/All/jm_ez_spi/jm_ez_spi.spin2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub null()
4545

4646

4747
pub start(sdipin, sdopin, sckpin, khz) : result | m, x
48+
pub start(sdipin, sdopin, sckpin, khz, cpha) : result | m, x
49+
pub start(sdipin, sdopin, sckpin, khz, cpha, cpol) : result | m, x
4850

4951
'' Configure P2 smart pins for SPI coms
5052
'' -- sdipin is input from external device (-1 if not used)
@@ -69,6 +71,7 @@ pub start(sdipin, sdopin, sckpin, khz) : result | m, x
6971
if (sdo >= 0)
7072
m := P_OE | P_SYNC_TX ' spi tx mode
7173
m |= ((sck-sdo) & %111) << 24 ' add SCK offset (B pin)
74+
m |= cpha << 27 ' set clock phase
7275
x := %1_00000 | (8-1) ' start/stop mode, 8 bits
7376
pinstart(sdo, m, x, 0) ' configure smart pin
7477
pinf(sdo) ' disable until used
@@ -77,6 +80,7 @@ pub start(sdipin, sdopin, sckpin, khz) : result | m, x
7780
x.word[0] := 2 #> (clkfreq / (khz*1000)) <# $FFFF ' ticks in period
7881
x.word[1] := x.word[0] >> 1 ' ticks in low cycle (50%)
7982
pinstart(sck, m, x, 0) ' configure smart pin
83+
m |= cpol << 14 ' set clock polarity
8084

8185
setup := true
8286

0 commit comments

Comments
 (0)