Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LG by
SPI.c
- Committer:
- igor_v
- Date:
- 2016-02-03
- Revision:
- 21:bc8c1cec3da6
- Parent:
- 0:8ad47e2b6f00
- Child:
- 22:e456b51c72ed
- Child:
- 31:c783288001b5
File content as of revision 21:bc8c1cec3da6:
#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 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);
}
