SPI( rx, tx, clk[, data[, speed[, mode[, bits]]]] )
Sends and receives a byte using the SPI protocol with MMBasic as the master (ie, it generates the clock).
‘rx’ is the pin number for the data input (MISO)
‘tx’ is the pin number for the data output (MOSI)
‘clk’ is the pin number for the clock generated by MMBasic (CLK)
‘data’ is optional and is an integer representing the data byte to send over the data output pin. If it is not specified the ‘tx’ pin will be held low.
‘speed’ is optional and is the speed of the clock. It is a single letter either H, M or L where H is 500KHz, M is 50KHz and L is 5KHz. Default is H.
‘mode’ is optional and is a single numeric digit representing the transmission mode. The default mode is 3.
‘bits’ is optional and represents the number of bits to send/receive. Range is 1 to 23 (this limit is defined by how many bits can be stored in a floating point number). The default is 8.
Mode CPOL CPHA Description
Mode: 0 (Clock polarity: 0 Clock phase: 0) Clock is active high, data is captured on the rising edge and output on the falling edge
Mode: 1 (Clock polarity: 0 Clock phase: 1) Clock is active high, data is captured on the falling edge and output on the rising edge
Mode: 2 (Clock polarity: 1 Clock phase: 0) Clock is active low, data is captured on the falling edge and output on the rising edge
Mode: 3 (Clock polarity: 1 Clock phase: 1) Clock is active low, data is captured on the rising edge and output on the falling edge
See also:
SETPIN
Leave a Reply