123
Fork of LG by
Diff: host/Source/App/SPI.c
- Revision:
- 22:12e6183f04d4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/host/Source/App/SPI.c Wed Feb 03 10:44:42 2016 +0300 @@ -0,0 +1,101 @@ +#include "Global.h" +#include "SPI.h" +#include "stdlib.h" +#include "lpc17xx.h" +#include "InputOutput.h" +#include "MTimer.h" +struct SPI Spi; + unsigned int Temp_AMP=0; + + unsigned int Temp_ADC_2=0; + unsigned int Temp_ADC_3=0; + unsigned int Temp_ADC_4=0; + unsigned int Temp_ADC_5=0; + + + unsigned int Buff_ADC_1 [256]; + unsigned int Buff_ADC_2 [256]; + unsigned int Buff_ADC_3 [256]; + unsigned int Buff_ADC_4 [256]; + unsigned int Buff_ADC_5 [256]; + + unsigned int Buff_AMP [256]; + + unsigned int SinPLC[64]={1023, 1016, 1006, 993, 976, 954, 904, 874, 841, 806, 768, 728, + 687, 645, 601, 557, 500, 379, 337, 296, 256, 219, 183, 150, + 120, 93, 69, 48, 31, 18, 8, 0, 8, 18, 31, 48, + 69, 93, 120, 150, 183, 219, 256, 296, 337, 379, 468, 512, 557, + 601, 645, 687, 728, 768, 806, 841, 874, 904, 954, 976, 993, 1006, + 1016, 1023}; + void DACLInit( void ) +{ + /* setup the related pin to DAC output */ + LPC_PINCON->PINSEL1 = 0x00200000; /* set p0.26 to DAC output */ + return; +} +void SPI_Exchange() +{ + unsigned int Dummy; + + Spi.ADC5 = LPC_SSP0->DR; + Spi.ADC4 = LPC_SSP0->DR; + Spi.ADC3 = LPC_SSP0->DR; + Spi.ADC2 = LPC_SSP0->DR; + Spi.ADC1 = LPC_SSP0->DR; + + Input.ArrayIn[2]= Spi.ADC5; + + LPC_SSP0->DR=0x5555; + LPC_SSP0->DR=0x5555; + LPC_SSP0->DR=0x5555; + + if (CountV31 & 1) //åñëè íå÷åòíûé òàêò òî + { + LPC_SSP0->DR = WRITE_DAC0; //e.êîìàíäà äëÿ ÖÀÏ_0 ïåðåäàâàòü. + LPC_SSP0->DR = (Spi.DAC_A); //e. ïåðåäà÷à 12 áèò + } + else //åñëè òàêò ÷åòíûé. + { + LPC_SSP0->DR = WRITE_DAC1 ; //e.êîìàíäà äëÿ ÖÀÏ_1 ïåðåäàâàòü. + LPC_SSP0->DR = (Spi.DAC_B); //e. ïåðåäà÷à 12 áèò + } + + LPC_DAC->CR = (((SinPLC[CountV64]*35)+21300)); + while (LPC_SSP0->SR & RX_SSP_notEMPT) //åñëè áóôåð SPI íå ïóñò. + Dummy = LPC_SSP0->DR; //î÷èñòèòü áóôåð. + + + Buff_ADC_1 [CountV255] = Spi.ADC1; // àìïë àöï. + Buff_ADC_2 [CountV255] = Spi.ADC2; + Buff_ADC_3 [CountV255] = Spi.ADC3; + Buff_ADC_4 [CountV255] = Spi.ADC4; + Buff_ADC_5 [CountV255] = Spi.ADC5; + + + + Temp_AMP += Buff_ADC_5[CountV255]; + Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // çàïîëíåíèå áóôåðà íàêîïëåíûõ ïðèðàùåíèé çà 8 òàêòîâ + Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); + + Temp_ADC_2 += Buff_ADC_2[CountV255]; + Temp_ADC_2 -= Buff_ADC_2[(CountV255-32) & 0xff]; + + Temp_ADC_3 += Buff_ADC_3[CountV255]; + Temp_ADC_3 -= Buff_ADC_3[(CountV255-32) & 0xff]; + + Temp_ADC_4 += Buff_ADC_4[CountV255]; + Temp_ADC_4 -= Buff_ADC_4[(CountV255-32) & 0xff]; + + Temp_ADC_5 += Buff_ADC_1[CountV255]; + Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; +} +void Init_SPI_Exchange() +{ + ResetCS(ADC); //prepare ADC for sampling + SetDAC(DAC); + LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED +//LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED +//LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED + SetCS(ADC); //start ADC sampling + ResetDAC(DAC); +} \ No newline at end of file