Example 13 the serial peripheral interface spi
Download
1 / 17

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


  • 128 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Example 13 The Serial Peripheral Interface (SPI)' - locke


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

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

}

}

}