CH552/examples/SPI/MainMaster.C

60 lines
2.4 KiB
C++
Raw Normal View History

2018-10-17 10:44:45 +02:00
/********************************** (C) COPYRIGHT *******************************
* File Name : MainMaster.C
* Author : WCH
* Version : V1.0
* Date : 2017/01/20
* Description : CH554 SPI<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CH376ͨѶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CH376<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CH376ȡ<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><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>ʱ<EFBFBD>ȴ<EFBFBD><C8B4>ڲ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ȶ<EFBFBD>
mInitSTDIO( ); //<2F><><EFBFBD><EFBFBD>0<EFBFBD><30>ʼ<EFBFBD><CABC>
printf("start ...\n");
SPIMasterModeSet(3); //SPI<50><49><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD>ã<EFBFBD>ģʽ3
SPI_CK_SET(2); //2<><32>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// #ifdef SPI0Interrupt
// CH554SPIInterruptInit(); //SPI<50>жϳ<D0B6>ʼ<EFBFBD><CABC>
// EA = 1; //ʹ<><CAB9>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
// #endif
while(1)
{
SCS = 0;
CH554SPIMasterWrite(0x06); //CH554<35><34>CH376ͨѶ<CDA8><D1B6>CH376<37><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
mDelayuS(2); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EEA3AC><EFBFBD>յ<EFBFBD>CH376ȡ<36><C8A1><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
CH554SPIMasterWrite(i);
mDelayuS(2);
ret = CH554SPIMasterRead(); //<2F><><EFBFBD><EFBFBD>CH376<37><36><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
SCS = 1;
if(ret != (i^0xff))
{
printf("Err: %02X %02X \n",(UINT16)i,(UINT16)ret); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
}
mDelaymS(50);
i = i+1;
if((i%40)==0)
{
printf("success %02x\n",(UINT16)i); //ÿ<>ɹ<EFBFBD>40<34>δ<EFBFBD>ӡһ<D3A1><D2BB>
}
}
}