CH552/project/examples/SPI/MainSlave.C

57 lines
2.3 KiB
C++
Raw Normal View History

2018-10-17 10:44:45 +02:00
/********************************** (C) COPYRIGHT *******************************
* File Name : MainSlave.C
* Author : WCH
* Version : V1.0
* Date : 2017/01/20
* Description : CH554 SPI<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SPI<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>շ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>
Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͸<EFBFBD><EFBFBD>
*******************************************************************************/
#include "..\Public\CH554.H"
#include "..\Public\Debug.H"
#include "SPI.H"
#include "stdio.h"
#include "string.h"
/*Ӳ<><D3B2><EFBFBD>ӿڶ<D3BF><DAB6><EFBFBD>*/
/******************************************************************************
ʹ<EFBFBD><EFBFBD>CH554 Ӳ<EFBFBD><EFBFBD>SPI<EFBFBD>ӿ<EFBFBD>
CH554 DIR
P1.4 <==> SCS
P1.5 <==> MOSI
P1.6 <==> MISO
P1.7 <==> SCK
*******************************************************************************/
void main()
{
UINT8 ret,i=0;
CfgFsys( );
mDelaymS(5); //<2F>޸<EFBFBD>ϵͳ<CFB5><CDB3>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʱ<EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>Ƶ<EFBFBD>ȶ<EFBFBD>
mInitSTDIO( ); //<2F><><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC>
printf("start ...\n");
SPISlvModeSet( ); //SPI<50>ӻ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
// #if SPI0Interrupt
// CH554SPIInterruptInit(); //SPI<50>жϳ<D0B6>ʼ<EFBFBD><CABC>
// EA = 1; //ʹ<><CAB9>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
// #endif
while(1)
{
CH554SPISlvWrite(i); //SPI<50>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>
mDelayuS(2);
ret = CH554SPISlvRead(); //<2F><>ȡSPI<50><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(ret != (i^0xff))
{
printf("Err: %02X %02X \n",(UINT16)i,(UINT16)ret); //<2F><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>󣬴<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
mDelaymS(10);
i = i+1;
if((i%40)==0) //ÿ<>ɹ<EFBFBD>40<34>δ<EFBFBD>ӡһ<D3A1><D2BB>
{
printf("success %02x\n",(UINT16)i);
}
}
}