918af4f3ac
* change simulator svg * change radio image * Remove google fonts cdn * change color of 'advanced' button * font fix * font fix 2 * display fix * change fullsceen simulator bg * Continuous servo * handle continuous state * adding shims * update rendering for continuous servos * fixing sim * fix sig * typo * fix sim * bump pxt * bump pxt * rerun travis * Input blocks revision - add Button and Pin event types - merge onPinPressed & onPinReleased in new onPinEvent function - create new onButtonEvent function * update input blocks in docs and tests * remove device_pin_release block * Hide DAL.x behind Enum * bring back deprecated blocks, but hide them * shims and locales files * fix input.input. typing * remove buildpr * bump V3 * update simulator aspect ratio * add Loudness Block * revoke loudness block * Adds soundLevel To be replaced by pxt-common-packages when DAL is updated. * Remove P0 & P3 from AnalogPin Co-authored-by: Juri <gitkraken@juriwolf.de>
1.5 KiB
1.5 KiB
spi Frequency
Set the Serial Peripheral Interface (SPI) clock frequency.
pins.spiFrequency(1000000);
The @boardname@ sets the rate of data transfer and control timing for a SPI connection. This data rate and timing signal is controlled by the SCK pin. The signal on this pin is clocked using the frequency set for it.
~ hint
Simulator: This function needs real hardware to work with. It's not supported in the simulator.
~
The default clock frequency is 1 Mhz (10000000 Hz). You can set the frequency for the SPI connection to some other value if you need a different data rate.
Parameters
- frequency: a number to set as the frequency for SPI bus clock. This value is the number of clock changes per second (Hz).
Example
Read the value of the WHOAMI register from the device connected to the SPI bus. The chip select line is connected to pin 0 and the SPI signals use pins P13, P14, and P15.
pins.digitalWritePin(DigitalPin.P0, 1);
pins.spiPins(DigitalPin.C15, DigitalPin.C14, DigitalPin.C13);
pins.spiFormat(8, 3);
pins.spiFrequency(1000000);
pins.digitalWritePin(DigitalPin.P0, 0);
let command = pins.spiWrite(143);
let whoami = pins.spiWrite(0);
pins.digitalWritePin(DigitalPin.P0, 1);
basic.showNumber(whoami);
serial.writeLine("WHOAMI register value: " + whoami)