spi1.c

来自「nRF24L01开发指导」· C语言 代码 · 共 47 行

C
47
字号
/*****************************************************************************
*
* File: spi1.c
* 
* Copyright S. Brennen Ball, 2006-2007
* 
* The author provides no guarantees, warantees, or promises, implied or
*	otherwise.  By using this software you agree to indemnify the author
* 	of any damages incurred by using it.
* 
*****************************************************************************/

#include "spi1.h"
#include "LPC214x.h"

void spi1_open()
{
	SSPCR0 = 0x0007;
	SSPCPSR = 30;
	SSPIMSC = 0;
	SSPCR1 = 0x02;
}

int spi1_read()
{
	if(!(SSPSR & 0x04))
		return -1;
	
	return SSPDR;
}

unsigned char spi1_send_read_byte(unsigned char byte)
{
	int rec_val;
	
	while((SSPSR & 0x02) == 0){}

	SSPDR = byte;
	
	rec_val = spi1_read();
	
	while(rec_val == -1)
		rec_val = spi1_read();
	
	return (unsigned char)rec_val;
}

⌨️ 快捷键说明

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