Skip to content

Commit

Permalink
Start using SPI configuration command
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarop committed Jan 16, 2016
1 parent 85d449d commit cc5e56e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sw/examples/spi_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# Set the CS line as an output
bridge.gpiocfg(CS_PIN, 'output')

# Configure ~1.05MHz clock with CPOL=0,CPHA=0
bridge.spi_cfg(10500000, 0, 0)

# CS is active low in this case
bridge.gpio(CS_PIN, 1)

Expand Down
26 changes: 26 additions & 0 deletions sw/silta/stm32f407.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,32 @@ def spi(self, cspin, wbytes = []):

return rbytes

def spicfg(self, speed, cpol, cpha):
''' SPI Configuration
Arguments:
speed - SPI Speed in Hz
Supported speeds: 42000000, 21000000, 10500000, 5250000,
2625000, 1312500, 656250, 328125
cpol - Clock polarity
cpha - Clock phase
Return Values:
True for success
or
False for failure
'''

cmd = 'spicfg ' + str(speed) + ' ' + str(int(cpol) & 1) + ' ' + str(int(cpha) & 1)
line = self.__send_cmd(cmd)

result = line.strip().split(' ')

if result[0] == 'OK':
return True
else:
return False

# Configure GPIO as input/output/etc
def gpiocfg(self, name, mode='input', pull=None):
''' GPIO Configuration
Expand Down

0 comments on commit cc5e56e

Please sign in to comment.