Skip to content

Commit 96630ec

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 96630ec

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

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

Lines changed: 5 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)
@@ -64,11 +66,13 @@ pub start(sdipin, sdopin, sckpin, khz) : result | m, x
6466
m |= ((sck-sdi) & %111) << 24 ' add SCK offset (B pin)
6567
x := %0_00000 | (8-1) ' sample ahead of b pin rise, 8 bits
6668
pinstart(sdi, m, x, 0) ' configure smart pin
69+
m |= cpha << 27 ' set clock phase
6770
pinf(sdi) ' disable until used
6871

6972
if (sdo >= 0)
7073
m := P_OE | P_SYNC_TX ' spi tx mode
7174
m |= ((sck-sdo) & %111) << 24 ' add SCK offset (B pin)
75+
m |= cpha << 27 ' set clock phase
7276
x := %1_00000 | (8-1) ' start/stop mode, 8 bits
7377
pinstart(sdo, m, x, 0) ' configure smart pin
7478
pinf(sdo) ' disable until used
@@ -77,6 +81,7 @@ pub start(sdipin, sdopin, sckpin, khz) : result | m, x
7781
x.word[0] := 2 #> (clkfreq / (khz*1000)) <# $FFFF ' ticks in period
7882
x.word[1] := x.word[0] >> 1 ' ticks in low cycle (50%)
7983
pinstart(sck, m, x, 0) ' configure smart pin
84+
m |= cpol << 14 ' set clock polarity
8085

8186
setup := true
8287

0 commit comments

Comments
 (0)