![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LGstaandart by
Diff: SPI.c
- Revision:
- 31:c783288001b5
- Parent:
- 21:bc8c1cec3da6
- Child:
- 47:d902ef6f7564
diff -r 17c84ed091b3 -r c783288001b5 SPI.c --- a/SPI.c Fri Feb 05 23:21:54 2016 +0000 +++ b/SPI.c Fri Feb 05 23:30:23 2016 +0000 @@ -1,96 +1,94 @@ #include "Global.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 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_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 ) +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; + /* 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; + 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; - Input.ArrayIn[2]= Spi.ADC5; + LPC_SSP0->DR=0x5555; + LPC_SSP0->DR=0x5555; + LPC_SSP0->DR=0x5555; - 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 бит + } - 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; //очистить буфер. - + 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; + + - 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]; + 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 + 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); +//LPC_GPIO2->FIOSET |= 0x0000004; // turn on the LED + SetCS(ADC); //start ADC sampling + ResetDAC(DAC); } \ No newline at end of file