📄 spi.c
字号:
//*****************************************************************
//
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -