![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
n
Fork of LG by
SPI.c@28:1c9acd3b224d, 2016-02-04 (annotated)
- Committer:
- Kovalev_D
- Date:
- Thu Feb 04 10:21:57 2016 +0000
- Revision:
- 28:1c9acd3b224d
- Parent:
- 21:bc8c1cec3da6
- Child:
- 22:e456b51c72ed
13:21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 2 | struct SPI Spi; |
igor_v | 0:8ad47e2b6f00 | 3 | unsigned int Temp_AMP=0; |
igor_v | 0:8ad47e2b6f00 | 4 | |
igor_v | 0:8ad47e2b6f00 | 5 | unsigned int Temp_ADC_2=0; |
igor_v | 0:8ad47e2b6f00 | 6 | unsigned int Temp_ADC_3=0; |
igor_v | 0:8ad47e2b6f00 | 7 | unsigned int Temp_ADC_4=0; |
igor_v | 0:8ad47e2b6f00 | 8 | unsigned int Temp_ADC_5=0; |
igor_v | 0:8ad47e2b6f00 | 9 | |
igor_v | 0:8ad47e2b6f00 | 10 | |
igor_v | 0:8ad47e2b6f00 | 11 | unsigned int Buff_ADC_1 [256]; |
igor_v | 0:8ad47e2b6f00 | 12 | unsigned int Buff_ADC_2 [256]; |
igor_v | 0:8ad47e2b6f00 | 13 | unsigned int Buff_ADC_3 [256]; |
igor_v | 0:8ad47e2b6f00 | 14 | unsigned int Buff_ADC_4 [256]; |
igor_v | 0:8ad47e2b6f00 | 15 | unsigned int Buff_ADC_5 [256]; |
igor_v | 0:8ad47e2b6f00 | 16 | |
igor_v | 0:8ad47e2b6f00 | 17 | unsigned int Buff_AMP [256]; |
igor_v | 21:bc8c1cec3da6 | 18 | |
igor_v | 21:bc8c1cec3da6 | 19 | unsigned int SinPLC[64]={1023, 1016, 1006, 993, 976, 954, 904, 874, 841, 806, 768, 728, |
igor_v | 21:bc8c1cec3da6 | 20 | 687, 645, 601, 557, 500, 379, 337, 296, 256, 219, 183, 150, |
igor_v | 21:bc8c1cec3da6 | 21 | 120, 93, 69, 48, 31, 18, 8, 0, 8, 18, 31, 48, |
igor_v | 21:bc8c1cec3da6 | 22 | 69, 93, 120, 150, 183, 219, 256, 296, 337, 379, 468, 512, 557, |
igor_v | 21:bc8c1cec3da6 | 23 | 601, 645, 687, 728, 768, 806, 841, 874, 904, 954, 976, 993, 1006, |
igor_v | 21:bc8c1cec3da6 | 24 | 1016, 1023}; |
igor_v | 21:bc8c1cec3da6 | 25 | void DACLInit( void ) |
igor_v | 21:bc8c1cec3da6 | 26 | { |
igor_v | 21:bc8c1cec3da6 | 27 | /* setup the related pin to DAC output */ |
igor_v | 21:bc8c1cec3da6 | 28 | LPC_PINCON->PINSEL1 = 0x00200000; /* set p0.26 to DAC output */ |
igor_v | 21:bc8c1cec3da6 | 29 | return; |
igor_v | 21:bc8c1cec3da6 | 30 | } |
igor_v | 0:8ad47e2b6f00 | 31 | void SPI_Exchange() |
igor_v | 0:8ad47e2b6f00 | 32 | { |
igor_v | 0:8ad47e2b6f00 | 33 | unsigned int Dummy; |
igor_v | 0:8ad47e2b6f00 | 34 | |
igor_v | 0:8ad47e2b6f00 | 35 | Spi.ADC5 = LPC_SSP0->DR; |
igor_v | 0:8ad47e2b6f00 | 36 | Spi.ADC4 = LPC_SSP0->DR; |
igor_v | 0:8ad47e2b6f00 | 37 | Spi.ADC3 = LPC_SSP0->DR; |
igor_v | 0:8ad47e2b6f00 | 38 | Spi.ADC2 = LPC_SSP0->DR; |
igor_v | 0:8ad47e2b6f00 | 39 | Spi.ADC1 = LPC_SSP0->DR; |
igor_v | 0:8ad47e2b6f00 | 40 | |
igor_v | 0:8ad47e2b6f00 | 41 | Input.ArrayIn[2]= Spi.ADC5; |
igor_v | 0:8ad47e2b6f00 | 42 | |
igor_v | 0:8ad47e2b6f00 | 43 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 44 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 45 | LPC_SSP0->DR=0x5555; |
igor_v | 0:8ad47e2b6f00 | 46 | |
igor_v | 21:bc8c1cec3da6 | 47 | if (CountV31 & 1) //если нечетный такт то |
igor_v | 0:8ad47e2b6f00 | 48 | { |
igor_v | 21:bc8c1cec3da6 | 49 | LPC_SSP0->DR = WRITE_DAC0; //e.команда для ЦАП_0 передавать. |
igor_v | 21:bc8c1cec3da6 | 50 | LPC_SSP0->DR = (Spi.DAC_A); //e. передача 12 бит |
igor_v | 0:8ad47e2b6f00 | 51 | } |
igor_v | 21:bc8c1cec3da6 | 52 | else //если такт четный. |
igor_v | 0:8ad47e2b6f00 | 53 | { |
igor_v | 21:bc8c1cec3da6 | 54 | LPC_SSP0->DR = WRITE_DAC1 ; //e.команда для ЦАП_1 передавать. |
igor_v | 21:bc8c1cec3da6 | 55 | LPC_SSP0->DR = (Spi.DAC_B); //e. передача 12 бит |
igor_v | 0:8ad47e2b6f00 | 56 | } |
igor_v | 21:bc8c1cec3da6 | 57 | |
igor_v | 21:bc8c1cec3da6 | 58 | LPC_DAC->CR = (((SinPLC[CountV64]*35)+21300)); |
igor_v | 21:bc8c1cec3da6 | 59 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //если буфер SPI не пуст. |
igor_v | 21:bc8c1cec3da6 | 60 | Dummy = LPC_SSP0->DR; //очистить буфер. |
igor_v | 0:8ad47e2b6f00 | 61 | |
igor_v | 0:8ad47e2b6f00 | 62 | |
igor_v | 21:bc8c1cec3da6 | 63 | Buff_ADC_1 [CountV255] = Spi.ADC1; // ампл ацп. |
igor_v | 0:8ad47e2b6f00 | 64 | Buff_ADC_2 [CountV255] = Spi.ADC2; |
igor_v | 0:8ad47e2b6f00 | 65 | Buff_ADC_3 [CountV255] = Spi.ADC3; |
igor_v | 0:8ad47e2b6f00 | 66 | Buff_ADC_4 [CountV255] = Spi.ADC4; |
igor_v | 0:8ad47e2b6f00 | 67 | Buff_ADC_5 [CountV255] = Spi.ADC5; |
igor_v | 0:8ad47e2b6f00 | 68 | |
igor_v | 0:8ad47e2b6f00 | 69 | |
igor_v | 0:8ad47e2b6f00 | 70 | |
igor_v | 0:8ad47e2b6f00 | 71 | Temp_AMP += Buff_ADC_5[CountV255]; |
igor_v | 21:bc8c1cec3da6 | 72 | Temp_AMP -= Buff_ADC_5[(CountV255-32) & 0xff]; // заполнение буфера накопленых приращений за 8 тактов |
igor_v | 0:8ad47e2b6f00 | 73 | Buff_AMP[CountV255] = (unsigned int) (Temp_AMP); |
igor_v | 0:8ad47e2b6f00 | 74 | |
igor_v | 0:8ad47e2b6f00 | 75 | Temp_ADC_2 += Buff_ADC_2[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 76 | Temp_ADC_2 -= Buff_ADC_2[(CountV255-32) & 0xff]; |
igor_v | 0:8ad47e2b6f00 | 77 | |
igor_v | 0:8ad47e2b6f00 | 78 | Temp_ADC_3 += Buff_ADC_3[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 79 | Temp_ADC_3 -= Buff_ADC_3[(CountV255-32) & 0xff]; |
igor_v | 0:8ad47e2b6f00 | 80 | |
igor_v | 0:8ad47e2b6f00 | 81 | Temp_ADC_4 += Buff_ADC_4[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 82 | Temp_ADC_4 -= Buff_ADC_4[(CountV255-32) & 0xff]; |
igor_v | 0:8ad47e2b6f00 | 83 | |
igor_v | 0:8ad47e2b6f00 | 84 | Temp_ADC_5 += Buff_ADC_1[CountV255]; |
igor_v | 0:8ad47e2b6f00 | 85 | Temp_ADC_5 -= Buff_ADC_1[(CountV255-32) & 0xff]; |
igor_v | 0:8ad47e2b6f00 | 86 | } |
igor_v | 0:8ad47e2b6f00 | 87 | void Init_SPI_Exchange() |
igor_v | 0:8ad47e2b6f00 | 88 | { |
igor_v | 0:8ad47e2b6f00 | 89 | ResetCS(ADC); //prepare ADC for sampling |
igor_v | 0:8ad47e2b6f00 | 90 | SetDAC(DAC); |
igor_v | 0:8ad47e2b6f00 | 91 | LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
igor_v | 0:8ad47e2b6f00 | 92 | //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
igor_v | 0:8ad47e2b6f00 | 93 | //LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED |
igor_v | 0:8ad47e2b6f00 | 94 | SetCS(ADC); //start ADC sampling |
igor_v | 0:8ad47e2b6f00 | 95 | ResetDAC(DAC); |
igor_v | 21:bc8c1cec3da6 | 96 | } |