📄 main.c
字号:
#include <stdio.h>
#include <cdefBF535.h>
#include <signal.h>
void spi_isr(int i);
short int SPI_RD_VALUE;
short int SPI_RD_VALUE_TEMP;
int delay;
void main(void)
{
//Clear the SPI0 registers
*pSPI0_FLG = 0;
*pSPI0_BAUD = 0;
*pSPI0_CTL = 0;
//set up interrupt mask for SPI0 interrupt.spi_isr is the interrupt handler
interrupt(SIGIVG9, spi_isr);
*pSIC_IMASK = SIC_MASK8;//SIC_MASK_ALL;
*pSPI0_FLG = FLS1 | FLG1;//PF2 becomes CS# for AD7276
*pSPI0_CTL = SIZE | CPOL | MSTR | SPE | SZ | CPHA;
//For TIMOD1 condition, modified the defBF535.h file
*pSPI0_BAUD = 6;//This value will decide the serial bit clock for AD7276
//Dummy read has be done in order to initiate the read hence SCK0 and PF2
*pSPI0_FLG = FLS1;
SPI_RD_VALUE = *pSPI0_RDBR;
while(1)
{
//wait for SPI receive interrupt and read the data in the receive interrupt
}
}
void spi_isr(int i)
{
*pSPI0_FLG = FLS1 | FLG1;
for(delay=0; delay<=50; delay++)
{
asm("nop;");
}
*pSPI0_FLG = FLS1;
SPI_RD_VALUE_TEMP = *pSPI0_RDBR;//read receive buffer
SPI_RD_VALUE = SPI_RD_VALUE_TEMP >> 3;//First two bits are zero hence right shift to get 12-bit ADC data
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -