1 / 17

Example 13 The Serial Peripheral Interface (SPI)

Example 13 The Serial Peripheral Interface (SPI). Lecture L9.1. PIM_9DP256 Block Diagram. 3 SPI Ports. SPI2 Pins PP4 – PP7. Pins 112,111,110,109. SPI1 Pins PP0 – PP3. Pins 4,3,2,1. SPI0 Pins PS4 – PS7. Pins 93,94,95,96. SPI2 Pins PP4 – PP7. Pins 112,111,110,109. SPI1 Pins

locke
Download Presentation

Example 13 The Serial Peripheral Interface (SPI)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Example 13 The Serial Peripheral Interface (SPI) Lecture L9.1

  2. PIM_9DP256 Block Diagram 3 SPI Ports

  3. SPI2 Pins PP4 – PP7 Pins 112,111,110,109 SPI1 Pins PP0 – PP3 Pins 4,3,2,1 SPI0 Pins PS4 – PS7 Pins 93,94,95,96

  4. SPI2 Pins PP4 – PP7 Pins 112,111,110,109 SPI1 Pins PP0 – PP3 Pins 4,3,2,1 SPI0 Pins PS4 – PS7 Pins 93,94,95,96

  5. Two SPI modules connected in a master-slave configuration

  6. $D8

  7. Connecting a 16 x 1 hex keypad to two 74165 shift registers

  8. int read_16shift(void){ int data; char c; SS0_LO(); // latch data SS0_HI(); c = send_SPI0(0); // get 1st byte by sending dummy data data = c; data = data << 8; c = send_SPI0(0); // get 2nd byte by sending dummy data data = data | c; return data; }

  9. char get_key(){ const char keytbl[] = { 0x3, 0x2, 0x1, 0x0, 0x8, 0x9, 0xA, 0xB, 0x7, 0x6, 0x5, 0x4, 0xC, 0xD, 0xE, 0xF }; int mask; int data; int i; char found; char key; data = read_16shift(); mask = 0x8000; found = 0; i = 0; key = 16; // not found if key = 16 while((i < 16) && (found == 0)){ if((data & mask) == 0){ found = 1; key = keytbl[i]; } else { mask >>= 1; i++; } } return key; }

  10. // Example 13: SPI Keypad Interfacing with 74165 Shift Registers #include <hidef.h> /* common defines and macros */ #include <mc9s12dp256.h> /* derivative information */ #include "main_asm.h" /* interface to the assembly module */ #pragma LINK_INFO DERIVATIVE "mc9s12dp256b" int read_16shift(void); char get_key(void); void main(void) { char key; PLL_init(); // set system clock frequency to 24 MHz lcd_init(); // enable lcd SPI0_init(); // enable SPI0 set_lcd_addr(0x40); while(1) { key = get_key(); if(key < 16){ key = hex2asc(key); // convert to ascii data8(key); // display on lcd } } }

More Related