Spi Code

  • Uploaded by: Ankit Daftery
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Spi Code as PDF for free.

More details

  • Words: 186
  • Pages: 2
unsigned unsigned unsigned unsigned

char char char char

rcvd[5]; send[]={1,2,3,4,5}; count=0; junk;

void spi_init(void) { SPCR=0xf2; SPSR=0x01;

// SPE, DORD, MSTR, CPOL, SPR1 Set // SPI2x Set

}

<----------------------------------- Polling example ----------------------------------------------------------> void runspi(void) { int i; for (i=0; i<5;i++) // Send out 5 bytes of data by loading it on the SPDR { // Note that the STC interrupt will execute on transmission complete, PORTC=send[i]; // thus we need not worry about losing incoming data while(SPI_BSY); // Do nothing till the SPI section is busy junk = SPSR; // Necessary to read SPSR to clear SPIF after transmission and then rcvd[i]=SPDR; // read the SPI Data register. Both of these must be executed and in this order. } }

<----------------------------------- Interrupt example ----------------------------------------------------------> ISR(SPI_STC_vect) { rcvd[count] = SPDR; interrupt is executed count++; } void runspi(void) { int i; for (i=0; i<5;i++) on the SPDR { execute on transmission complete, PORTC=send[i];

// SPIF cleared automatically when the

// Send out 5 bytes of data by loading it // Note that the STC interrupt will // thus we need not worry about losing

incoming data } }

Related Documents

Spi Code
May 2020 8
Spi
June 2020 37
Spi
May 2020 36
Spi
August 2019 48
Spi
November 2019 43
Spi, Spi, Mlada Sneha
July 2020 27

More Documents from ""