Presentation is loading. Please wait.

Presentation is loading. Please wait.

Serial Peripheral Interface

Similar presentations


Presentation on theme: "Serial Peripheral Interface"— Presentation transcript:

1 Serial Peripheral Interface
5/23/2015 Richard Kuo Assistant Professor

2 OutLine Serial Peripheral Interface Introduction
10.NuMicro_SPI.ppt Exercise: use SPI read/write SPI Flash (SPI_Flash) Exercise: use SPI & PDMA access SPI Flash (SPI2_Flash) Exercise : use SPI interface with RF2.4GHz (SPI_RF24L01) Exercise : use SPI interface with RFID (SPI_RFID-RC522) nRF24L01 RC522 RFID Reader

3 SPI Pins used on Nu-LB-NUC140 board
SPI signals SPI0 SPI1 SPI2 SPI3 CS GPC0 GPC8 GPD0 GPD8 CLK GPC1 GPC9 GPD1 GPD9 DI0 (MISO) GPC2 GPC10 GPD2 GPD10 DO0 (MOSI) GPC3 GPC11 GPD3 GPD11 DI1 GPC4 GPC12 GPD4 GPD12 DO1 GPC5 GPC13 GPD5 GPD13 Nu-LB-NUC140 On-Board I2S Codec (WAU8822) SD/MMC EEPROM (W25Q16CV) LCD 128x64

4 SPI (Serial Peripheral Interface)
master slave SPI signals MOSI : master out slave in MISO : master in slave out SCK : serial clock CSB : chip select (low-active)

5 SPI Write Cycle

6 SPI Read Cycle

7 SPI Controller Features
Up to four SPI controllers Each SPI controller can drive up to two slave devices in master mode Support master/slave mode operation Support 1-channel or 2-channel serial data IN/OUT Configurable data length Provide burst mode operation MSB or LSB first Support Word- and Byte-Suspend function Support DMA-transmitting and DMA-receiving Support SPI mode 0 ~ mode 4

8 SPI Feature Summary The maximum SPI clock frequency is 20MHz in master mode, 10MHz in slave mode Drive up to eight SPI slave devices in master mode Configurable clock polarity and transfer timing Support two-channel I/O transfer Automatic slave select

9 SPI block diagram 1-channel I/O 2-channel I/O

10 One-Channel Master Mode System Diagram
2 Slave Select Prevent from bus conflict

11 One-Channel Slave Mode System Diagram
SPI Clock Slave Select

12 Two-Channel Master Mode System Diagram

13 SPI Flash – W25X16

14 W25X16 Manufacture ID & Device ID
Reference : Winbond W25X16 datasheet

15 W25X16 Erase & Program Instructions
Reference : Winbond W25X16 datasheet

16 W25X16 Read Instructions Reference : Winbond W25X16 datasheet

17 SPI_Open & SPI_EnableAutoSS
uint32_t SPI_Open(SPI_T *spi, uint32_t u32MasterSlave, uint32_t u32SPIMode, uint32_t u32DataWidth, uint32_t u32BusClock) Ex. SPI_Open(SPI1, SPI_MASTER, SPI_MODE_0, 32, ); void SPI_EnableAutoSS(SPI_T *spi, uint32_t u32SSPinMask, uint32_t u32ActiveLevel) Ex. SPI_EnableAutoSS(SPI1, SPI_SS0, SPI_SS_ACTIVE_LOW);

18 SPI_Init void SPI_Init(void) { // set SPI0, mode 0, 32bit, 20MHz, enable AutoSS (active-low) SPI_Open(SPI0, SPI_MASTER, SPI_MODE_0, 32, SPI0_CLOCK_FREQUENCY); SPI_EnableAutoSS(SPI0, SPI_SS0, SPI_SS0_ACTIVE_LOW); SPI_DISABLE_2BIT_MODE(SPI0); SPI_DisableInt(SPI0, SPI_IE_MASK); NVIC_DisableIRQ(SPI0_IRQn); }

19 SPI_Init TX : SPI Write SPI_WRITE_TX0(SPI0, SrcData[i]);
SPI_TRIGGER(SPI0); while(SPI_IS_BUSY(SPI0)); RX : SPI Read DestData[i] = SPI_READ_RX0(SPI0);

20 nRF24L01 - RF 2.4GHz module

21 nRF24L01 schematic

22 nRF24L01 block diagram

23 nRF24L01 Star Network 6 data pipes

24 SPI_NRF24L01

25 SPI_NRF24L01 int main(void) { uint8_t temp; char Text[16] = " "; char Data[PAYLOAD] = "Hello"; uint8_t Tx_address[5] = {0x34, 0x43, 0x10, 0x10, 0x01}; uint8_t Rx_address[5] = {0x34, 0x43, 0x10, 0x10, 0x01}; SYS_Init(); nRF_Init(); nRF_config(2, PAYLOAD); // channel #, payload nRF_setTADDR(Tx_address); nRF_setRADDR(Rx_address); init_LCD(); //call initial pannel function clear_LCD(); print_Line(0,"SPI_NRF24L01"); #if TRANSMITTER print_Line(1,"Transmitting..."); #else print_Line(1,"Receiving..."); #endif while(1) { #if TRANSMITTER print_Line(2,Data); nRF_send(Data); sprintf(Text,"%d",TransferCount); print_Line(3,Text); TransferCount++; CLK_SysTickDelay(50000); #else nRF24_getData(Data); print_Line(2, Data); sprintf(TEXT,"%d",TransferCount); print_Line(3, TEXT); } #endif

26 RC522 RFID Card Reader NSS SCK MOSI MISO IRQ GND NRST 3.3V

27 SPI_RFID-RC522

28 Reading RFID Tag

29 SPI_QC12864B NU-LB-NUC140 + QC12864B NuTiny-SDK-NUC140 + QC12864B
QC12864B is a LCD 128x64, its interface is SPI.

30 QC12864B.c LCD 128x64 : font = 8x16 (X * Y)
Line = 64 / 16 = 4 lines Char array = 128 / 8 = 16 for each line // LCD QC12864B module // pin 1 : Vss to Gnd // pin 2 : Vcc to Vcc+5V // pin 3 : 0V to N.C. // pin 4 : CS to NUC140 SPI1_CS (GPC8 /pin61) // pin 5 : SID to NUC140 SPI1_DO0 (GPC11/pin58) // pin 6 : SCLK to NUC140 SPI1_CLK (GPC9 /pin60) // pin 7~14: N.C. // pin 15: PSB to Gnd (0=Serial-port mode, 1=Parallel-port mode) // pin 16: N.C. // pin 17: RST to Vcc // pin 18: N.C. // pin 19: LED_A to +5V (Backlight Anode) // pin 20: LED_K to Gnd (Backlight Cathode)

31 Important Notice ! This educational material are neither intended nor warranted for usage in systems or equipment, any malfunction or failure of which may cause loss of human life, bodily injury or severe property damage. Such applications are deemed, “Insecure Usage”. Insecure usage includes, but is not limited to: equipment for surgical implementation, atomic energy control instruments, airplane or spaceship instruments, the control or operation of dynamic, brake or safety systems designed for vehicular use, traffic signal instruments, all types of safety devices, and other applications intended to support or sustain life. All Insecure Usage shall be made at user’s own risk, and in the event that third parties lay claims to the author as a result of customer’s Insecure Usage, the user shall indemnify the damages and liabilities thus incurred by using this material. Please note that all lecture and sample codes are subject to change without notice. All the trademarks of products and companies mentioned in this material belong to their respective owners.


Download ppt "Serial Peripheral Interface"

Similar presentations


Ads by Google