Spread the love

SPI Protocol of ARM7

___________________________________________________________________________________________________

 


What is SPI protocol ? 

 The Serial Peripheral Interface or SPI bus is a synchronous serial data link, a de facto standard, named by Motorola, that operates in full duplex mode. It is used for short distance, single master communication

 SPI Protocol of ARM7

How SPI work 

 Firstly, SPI works in a master/slave setup. The master is the one that sends the clock pulses. At each pulse, data will be sent and received. SPI has a chip select pin. Every device will share the “SDI”, “SDO” and “Clock” pins, but each device will have it’s own chip select pin (also known as slave select). This means we can have a virtually unlimited number of devices on the same SPI bus. You should also note that the chip select pin can be active high or active low depending on the device. For some devices, the chip select pin must stay enabled throughout the transmission, and others require a change in the chip select line before the next transmission. SPI is Dual-Duplex. This means data can be sent and received at the same time. If you wish to send data and not receive any, the PIC will receive data anyways. You may ignore the return byte. Here’s a diagram showing the way in which SPI sends & receives data:

 SPI_timing_diagram2

  Feature of  SPI 

  • Full duplex communication.
  • Higher throughput than TWI.
  • Not limited to 8 bit words in the case of bit transferring.
  • Simple hardware interfacing
  • Arbitrary choice of message sizes, contents and purpose.
  • Typically low power requirements
  • Slave uses master’s clock and does not require precision oscillators.
  • Lower power requirements than TWI due to less circuitry.
  • Many SPI-enabled ICs and Microcontrollers can cope with data rates of over 10MHz, so transfer is much faster than with I2C

5842593614_09836c871f

Applications  

SPI is used to talk to a variety of peripherals, such as

  • Sensors: temperature, pressure, ADC, touchscreens, video game controllers
  • Control devices: audio codecs, digital potentiometers, DAC
  • Camera lenses: Canon EF lens mount
  • Communications: Ethernet, USB, USART, CAN, IEEE 802.15.4, IEEE 802.11, handheld video games
  • Memory: flash and EEPROM
  • Real-time clocks
  • LCD, sometimes even for managing image data
  • Any MMC or SD card (including SDIO variant)

Click Here: Depth understanding of SPI Protocol

 1. Circuit of SPI protocol of ARM7 ( LPC2148 ) with MAX7221 ic

 Circuit of SPI protocol of ARM7 ( LPC2148 ) with MAX7221 ic

________________________________________________________________________________________________

1.  Program of  SPI protocol of ARM7 ( LPC2148 ) with MAX7221 ic

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- Program Of Multiplex 8 Seven Segment Using
Max7221 And Controlled With ARM(LPC21XX) Using SPI Protocol
******************************************************/

#include<lpc21xx.h>

unsigned char spi_rec;

void spi_ini();
void spi_tr1(unsigned int x);
char spi_re();
void spi_tr(unsigned char cmd,unsigned char data);
void spi_str(unsigned char *str);

int ar[10]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f };
int ar1[8]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};

void pll();

void delay_ms(unsigned int x);

int main()
   {
			int i,a,b,c,d,e,f,g,h;
			a=b=c=d=e=f=g=h=0;
			PINSEL0=0X00000000;
			IO0DIR=0XFFFFFFFF;
			pll();
			spi_ini();
			spi_tr(0x0a,0xf);
			spi_tr(0x0b,0xf);   
			for(i=0;i<9;i++)
	      {
	          spi_tr(ar1[i],ar[0]);
	          delay_ms(100);
	      }
	   spi_tr(0x0c,0x01);
	   while(1)
	     {
		       spi_tr(ar1[7],ar[a]);
		       spi_tr(ar1[6],ar[b]);
		       spi_tr(ar1[5],ar[c]);
		       spi_tr(ar1[4],ar[d]);
		       spi_tr(ar1[3],ar[e]);
		       spi_tr(ar1[2],ar[f]);
		       spi_tr(ar1[1],ar[g]);
		       spi_tr(ar1[0],ar[h]);
		       a++;

           if(a==10)
		        {
		           a=0;
			         b++;
		        }
		       if(b==10)
		        {
		           a=b=0;
			         c++;
		        }
		      if(c==10)
		        {
		           a=b=c=0;
			         d++;
		        }
		      if(d==10)
		        {
		           a=b=c=d=0;
			         e++;
		        }
		      if(e==10)
		        {
		            a=b=c=d=e=0;
			          f++;
		        }
		      if(f==10)
		        {
		             a=b=c=d=e=f=0;
                 g++;
		        }
		      if(g==10)
		        {
		             a=b=c=d=e=f=g=0;
			           h++;
		        }
		      if(h==10)
		        {
		            a=b=c=d=e=f=g=h=0;
		        }
		     delay_ms(3000);	 
	    }
  }

void pll()
  { 
			/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
			PLLCFG=0X24;		 // SET PSEL=2 AND MSEL=5
			PLLCON=0X01;		 //PLL IS ACTIVE BUT NOT YET CONNECT
			PLLFEED=0XAA;		 //FEED SEQUENCE
			PLLFEED=0X55;		 //FEED SEQUENCE
			while((PLLSTAT & 0X400)==0);   //WAIT FOR FEED SEQUENCE TO BE INSERTED
			PLLCON=0X03;		// PLL HAS BEEN ACTIVE AND BEING CONNECTRD
			VPBDIV=0X00;		 // SET PCLK SAME AS FCCLK
			PLLFEED=0XAA;		//FEED SEQUENCE
			PLLFEED=0X55;		//FEED SEQUENCE
  }

void spi_ini()
  {
		 PINSEL0 |=0x1500;          /* P0.4, P0.5, P0.6, P0.7 are set as SCK, MISO, MOSI and GPIO */
		 //IODIR0 |= 0X80; 				  /* SSEL is output */
		 //IOSET0 |=0X80; 				  /* set SSEL to high */
		 S0SPCCR=8;						      /* SPI clock prescale register minimum value is 8. */
		 S0SPCR=0x0030;					    /* Device select as master, Set data to 8-bit, CPOL = 0, CPHA = 0*/ 
  }

void spi_tr1(unsigned int x)
  {
     S0SPDR =x;
     while ( !(S0SPSR & 0x80) );	/* Wait until the SPIF bit is set to indicate trabsfer complete */
  }

char spi_re()
  {
	    while ( !(S0SPSR & 0x80) );	/* Wait until the SPIF bit is set to indicate trabsfer complete */
      spi_rec= S0SPDR;
      return spi_rec;
  }

void spi_str(unsigned char *str)
  {
     while(*str!='\0')
      {
        spi_tr1(*str);
        str++;
      }
  }
	
void spi_tr(unsigned char cmd,unsigned char data)
	{
		IO0CLR=(1<<7);  //enable transmission
		spi_tr1(cmd);
		spi_tr1(data);
		IO0SET=(1<<7);   // disable transmission

	}
	
void delay_ms(unsigned int x)
	{
		int i;
		while(x--)
		 {
			  for(i=0;i<100;i++);
		 }
	}

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1)

Content for the tab VIDEO