Example 13 the serial peripheral interface spi
This presentation is the property of its rightful owner.
Sponsored Links
1 / 17

Example 13 The Serial Peripheral Interface (SPI) PowerPoint PPT Presentation


  • 90 Views
  • Uploaded on
  • Presentation posted in: General

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

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Example 13 the serial peripheral interface spi

Example 13 The Serial Peripheral Interface (SPI)

Lecture L9.1


Example 13 the serial peripheral interface spi

PIM_9DP256

Block Diagram

3 SPI Ports


Example 13 the serial peripheral interface spi

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


Example 13 the serial peripheral interface spi

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


Example 13 the serial peripheral interface spi

Two SPI modules connected in a master-slave configuration


Example 13 the serial peripheral interface spi

$D8


Example 13 the serial peripheral interface spi

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


Example 13 the serial peripheral interface spi

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;

}


Example 13 the serial peripheral interface spi

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;

}


Example 13 the serial peripheral interface spi

// 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

}

}

}


  • Login