PV198 – One-chip Controllers, SPI / Dávid Danaj 1 PV198 – One-chip Controllers SPI PV198 – One-chip Controllers, SPI / Dávid Danaj Content 1.What is SPI 2.What is it used for 3.How does it work 4.FRDM-K66F SPI 5.Sensor – BMP 280 6.Application • 2 PV198 – One-chip Controllers, SPI / Dávid Danaj What is SPI §SPI – Serial Peripheral Interface • §Serial interface bus 3 PV198 – One-chip Controllers, SPI / Dávid Danaj What is it used for §Intra-board communication • §External peripherals §Sensors • • • • • 4 How does it work – Scheme PV198 – One-chip Controllers, SPI / Dávid Danaj 5 Figure 1. SPI configuration with master and a slave https://www.analog.com/en/analog-dialogue/articles/introduction-to-spi-interface.html How does it work PV198 – One-chip Controllers, SPI / Dávid Danaj §4 wires (Clock, Chip Select, Master In Slave Out, Master Out Slave In) §Single-master & multi-slave §Chip Select selects slave for communication §Synchronous §Full-duplex §Possibility to use only 3 wires (only 1 data wire) 6 How does it work – Message PV198 – One-chip Controllers, SPI / Dávid Danaj 7 By SPI_timing_diagram.svg: en:User:Cburnettderivative work: Jordsan (talk) - SPI_timing_diagram.svg, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=11405368 FRDM-K66F SPI §3 SPI modules §Master & Slave support §Interrupts §Programmable frame size (4 to 16 bits) §6 peripheral Chip Selects • PV198 – One-chip Controllers, SPI / Dávid Danaj 8 Temperature & Pressure sensor §Bosch BMP280 Digital Pressure Sensor – link §Digital interfaces I²C (up to 3.4 MHz) SPI (3 and 4 wire, up to 10 MHz) §Pressure resolution 0.16 Pa §Temperature resolution 0.01°C • • • PV198 – One-chip Controllers, SPI / Dávid Danaj 9 BMP 280 PV198 – One-chip Controllers, SPI / Dávid Danaj 10 BMP 280 SPI PV198 – One-chip Controllers, SPI / Dávid Danaj 11 BST-BMP280-DS001-11 BMP 280 SPI – Write PV198 – One-chip Controllers, SPI / Dávid Danaj 12 BMP 280 SPI – Read PV198 – One-chip Controllers, SPI / Dávid Danaj 13 Application §Create an application that reads temperature from BMP280 sensor §Print temperature into console PV198 – One-chip Controllers, SPI / Dávid Danaj 14 Accelerometer & Magnetometer PV198 – One-chip Controllers, SPI / Dávid Danaj GND VCC SCL SDA CSB Temp & Pressure Sensor BMP 280 SDO 15 Application – Step-by-step guide 1.Study BMP280 Datasheet 2.Study Serial Peripheral Interface (SPI) chapter in MCU Reference manual 3.Setup pin routing 4.Setup DSPI peripheral driver (speed, timing, etc.) 5.Download BMP280_driver and temperature example 6.Import driver to the project, use example code 7.Implement HW specific functions – your main task 8.Repeat steps 1-7 if necessary PV198 – One-chip Controllers, SPI / Dávid Danaj 16 Application – Template 1.Study BMP280 Datasheet 2.Study Serial Peripheral Interface (SPI) chapter in MCU Reference manual 3.Setup pin routing 4.Setup DSPI peripheral driver (speed, timing, etc.) 5.Download BMP280_driver and temperature example 6.Import driver to the project, use example code 7.Implement HW specific functions – your main task 8.Repeat steps 1, 2 and 7 if necessary PV198 – One-chip Controllers, SPI / Dávid Danaj Checkmark Checkmark Checkmark Checkmark 17 Application – Template PV198 – One-chip Controllers, SPI / Dávid Danaj §Check pin routing §Check DSPI configuration §Check timing §Check sensor.c/.h files 18 Application – Traps PV198 – One-chip Controllers, SPI / Dávid Danaj §There are multiple traps in the template, here are hints: lMake sure you do proper error checking for input data (And check that it works) lYou have to enable continuous chip select for the Transfer call 19 Homework §Update the application to print pressure as well as temperature §Make sure to print the uncompressed pressure (don’t change it) PV198 – One-chip Controllers, SPI / Dávid Danaj 20