123
Fork of LG by
host/Source/App/SPI.c@22:12e6183f04d4, 2016-02-03 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Feb 03 10:44:42 2016 +0300
- Revision:
- 22:12e6183f04d4
[thyz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kovalev_D |
22:12e6183f04d4 | 1 | #include "Global.h" |
Kovalev_D |
22:12e6183f04d4 | 2 | #include "SPI.h" |
Kovalev_D |
22:12e6183f04d4 | 3 | #include "stdlib.h" |
Kovalev_D |
22:12e6183f04d4 | 4 | #include "lpc17xx.h" |
Kovalev_D |
22:12e6183f04d4 | 5 | #include "InputOutput.h" |
Kovalev_D |
22:12e6183f04d4 | 6 | #include "MTimer.h" |
Kovalev_D |
22:12e6183f04d4 | 7 | struct SPI Spi; |
Kovalev_D |
22:12e6183f04d4 | 8 | unsigned int Temp_AMP=0; |
Kovalev_D |
22:12e6183f04d4 | 9 | |
Kovalev_D |
22:12e6183f04d4 | 10 | unsigned int Temp_ADC_2=0; |
Kovalev_D |
22:12e6183f04d4 | 11 | unsigned int Temp_ADC_3=0; |
Kovalev_D |
22:12e6183f04d4 | 12 | unsigned int Temp_ADC_4=0; |
Kovalev_D |
22:12e6183f04d4 | 13 | unsigned int Temp_ADC_5=0; |
Kovalev_D |
22:12e6183f04d4 | 14 | |
Kovalev_D |
22:12e6183f04d4 | 15 | |
Kovalev_D |
22:12e6183f04d4 | 16 | unsigned int Buff_ADC_1 [256]; |
Kovalev_D |
22:12e6183f04d4 | 17 | unsigned int Buff_ADC_2 [256]; |
Kovalev_D |
22:12e6183f04d4 | 18 | unsigned int Buff_ADC_3 [256]; |
Kovalev_D |
22:12e6183f04d4 | 19 | unsigned int Buff_ADC_4 [256]; |
Kovalev_D |
22:12e6183f04d4 | 20 | unsigned int Buff_ADC_5 [256]; |
Kovalev_D |
22:12e6183f04d4 | 21 | |
Kovalev_D |
22:12e6183f04d4 | 22 | unsigned int Buff_AMP [256]; |
Kovalev_D |
22:12e6183f04d4 | 23 | |
Kovalev_D |
22:12e6183f04d4 | 24 | unsigned int SinPLC[64]={1023, 1016, 1006, 993, 976, 954, 904, 874, 841, 806, 768, 728, |
Kovalev_D |
22:12e6183f04d4 | 25 | 687, 645, 601, 557, 500, 379, 337, 296, 256, 219, 183, 150, |
Kovalev_D |
22:12e6183f04d4 | 26 | 120, 93, 69, 48, 31, 18, 8, 0, 8, 18, 31, 48, |
Kovalev_D |
22:12e6183f04d4 | 27 | 69, 93, 120, 150, 183, 219, 256, 296, 337, 379, 468, 512, 557, |
Kovalev_D |
22:12e6183f04d4 | 28 | 601, 645, 687, 728, 768, 806, 841, 874, 904, 954, 976, 993, 1006, |
Kovalev_D |
22:12e6183f04d4 | 29 | 1016, 1023}; |
Kovalev_D |
22:12e6183f04d4 | 30 | void DACLInit( void ) |
Kovalev_D |
22:12e6183f04d4 | 31 | { |
Kovalev_D |
22:12e6183f04d4 | 32 | /* setup the related pin to DAC output */ |
Kovalev_D |
22:12e6183f04d4 | 33 | LPC_PINCON->PINSEL1 = 0x00200000; /* set p0.26 to DAC output */ |
Kovalev_D |
22:12e6183f04d4 | 34 | return; |
Kovalev_D |
22:12e6183f04d4 | 35 | } |
Kovalev_D |
22:12e6183f04d4 | 36 | void SPI_Exchange() |
Kovalev_D |
22:12e6183f04d4 | 37 | { |
Kovalev_D |
22:12e6183f04d4 | 38 | unsigned int Dummy; |
Kovalev_D |
22:12e6183f04d4 | 39 | |
Kovalev_D |
22:12e6183f04d4 | 40 | Spi.ADC5 = LPC_SSP0->DR; |
Kovalev_D |
22:12e6183f04d4 | 41 | Spi.ADC4 = LPC_SSP0->DR; |
Kovalev_D |
22:12e6183f04d4 | 42 | Spi.ADC3 = LPC_SSP0->DR; |
Kovalev_D |
22:12e6183f04d4 | 43 | Spi.ADC2 = LPC_SSP0->DR; |
Kovalev_D |
22:12e6183f04d4 | 44 | Spi.ADC1 = LPC_SSP0->DR; |
Kovalev_D |
22:12e6183f04d4 | 45 | |
Kovalev_D |
22:12e6183f04d4 | 46 | Input.ArrayIn[2]= Spi.ADC5; |
Kovalev_D |
22:12e6183f04d4 | 47 | |
Kovalev_D |
22:12e6183f04d4 | 48 | LPC_SSP0->DR=0x5555; |
Kovalev_D |
22:12e6183f04d4 | 49 | LPC_SSP0->DR=0x5555; |
Kovalev_D |
22:12e6183f04d4 | 50 | LPC_SSP0->DR=0x5555; |
Kovalev_D |
22:12e6183f04d4 | 51 | |
Kovalev_D |
22:12e6183f04d4 | 52 | if (CountV31 & 1) //åñëè íå÷åòíûé òàêò òî |
Kovalev_D |
22:12e6183f04d4 | 53 | { |
Kovalev_D |
22:12e6183f04d4 | 54 | LPC_SSP0->DR = WRITE_DAC0; //e.êîìàíäà äëÿ ÖÀÏ_0 ïåðåäàâàòü. |
Kovalev_D |
22:12e6183f04d4 | 55 | LPC_SSP0->DR = (Spi.DAC_A); //e. ïåðåäà÷à 12 áèò |
Kovalev_D |
22:12e6183f04d4 | 56 | } |
Kovalev_D |
22:12e6183f04d4 | 57 | else //åñëè òàêò ÷åòíûé. |
Kovalev_D |
22:12e6183f04d4 | 58 | { |
Kovalev_D |
22:12e6183f04d4 | 59 | LPC_SSP0->DR = WRITE_DAC1 ; //e.êîìàíäà äëÿ ÖÀÏ_1 ïåðåäàâàòü. |
Kovalev_D |
22:12e6183f04d4 | 60 | LPC_SSP0->DR = (Spi.DAC_B); //e. ïåðåäà÷à 12 áèò |
Kovalev_D |
22:12e6183f04d4 | 61 | } |
Kovalev_D |
22:12e6183f04d4 | 62 | |
Kovalev_D |
22:12e6183f04d4 | 63 | LPC_DAC->CR = (((SinPLC[CountV64]*35)+21300)); |
Kovalev_D |
22:12e6183f04d4 | 64 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //åñëè áóôåð SPI íå ïóñò. |
Kovalev_D |
22:12e6183f04d4 | 65 | Dummy = LPC_SSP0->DR; //î÷èñòèòü áóôåð. |
Kovalev_D |
22:12e6183f04d4 | 66 | |
Kovalev_D |
22:12e6183f04d4 | 67 | |
Kovalev_D |
22:12e6183f04d4 | 68 | Buff_ADC_1 [CountV255] = Spi.ADC1; // àìïë àöï. |
Kovalev_D |
22:12e6183f04d4 | 69 | Buff_ADC_2 [CountV255] = Spi.ADC2; |
Kovalev_D |
22:12e6183f04d4 | 70 | Buff_ADC_3 [CountV255] = Spi.ADC3; |
Kovalev_D |
22:12e6183f04d4 | 71 | Buff_ADC_4 [CountV255] = Spi.ADC4; |
Kovalev_D |
22:12e6183f04d4 | 72 | Buff_ADC_5 [CountV255] = Spi.ADC5; |
Kovalev_D |
22:12e6183f04d4 | 73 | |
Kovalev_D |
22:12e6183f04d4 | 74 | |
Kovalev_D |
22:12e6183f04d4 | 75 | |
Kovalev_D |
22:12e6183f04d4 | 76 | Temp_AMP += Buff_ADC_5[CountV255]; |
Kovalev_D |
22:12e6183f04d4 | 77 | Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // çàïîëíåíèå áóôåðà íàêîïëåíûõ ïðèðàùåíèé çà 8 òàêòîâ |
Kovalev_D |
22:12e6183f04d4 | 78 | Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); |
Kovalev_D |
22:12e6183f04d4 | 79 | |
Kovalev_D |
22:12e6183f04d4 | 80 | Temp_ADC_2 += Buff_ADC_2[CountV255]; |
Kovalev_D |
22:12e6183f04d4 | 81 | Temp_ADC_2 -= Buff_ADC_2[(CountV255-32) & 0xff]; |
Kovalev_D |
22:12e6183f04d4 | 82 | |
Kovalev_D |
22:12e6183f04d4 | 83 | Temp_ADC_3 += Buff_ADC_3[CountV255]; |
Kovalev_D |
22:12e6183f04d4 | 84 | Temp_ADC_3 -= Buff_ADC_3[(CountV255-32) & 0xff]; |
Kovalev_D |
22:12e6183f04d4 | 85 | |
Kovalev_D |
22:12e6183f04d4 | 86 | Temp_ADC_4 += Buff_ADC_4[CountV255]; |
Kovalev_D |
22:12e6183f04d4 | 87 | Temp_ADC_4 -= Buff_ADC_4[(CountV255-32) & 0xff]; |
Kovalev_D |
22:12e6183f04d4 | 88 | |
Kovalev_D |
22:12e6183f04d4 | 89 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
Kovalev_D |
22:12e6183f04d4 | 90 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
Kovalev_D |
22:12e6183f04d4 | 91 | } |
Kovalev_D |
22:12e6183f04d4 | 92 | void Init_SPI_Exchange() |
Kovalev_D |
22:12e6183f04d4 | 93 | { |
Kovalev_D |
22:12e6183f04d4 | 94 | ResetCS(ADC); //prepare ADC for sampling |
Kovalev_D |
22:12e6183f04d4 | 95 | SetDAC(DAC); |
Kovalev_D |
22:12e6183f04d4 | 96 | LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
Kovalev_D |
22:12e6183f04d4 | 97 | //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
Kovalev_D |
22:12e6183f04d4 | 98 | //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
Kovalev_D |
22:12e6183f04d4 | 99 | SetCS(ADC); //start ADC sampling |
Kovalev_D |
22:12e6183f04d4 | 100 | ResetDAC(DAC); |
Kovalev_D |
22:12e6183f04d4 | 101 | } |