📄 spi_main.c
字号:
/* ======================================================================
* Project: SPI_Example *
* file: SPI_main.c *
* -------------------------------------------------------------------- *
* Description: *
* SPI Communication between 2 boards *
* *
* -------------------------------------------------------------------- *
* Author: Luis Fdo. Reynoso Covarrubias *
* Motorola Mexico FAE Team *
* *
* Last Modification: 18/Dec/02 *
* =====================================================================*/
#define SLAVE_SELECTED //define MASTER_SELECTED if this program is for a Master,
// SLAVE_SELECTED if this is for a slave
#define __DECL__6812DP256_H__
#include <hidef.h>
#include <6812dp256.h>
#ifdef MASTER_SELECTED
void main(void){
unsigned long delay = 0;
PTP=0xFF; // Turn off the Leds
DDRP=0x80; // Set PORTP as output
SPI0CR1=0xDE; /* SPI Interrupts enabled, Transmit Interrupt disabled, SPI enabled, Master Mode, SCK idles hisgh, SCK is issued at the beggining,
SS output, Data is transferred most significant first*/
SPI0CR2=0x10; /*Enable MODF Error, Output Buffer Disabled, SPI normally in Wait, Pin Mode Normal*/
SPI0BR=0x43; // DSPI Module Clock Divisor= 80; BaudRate=8MHz/80=>100KHz
do
{
SPI0DR=0xAA; // Send 1st Data
PTP=0x00;
while (SPIF_0==0) {}; // Wait until sent
for (delay=0;delay<100000;delay++){};
SPI0DR=0x55; // Send 2nd data
PTP=0xFF;
while (SPIF_0==0) {}; // Wait until sent
for (delay=0;delay<100000;delay++){};
}while(1); // Repeat forever
}
#endif
#ifdef SLAVE_SELECTED
void main(void){
PTP=0xFF; // Turn off the Leds
DDRP=0x80; // Set PORTP as output
SPI0CR1=0xCE; /* SPI Interrupts enabled, Transmit Interrupt disabled, SPI enabled, Slave Mode, SCK idles hisgh, SCK is issued at the beggining,
SS output, Data is transferred most significant first*/
SPI0CR2=0x00; /*Enable MODF Error, Output Buffer Disabled, SPI normally in Wait, Pin Mode Normal*/
SPI0BR=0x43; // DSPI Module Clock Divisor= 80; BaudRate=8MHz/80=>100KHz
EnableInterrupts;
do
{}while(1);
}
/*****************SPI_ISR****************************
* SPI Interrupt *
* *
****************************************************/
interrupt 19 void SPI_ISR(void)
{
if (SPIF_0==1)
{
SPI0SR;
if (SPI0DR==0xAA) // 1st Data received
{ PTP=0x00;
}
else if (SPI0DR==0x55) // 2nd Data received (If both received, toggle)
{ PTP=0xFF;
}
}
else
SPI0SR;
} //int 19
#endif
/*
Services performed by MOTOROLA in this matter are performed "AS IS" and without any warranty. CUSTOMER retains the final decision relative to the total design and functionality of the end product . MOTOROLA neither guarantees nor will be held liable by CUSTOMER for the success of this project. MOTOROLA DISCLAIMS ALL WARRANTIES, EXPRESS, IMPLIED OR STATUTORY INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ON ANY HARDWARE, SOFTWARE ORE ADVISE SUPPLIED TO THE PROJECT BY MOTOROLA, AND OR NAY PRODUCT RESULTING FROM MOTOROLA SERVICES . IN NO EVENT SHALL MOTOROLA BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT.
CUSTOMER agrees to hold MOTOROLA harmless against any and all claims demands or actions by anyone on account of any damage, or injury, whether commercial, contractual, or tortuous, rising directly or indirectly as a result of the advise or assistance supplied CUSTOMER in connection with product, services or goods supplied under this Agreement.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -