📄 spi_test.c
字号:
/*********************************************************************************************
* File: spi_test.c
* Author: embest
* Desc: spi test file
* History:
* H.T.Zhang, Programming modify, September 14, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "lcd.h"
#include "demo.h"
/*------------------------------------------------------------------------------------------*/
/* external varibles and functions */
/*------------------------------------------------------------------------------------------*/
void spi0_int(void); //__attribute__((interrupt("IRQ")));
void spi1_int(void); //__attribute__((interrupt("IRQ")));
extern void isrSPI0(void);
extern void isrSPI1(void);
INT32T ucSpiBaud=200000;
UINT8T *cTxData="S3C2410SPI COMMUNICATION TEST!";
UINT8T cRxData[256];
UINT8T cRxNo,cTxEnd;
/*********************************************************************************************
* name: spi_test
* func: spi_test function
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void spi_test(void)
{
uart_printf("\n SPI Communication Test Example\n");
uart_printf(" The words that SPI0 transmit are:\n");
uart_printf(" %s\n",cTxData);
print_lcd(30,40,BLUE,"SPI Communication Test Example");
print_lcd(30,60,BLUE,"The words that SPI0 transmit are:");
print_lcd(30,80,RED,cTxData);
pISR_SPI0=(int)isrSPI0;
pISR_SPI1=(int)isrSPI1;
//clear interrupt pending
ClearPending(BIT_SPI0);
ClearPending(BIT_SPI1);
//IO port configuration
rGPECON &= 0xF0000000|(2<<26)|(2<<24)|(2<<22); //SPI1 configued slave
rGPGCON = (3<<14)|(3<<12)|(3<<10)|(3<<6)|(1<<4); //nSS0 bit is output
rGPGUP &=0xFF13;
rGPEUP &=0xC7FF;
rSPPRE0=PCLK/2/ucSpiBaud-1;
rSPCON0=(1<<5)|(1<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0); //interrupt mode,enable ENSCK,master,CPOL=0,CPHA=0,normal mode
rSPPRE1=PCLK/2/ucSpiBaud-1;
rSPCON1=(1<<5)|(1<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0); //interrupt mode,enable ENSCK,slave,CPOL=0,CPHA=0,normal mode
rSPPIN0=(0<<2)|(1<<1)|(0<<0); //dis-ENMUL,SBO,release
rGPGDAT &=0xFFFB; //nSS0=0
rINTMOD &= ~(BIT_SPI0 | BIT_SPI1);
rINTMSK &= ~(BIT_SPI0 | BIT_SPI1);
while(!(rSPSTA0 & rSPSTA1 & 0x1));
cTxEnd=0;
rSPTDAT0=*cTxData++;
uart_printf(" end.\n");
print_lcd(30,180,RED,"**********END**********");
rINTMSK |= (BIT_SPI0 | BIT_SPI1);
}
/*********************************************************************************************
* name: spi0_int
* func: spi0 inerrupt service routine
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void spi0_int(void)
{
ClearPending(BIT_SPI0);
while(!(rSPSTA0&0x01));
if((*cTxData)!='\0')
rSPTDAT0=*cTxData++;
else if(cTxEnd==0)
{
cTxEnd=1;
rSPTDAT0='\0';
uart_printf("\n .......................Tx OK\n");
print_lcd(30,100,RED,".......................Tx OK");
}
if(cTxEnd==1)
rINTMSK |= BIT_SPI0;
}
/*********************************************************************************************
* name: spi1_int
* func: spi1 interrupt service routine
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void spi1_int(void)
{
ClearPending(BIT_SPI1);
while(!(rSPSTA1&0x1));
cRxData[cRxNo++]=rSPRDAT1;
if((cRxNo>0)&&(cRxData[cRxNo-1])=='\0')
{
rINTMSK |= BIT_SPI1;
uart_printf(" .......................Rx OK\n\n");
uart_printf(" The words that SPI1 receive are:\n");
uart_printf(" %s",cRxData);
print_lcd(30,120,BLUE,".......................Rx OK");
print_lcd(30,140,BLUE,"The words that SPI1 receive are:");
print_lcd(30,160,RED,cRxData);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -