123
Fork of LG by
Diff: DeviceSSP.c
- Revision:
- 156:e68ee0bcdcda
- Parent:
- 149:abbf7663d27d
- Child:
- 166:c3c0b8a90d81
--- a/DeviceSSP.c Fri May 06 14:08:54 2016 +0000 +++ b/DeviceSSP.c Mon May 09 20:03:26 2016 +0000 @@ -1,10 +1,63 @@ #include "Device.h" + +#define SSPCR1_SSE 0x00000002 + +#define TX_SSP_EMPT 0x00000001 +#define RX_SSP_notEMPT 0x00000004 +#define TX_SSP_notFULL 0x00000002 +#define RX_SSP_FULL 0x00000008 +#define SSP_BUSY 0x00000010 + +#define ADC_ERR_MSK 0x00000001 +#define DAC_ERR_MSK 0x00000002 + extern Device device; void InitSSPWithDefaults(void){ } void InitSSP(void){ + uint32_t Dummy; + + LPC_SC->PCONP |= (1<<21); //Power on SSP0 + + /* выбор частоты для переферии используем по умолчания с делителем основной на 4 */ + LPC_SC->PCLKSEL1 &= ~(0x3<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/8 + LPC_SC->PCLKSEL1 |= (0x0<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/ + + // P0.15~0.18 as SSP0 + LPC_PINCON->PINSEL0 &= ~(0x3UL<<30); //установит Р 0.15 + LPC_PINCON->PINSEL0 |= (0x2UL<<30); //частота для синхронизациии Master - slave + + LPC_PINCON->PINSEL1 &= ~((0x3<<0)|(0x3<<2)|(0x3<<4)); // устанивоить Р 0.17 и Р 0.18 + LPC_PINCON->PINSEL1 |= ((0x2<<2)|(0x2<<4)); // как MISO0 и MOSI0 + + LPC_PINCON->PINMODE0 &= ~(0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled + LPC_PINCON->PINMODE0 |= (0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled + + LPC_PINCON->PINMODE1 &= ~((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled + LPC_PINCON->PINMODE1 |= ((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled + + LPC_SSP0->CR0 = ((3<<8)|(0<<7)|(0<<4) |0xF); // (0xF)-установление DSS(Data sise select) в 16-битный формат, (3<<8 scr - выбор частоты), + // низкий уровень линии тактирования между кадрами, прикрепление передачи к первому нарастанию тактового мигнала + // формат кадра TI. + + /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ + LPC_SSP0->CPSR = 0x2; // freq = CLK/(cpsdvr*(scr+1)) = 1.6 MHz + + /*SSP enable, master mode */ + LPC_SSP0->CR1 = SSPCR1_SSE; + while (LPC_SSP0->SR & SSP_BUSY); //wait until busy + while (LPC_SSP0->SR & RX_SSP_notEMPT) /* clear the RxFIFO */ + Dummy = LPC_SSP0->DR; + //all pins after reset is in GPIO mode, so CS pins needn't to configure + LPC_GPIO0->FIODIR |= (1<<16); // P0.16 defined as CS for ADC + LPC_GPIO0->FIOSET |= (1<<16); // set CS for ADC + + LPC_GPIO0->FIODIR |= (1<<23); // P defined as CS for DAC + LPC_GPIO0->FIOCLR |= (1<<23); // set CS for DAC + while (LPC_SSP1->SR & RX_SSP_notEMPT) + Dummy = LPC_SSP1->DR; /* clear the RxFIFO */ } void DeviceSSPReceive(void){ @@ -14,18 +67,18 @@ LPC_GPIO0->FIOSET = 1<<16; //set SSEL signal for ADCs //Get samples uint32_t value; - device.SSP.accumulator[4] += LPC_SSP0->DR; - device.SSP.accumulator[3] += LPC_SSP0->DR; - device.SSP.accumulator[2] += LPC_SSP0->DR; - device.SSP.accumulator[1] += LPC_SSP0->DR; - device.SSP.accumulator[0] += LPC_SSP0->DR; + device.controller.SSP.accumulator[4] += LPC_SSP0->DR; + device.controller.SSP.accumulator[3] += LPC_SSP0->DR; + device.controller.SSP.accumulator[2] += LPC_SSP0->DR; + device.controller.SSP.accumulator[1] += LPC_SSP0->DR; + device.controller.SSP.accumulator[0] += LPC_SSP0->DR; while (LPC_SSP0->SR & 0x00000004) value = LPC_SSP0->DR; //Average samples for dither period - if (device.dither.state.inPeriodCounter == 0) { + if (device.measurement.counter == 0) { for (uint8_t i = 0; i < 5; i++){ - device.SSP.in[i] = device.SSP.accumulator[i] >> 5; - device.SSP.accumulator[i] = 0; - device.SSP.dataReady = 1; + device.controller.SSP.in[i] = device.controller.SSP.accumulator[i] >> 5; + device.controller.SSP.accumulator[i] = 0; + device.controller.SSP.dataReady = 1; } } } @@ -40,31 +93,9 @@ if (index){ LPC_SSP0->DR = 0x00000030; //Write DAC0 - LPC_SSP0->DR = device.SSP.out[0]; + LPC_SSP0->DR = device.controller.SSP.out[0]; } else { LPC_SSP0->DR = 0x00000031; //Write DAC1 - LPC_SSP0->DR = device.SSP.out[1]; - /* - //Move to DevicePLCS from here as not SSP specific - uint32_t value; - switch(device.plcs.state.modulation) { - case 1://малое воздействие - value = device.SSP.DAC[1] + Gyro.StrayPLC_Pls; - break; - - case 3://малое воздействие - value = device.SSP.DAC[1] + Gyro.StrayPLC_Mns; - break; - - case 2://большое воздействие - value = device.SSP.DAC[1] + Gyro.StrayPLC_2Mode; - break; - - default://режим без воздействия - value = device.SSP.DAC[1]; - break; - } - LPC_SSP0->DR = device.SSP.DAC[1]; - */ + LPC_SSP0->DR = device.controller.SSP.out[1]; } } \ No newline at end of file