spi.c

来自「Procyon方案(手工制作的MP3播放器电路及资料)」· C语言 代码 · 共 48 行

C
48
字号

//*****************************************************************
//
// File Name	: 'spi.c'
// Title			: SPI driver
// Author		: Pascal Stang
// Date			: 11/22/2000
// Version		: 0.1
// Target MCU	: ATmega103
// Editor Tabs	: 3
//
//*****************************************************************

#include "io.h"
#include <signal.h>
#include <interrupt.h>

#include "systimer.h"
#include "spi.h"


void spiInit()
{
	// setup SPI I/O pins
	sbi(PORTB, 7);	// set SCK hi
	sbi(DDRB, 7);	// set SCK as output

	sbi(DDRB, 5);	// set MOSI as output
	sbi(DDRB, 4);	// SS must be output for Master mode to work
	
	// setup SPI interface :
	// clock = f/4
	// select clock phase negative going in middle of data
	// master mode
	// enable SPI
	outp((1<<CPHA)|(1<<MSTR)|(1<<SPE), SPCR );
	//outp((1<<CPHA)|(1<<MSTR)|(1<<SPE)|(1<<SPR0), SPCR );
	
	inp(SPSR);	// clear status
}

void spiSendByte(u08 byte)
{
	// this function is provided as a courtesy
	// should probably place the line below into any routines
	// that want to use SPI
	outp(byte, SPDR);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?