![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
forkd
Fork of LG2 by
host/Source/App/InputOutput.c@23:12e6183f04d4, 2016-02-03 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Feb 03 10:44:42 2016 +0300
- Revision:
- 23:12e6183f04d4
[thyz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kovalev_D |
23:12e6183f04d4 | 1 | #include "InputOutput.h" |
Kovalev_D |
23:12e6183f04d4 | 2 | #include "CyclesSync.h" |
Kovalev_D |
23:12e6183f04d4 | 3 | #include "lpc17xx.h" |
Kovalev_D |
23:12e6183f04d4 | 4 | //-------------------temp------- |
Kovalev_D |
23:12e6183f04d4 | 5 | #include "el_lin.h" |
Kovalev_D |
23:12e6183f04d4 | 6 | INPUT Input; |
Kovalev_D |
23:12e6183f04d4 | 7 | OUTPUT Output; |
Kovalev_D |
23:12e6183f04d4 | 8 | |
Kovalev_D |
23:12e6183f04d4 | 9 | volatile uint32_t I2CMasterState = I2C_IDLE; |
Kovalev_D |
23:12e6183f04d4 | 10 | volatile uint32_t I2CMasterBuffer[I2C_WRITELENGTH]; |
Kovalev_D |
23:12e6183f04d4 | 11 | |
Kovalev_D |
23:12e6183f04d4 | 12 | int ExchangeErr = 0; |
Kovalev_D |
23:12e6183f04d4 | 13 | //----------------------temp--------------------- |
Kovalev_D |
23:12e6183f04d4 | 14 | extern char test; |
Kovalev_D |
23:12e6183f04d4 | 15 | /****************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 16 | ** Function name: G_Photo_Exchange |
Kovalev_D |
23:12e6183f04d4 | 17 | ** |
Kovalev_D |
23:12e6183f04d4 | 18 | ** Descriptions: Driver for I2C exchange |
Kovalev_D |
23:12e6183f04d4 | 19 | ** |
Kovalev_D |
23:12e6183f04d4 | 20 | ** parameters: None |
Kovalev_D |
23:12e6183f04d4 | 21 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 22 | ** |
Kovalev_D |
23:12e6183f04d4 | 23 | ******************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 24 | |
Kovalev_D |
23:12e6183f04d4 | 25 | void G_Photo_Exchange(void) |
Kovalev_D |
23:12e6183f04d4 | 26 | { |
Kovalev_D |
23:12e6183f04d4 | 27 | uint32_t StatValue; |
Kovalev_D |
23:12e6183f04d4 | 28 | static uint32_t WrIndex; |
Kovalev_D |
23:12e6183f04d4 | 29 | static int32_t time_out = TIMEOUT; |
Kovalev_D |
23:12e6183f04d4 | 30 | |
Kovalev_D |
23:12e6183f04d4 | 31 | if (I2CMasterState) |
Kovalev_D |
23:12e6183f04d4 | 32 | return; //e.transmitting is not active, go away |
Kovalev_D |
23:12e6183f04d4 | 33 | |
Kovalev_D |
23:12e6183f04d4 | 34 | if (--time_out < 0) //e. valid time period elapsed, go away |
Kovalev_D |
23:12e6183f04d4 | 35 | { |
Kovalev_D |
23:12e6183f04d4 | 36 | time_out = TIMEOUT; |
Kovalev_D |
23:12e6183f04d4 | 37 | I2CMasterState = I2C_IDLE; //e. timer elapsed, go away |
Kovalev_D |
23:12e6183f04d4 | 38 | LPC_I2C0->CONSET = I2CONSET_STO; //e. Set Stop flag |
Kovalev_D |
23:12e6183f04d4 | 39 | LPC_I2C0->CONCLR = I2CONCLR_AAC | I2CONCLR_SIC | I2CONCLR_STAC; |
Kovalev_D |
23:12e6183f04d4 | 40 | return; |
Kovalev_D |
23:12e6183f04d4 | 41 | } |
Kovalev_D |
23:12e6183f04d4 | 42 | else if (!(LPC_I2C0->CONSET & I2CONSET_SI)) //e. state of I2C bus has not been changed |
Kovalev_D |
23:12e6183f04d4 | 43 | return; |
Kovalev_D |
23:12e6183f04d4 | 44 | |
Kovalev_D |
23:12e6183f04d4 | 45 | StatValue = LPC_I2C0->STAT; |
Kovalev_D |
23:12e6183f04d4 | 46 | |
Kovalev_D |
23:12e6183f04d4 | 47 | switch ( StatValue ) |
Kovalev_D |
23:12e6183f04d4 | 48 | { |
Kovalev_D |
23:12e6183f04d4 | 49 | case 0x08: // A Start condition is issued (write data for the first potentiometer) |
Kovalev_D |
23:12e6183f04d4 | 50 | WrIndex = 0; |
Kovalev_D |
23:12e6183f04d4 | 51 | time_out = TIMEOUT; //e. enable countdown |
Kovalev_D |
23:12e6183f04d4 | 52 | LPC_I2C0->DAT = I2CMasterBuffer[WrIndex++]; //e. send address |
Kovalev_D |
23:12e6183f04d4 | 53 | LPC_I2C0->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC); //e .clear interrupt bit and start bit |
Kovalev_D |
23:12e6183f04d4 | 54 | break; |
Kovalev_D |
23:12e6183f04d4 | 55 | |
Kovalev_D |
23:12e6183f04d4 | 56 | case 0x10: // A repeated started is issued (write data for the second potentiometer) |
Kovalev_D |
23:12e6183f04d4 | 57 | LPC_I2C0->DAT = I2CMasterBuffer[WrIndex++]; //e. send address |
Kovalev_D |
23:12e6183f04d4 | 58 | LPC_I2C0->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC); //e .clear interrupt bit and start bit |
Kovalev_D |
23:12e6183f04d4 | 59 | break; |
Kovalev_D |
23:12e6183f04d4 | 60 | |
Kovalev_D |
23:12e6183f04d4 | 61 | case 0x18: //e. Regardless, it's a ACK after slave address reading |
Kovalev_D |
23:12e6183f04d4 | 62 | LPC_I2C0->DAT = I2CMasterBuffer[WrIndex++]; //e. send another byte |
Kovalev_D |
23:12e6183f04d4 | 63 | LPC_I2C0->CONCLR = I2CONCLR_SIC; //e. clear interrupt bit |
Kovalev_D |
23:12e6183f04d4 | 64 | break; |
Kovalev_D |
23:12e6183f04d4 | 65 | |
Kovalev_D |
23:12e6183f04d4 | 66 | case 0x28: //e. Regardless it's a ACK after data byte |
Kovalev_D |
23:12e6183f04d4 | 67 | if (WrIndex == I2C_WRITELENGTH) //e. we have transmitted the data for the B potentiometer |
Kovalev_D |
23:12e6183f04d4 | 68 | { |
Kovalev_D |
23:12e6183f04d4 | 69 | I2CMasterState = I2C_IDLE; |
Kovalev_D |
23:12e6183f04d4 | 70 | LPC_I2C0->CONSET = I2CONSET_STO; //e. Set Stop flag |
Kovalev_D |
23:12e6183f04d4 | 71 | Output.Str.Cnt_Dif = 300; |
Kovalev_D |
23:12e6183f04d4 | 72 | } |
Kovalev_D |
23:12e6183f04d4 | 73 | else if (WrIndex == 3) |
Kovalev_D |
23:12e6183f04d4 | 74 | { |
Kovalev_D |
23:12e6183f04d4 | 75 | LPC_I2C0->CONSET = I2CONSET_STA; |
Kovalev_D |
23:12e6183f04d4 | 76 | Output.Str.Cnt_Dif = 200; |
Kovalev_D |
23:12e6183f04d4 | 77 | } |
Kovalev_D |
23:12e6183f04d4 | 78 | else |
Kovalev_D |
23:12e6183f04d4 | 79 | { |
Kovalev_D |
23:12e6183f04d4 | 80 | LPC_I2C0->DAT = I2CMasterBuffer[WrIndex++]; //e. send another byte |
Kovalev_D |
23:12e6183f04d4 | 81 | Output.Str.Cnt_Dif = 100; |
Kovalev_D |
23:12e6183f04d4 | 82 | } |
Kovalev_D |
23:12e6183f04d4 | 83 | LPC_I2C0->CONCLR = I2CONCLR_SIC; //e. clear interrupt bit |
Kovalev_D |
23:12e6183f04d4 | 84 | break; |
Kovalev_D |
23:12e6183f04d4 | 85 | |
Kovalev_D |
23:12e6183f04d4 | 86 | case 0x20: //e. no aknowledgement after address transmitting |
Kovalev_D |
23:12e6183f04d4 | 87 | case 0x30: //e. no aknowledgement after data block transmitting |
Kovalev_D |
23:12e6183f04d4 | 88 | LPC_I2C0->CONSET = I2CONSET_STO; //e. Set Stop flag |
Kovalev_D |
23:12e6183f04d4 | 89 | LPC_I2C0->CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC); |
Kovalev_D |
23:12e6183f04d4 | 90 | I2CMasterState = I2C_IDLE; //e. fix new state |
Kovalev_D |
23:12e6183f04d4 | 91 | break; |
Kovalev_D |
23:12e6183f04d4 | 92 | } |
Kovalev_D |
23:12e6183f04d4 | 93 | return; |
Kovalev_D |
23:12e6183f04d4 | 94 | } |
Kovalev_D |
23:12e6183f04d4 | 95 | /****************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 96 | ** Function name: DAC_ADC_Exchange |
Kovalev_D |
23:12e6183f04d4 | 97 | ** |
Kovalev_D |
23:12e6183f04d4 | 98 | ** Descriptions: Loading data to DACs and initialization of ADC reading |
Kovalev_D |
23:12e6183f04d4 | 99 | ** |
Kovalev_D |
23:12e6183f04d4 | 100 | ** parameters: None |
Kovalev_D |
23:12e6183f04d4 | 101 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 102 | ** |
Kovalev_D |
23:12e6183f04d4 | 103 | ******************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 104 | void DAC_ADC_Exchange() |
Kovalev_D |
23:12e6183f04d4 | 105 | { |
Kovalev_D |
23:12e6183f04d4 | 106 | //-------------------------loading data from ADC to buffer--------------------------------------- |
Kovalev_D |
23:12e6183f04d4 | 107 | //int x; |
Kovalev_D |
23:12e6183f04d4 | 108 | ExchangeErr &= ~ADC_ERR_MSK; //e. ñáðîñèòü ôëàã îøèáêè |
Kovalev_D |
23:12e6183f04d4 | 109 | if (LPC_SSP0->SR & SSP_BUSY) //e. åñëè áóôåð ïåðåäàò÷èêà íå ïîëîí |
Kovalev_D |
23:12e6183f04d4 | 110 | { |
Kovalev_D |
23:12e6183f04d4 | 111 | ExchangeErr |= ADC_ERR_MSK; //e. óñòàíîâèòü ôëàã îøèáêè |
Kovalev_D |
23:12e6183f04d4 | 112 | } |
Kovalev_D |
23:12e6183f04d4 | 113 | else |
Kovalev_D |
23:12e6183f04d4 | 114 | { |
Kovalev_D |
23:12e6183f04d4 | 115 | LPC_SSP0->DR = 0x8001; //çàïèñàòü 0x8001 â ðåãèñòð ïåðåäà÷è. |
Kovalev_D |
23:12e6183f04d4 | 116 | if (Sys_Clock & 1)//åñëè íå÷åòíûé òàêò òî |
Kovalev_D |
23:12e6183f04d4 | 117 | { |
Kovalev_D |
23:12e6183f04d4 | 118 | LPC_SSP0->DR = WRITE_DAC0; //e.êîìàíäà äëÿ ÖÀÏ_0 ïåðåäàâàòü. |
Kovalev_D |
23:12e6183f04d4 | 119 | LPC_SSP0->DR = (-Output.ArrayOut[3]+32767); //e. ïåðåäà÷à 12 áèò |
Kovalev_D |
23:12e6183f04d4 | 120 | } |
Kovalev_D |
23:12e6183f04d4 | 121 | else //åñëè òàêò ÷åòíûé. |
Kovalev_D |
23:12e6183f04d4 | 122 | { |
Kovalev_D |
23:12e6183f04d4 | 123 | LPC_SSP0->DR = WRITE_DAC1 ; //e.êîìàíäà äëÿ ÖÀÏ_1 ïåðåäàâàòü. |
Kovalev_D |
23:12e6183f04d4 | 124 | LPC_SSP0->DR = (Output.ArrayOut[0]<<1) & 0xFFF0; //e. ïåðåäà÷à 12 áèò |
Kovalev_D |
23:12e6183f04d4 | 125 | } |
Kovalev_D |
23:12e6183f04d4 | 126 | } |
Kovalev_D |
23:12e6183f04d4 | 127 | } |
Kovalev_D |
23:12e6183f04d4 | 128 | /****************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 129 | ** Function name: ADC_Input |
Kovalev_D |
23:12e6183f04d4 | 130 | ** |
Kovalev_D |
23:12e6183f04d4 | 131 | ** Descriptions: Reading data from ADC |
Kovalev_D |
23:12e6183f04d4 | 132 | ** |
Kovalev_D |
23:12e6183f04d4 | 133 | ** parameters: None |
Kovalev_D |
23:12e6183f04d4 | 134 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 135 | ** |
Kovalev_D |
23:12e6183f04d4 | 136 | ******************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 137 | void ADC_Input() |
Kovalev_D |
23:12e6183f04d4 | 138 | { |
Kovalev_D |
23:12e6183f04d4 | 139 | uint32_t Dummy; |
Kovalev_D |
23:12e6183f04d4 | 140 | |
Kovalev_D |
23:12e6183f04d4 | 141 | //---------------------read data from ADC buffer--------------------------------------------- |
Kovalev_D |
23:12e6183f04d4 | 142 | Dummy = Dummy; |
Kovalev_D |
23:12e6183f04d4 | 143 | ExchangeErr &= ~ADC_ERR_MSK; |
Kovalev_D |
23:12e6183f04d4 | 144 | |
Kovalev_D |
23:12e6183f04d4 | 145 | if (LPC_SSP0->SR & SSP_BUSY) //åñëè áóôåð ôèôî íå ïîëíûé(ïåðåäà÷à àòèâíà) |
Kovalev_D |
23:12e6183f04d4 | 146 | { ExchangeErr |= ADC_ERR_MSK; //óñòàíîâèòü ôëàã îøèáêè |
Kovalev_D |
23:12e6183f04d4 | 147 | |
Kovalev_D |
23:12e6183f04d4 | 148 | if (!(LPC_SSP0->SR & TX_SSP_EMPT)) //áóôåð ïåðåäà÷è íå ïóñò. |
Kovalev_D |
23:12e6183f04d4 | 149 | ExchangeErr |= ADC_ERR_MSK; //óñòàíîâèòü ôëàã îøèáêè |
Kovalev_D |
23:12e6183f04d4 | 150 | } |
Kovalev_D |
23:12e6183f04d4 | 151 | else //îáìåí çàêîí÷åí ïðî÷èòàòü áóôåð. |
Kovalev_D |
23:12e6183f04d4 | 152 | { |
Kovalev_D |
23:12e6183f04d4 | 153 | Input.ArrayIn[0] = LPC_SSP0->DR; //÷òåíèåThermo2 |
Kovalev_D |
23:12e6183f04d4 | 154 | Input.ArrayIn[1] = LPC_SSP0->DR; //÷òåíèå Thermo1 |
Kovalev_D |
23:12e6183f04d4 | 155 | Input.ArrayIn[2] = LPC_SSP0->DR; //÷òåíèå HF_out |
Kovalev_D |
23:12e6183f04d4 | 156 | |
Kovalev_D |
23:12e6183f04d4 | 157 | while (LPC_SSP0->SR & RX_SSP_notEMPT) //åñëè áóôåð SPI íå ïóñò. |
Kovalev_D |
23:12e6183f04d4 | 158 | Dummy = LPC_SSP0->DR; //î÷èñòèòü áóôåð. |
Kovalev_D |
23:12e6183f04d4 | 159 | } |
Kovalev_D |
23:12e6183f04d4 | 160 | |
Kovalev_D |
23:12e6183f04d4 | 161 | |
Kovalev_D |
23:12e6183f04d4 | 162 | } |
Kovalev_D |
23:12e6183f04d4 | 163 | /***************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 164 | ** Function name: DAC_Output |
Kovalev_D |
23:12e6183f04d4 | 165 | ** |
Kovalev_D |
23:12e6183f04d4 | 166 | ** Descriptions: Output data to intrnal DAC |
Kovalev_D |
23:12e6183f04d4 | 167 | ** |
Kovalev_D |
23:12e6183f04d4 | 168 | ** parameters: output - code for output |
Kovalev_D |
23:12e6183f04d4 | 169 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 170 | ** |
Kovalev_D |
23:12e6183f04d4 | 171 | *****************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 172 | void DAC_Output(int output) |
Kovalev_D |
23:12e6183f04d4 | 173 | { |
Kovalev_D |
23:12e6183f04d4 | 174 | // LPC_DAC->CR = (output<<6); |
Kovalev_D |
23:12e6183f04d4 | 175 | return; |
Kovalev_D |
23:12e6183f04d4 | 176 | } |
Kovalev_D |
23:12e6183f04d4 | 177 | /****************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 178 | ** Function name: G_Photo_Init |
Kovalev_D |
23:12e6183f04d4 | 179 | ** |
Kovalev_D |
23:12e6183f04d4 | 180 | ** Descriptions: Initialization of exchange with digital potentiometers |
Kovalev_D |
23:12e6183f04d4 | 181 | ** |
Kovalev_D |
23:12e6183f04d4 | 182 | ** parameters: None |
Kovalev_D |
23:12e6183f04d4 | 183 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 184 | ** |
Kovalev_D |
23:12e6183f04d4 | 185 | ******************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 186 | void G_Photo_Init(void ) |
Kovalev_D |
23:12e6183f04d4 | 187 | { |
Kovalev_D |
23:12e6183f04d4 | 188 | LPC_SC->PCONP |= (1 << 19);//âêëþ÷åíèå èíòåðôåéñà I2C. |
Kovalev_D |
23:12e6183f04d4 | 189 | |
Kovalev_D |
23:12e6183f04d4 | 190 | /* set PIO0.27 and PIO0.28 to I2C0 SDA and SCK */ |
Kovalev_D |
23:12e6183f04d4 | 191 | /* function to 01 on both SDA and SCK. */ |
Kovalev_D |
23:12e6183f04d4 | 192 | LPC_PINCON->PINSEL1 &= ~0x03C00000; //P0.27 - SDA. |
Kovalev_D |
23:12e6183f04d4 | 193 | LPC_PINCON->PINSEL1 |= 0x01400000; //P0.28 - SCK. |
Kovalev_D |
23:12e6183f04d4 | 194 | |
Kovalev_D |
23:12e6183f04d4 | 195 | // ïîäòâåðæäåíèå Ôëàã ôëàã ðàçðåøåíèÿ |
Kovalev_D |
23:12e6183f04d4 | 196 | /*ñáðîñ ôëàãîô ôëàãà ïðåðûâàíèÿ I2C ñòàðòà èíòåðôåéñà I2C */ |
Kovalev_D |
23:12e6183f04d4 | 197 | LPC_I2C0->CONCLR = I2CONCLR_AAC | I2CONCLR_SIC | I2CONCLR_STAC | I2CONCLR_I2ENC; // óñòàíîâêà ìèêðîêîíòðîëëåðà â ðåæèì ìàñòåðà |
Kovalev_D |
23:12e6183f04d4 | 198 | |
Kovalev_D |
23:12e6183f04d4 | 199 | /*--- Reset registers ---*/ |
Kovalev_D |
23:12e6183f04d4 | 200 | LPC_I2C0->SCLL = I2SCLL_SCLL; // - ñ÷åò÷èê scl low time period |
Kovalev_D |
23:12e6183f04d4 | 201 | LPC_I2C0->SCLH = I2SCLH_SCLH; // - ñ÷åò÷èê scl high time period |
Kovalev_D |
23:12e6183f04d4 | 202 | |
Kovalev_D |
23:12e6183f04d4 | 203 | I2CMasterBuffer[0] = A_ADDRESS; //àðåñ ïîòåíöèîìåòðà êàíàëà À |
Kovalev_D |
23:12e6183f04d4 | 204 | I2CMasterBuffer[1] = WRITE_CMD; //Äàííûå |
Kovalev_D |
23:12e6183f04d4 | 205 | I2CMasterBuffer[3] = B_ADDRESS; //àðåñ ïîòåíöèîìåòðà êàíàëà Â |
Kovalev_D |
23:12e6183f04d4 | 206 | I2CMasterBuffer[4] = WRITE_CMD; //Äàííûå |
Kovalev_D |
23:12e6183f04d4 | 207 | |
Kovalev_D |
23:12e6183f04d4 | 208 | LPC_I2C0->CONSET = I2CONSET_I2EN; //âêëþ÷åíèå èíòåðôåéñà I2C. |
Kovalev_D |
23:12e6183f04d4 | 209 | |
Kovalev_D |
23:12e6183f04d4 | 210 | } |
Kovalev_D |
23:12e6183f04d4 | 211 | /****************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 212 | ** Function name: DAC_ADC_Exchange_Init |
Kovalev_D |
23:12e6183f04d4 | 213 | ** |
Kovalev_D |
23:12e6183f04d4 | 214 | ** Descriptions: Initialization of data exchange with DACs and ADCs |
Kovalev_D |
23:12e6183f04d4 | 215 | ** |
Kovalev_D |
23:12e6183f04d4 | 216 | ** parameters: None |
Kovalev_D |
23:12e6183f04d4 | 217 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 218 | ** |
Kovalev_D |
23:12e6183f04d4 | 219 | ******************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 220 | void DAC_ADC_Exchange_Init() |
Kovalev_D |
23:12e6183f04d4 | 221 | { |
Kovalev_D |
23:12e6183f04d4 | 222 | |
Kovalev_D |
23:12e6183f04d4 | 223 | int Dummy; // èíèöèàëèçàöèÿ ìóñîðêè äëÿ î÷èñòêè áóôåðà ïðèåìà. |
Kovalev_D |
23:12e6183f04d4 | 224 | Dummy = Dummy; |
Kovalev_D |
23:12e6183f04d4 | 225 | |
Kovalev_D |
23:12e6183f04d4 | 226 | /* Enable AHB clock to the SSP0, SSP1 */ |
Kovalev_D |
23:12e6183f04d4 | 227 | LPC_SC->PCONP |= (0x1<<21); // âêëþ÷åíèå SSP0. |
Kovalev_D |
23:12e6183f04d4 | 228 | // LPC_SC->PCONP |= (0x1<<10); |
Kovalev_D |
23:12e6183f04d4 | 229 | |
Kovalev_D |
23:12e6183f04d4 | 230 | /* âûáîð ÷àñòîòû äëÿ ïåðåôåðèè èñïîëüçóåì ïî óìîë÷àíèÿ ñ äåëèòåëåì îñíîâíîé íà 4 */ |
Kovalev_D |
23:12e6183f04d4 | 231 | LPC_SC->PCLKSEL1 &= ~(0x3<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/8 |
Kovalev_D |
23:12e6183f04d4 | 232 | LPC_SC->PCLKSEL1 |= (0x0<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/8 |
Kovalev_D |
23:12e6183f04d4 | 233 | // LPC_SC->PCLKSEL0 &= ~(0x3<<20); |
Kovalev_D |
23:12e6183f04d4 | 234 | |
Kovalev_D |
23:12e6183f04d4 | 235 | // P0.15~0.18 as SSP0 |
Kovalev_D |
23:12e6183f04d4 | 236 | LPC_PINCON->PINSEL0 &= ~(0x3UL<<30); //óñòàíîâèò Ð 0.15 |
Kovalev_D |
23:12e6183f04d4 | 237 | LPC_PINCON->PINSEL0 |= (0x2UL<<30); //êàê (???? SCK 0 ???). ÷àñòîòà äëÿ ñèíõðîíèçàöèèè Master - slave |
Kovalev_D |
23:12e6183f04d4 | 238 | |
Kovalev_D |
23:12e6183f04d4 | 239 | LPC_PINCON->PINSEL1 &= ~((0x3<<0)|(0x3<<2)|(0x3<<4)); // óñòàíèâîèòü Ð 0.17 è Ð 0.18 |
Kovalev_D |
23:12e6183f04d4 | 240 | LPC_PINCON->PINSEL1 |= ((0x2<<2)|(0x2<<4)); // êàê MISO0 è MOSI0 |
Kovalev_D |
23:12e6183f04d4 | 241 | |
Kovalev_D |
23:12e6183f04d4 | 242 | LPC_PINCON->PINMODE0 &= ~(0x3UL<<30);// ? óñòàíîâëåíèå íà Ð 0.15 ðåæèìà On-Chip pull-down resistor enabled |
Kovalev_D |
23:12e6183f04d4 | 243 | LPC_PINCON->PINMODE0 |= (0x3UL<<30);// ? óñòàíîâëåíèå íà Ð 0.15 ðåæèìà On-Chip pull-down resistor enabled |
Kovalev_D |
23:12e6183f04d4 | 244 | |
Kovalev_D |
23:12e6183f04d4 | 245 | LPC_PINCON->PINMODE1 &= ~((0x3<<2)|(0x3<<4));// ? óñòàíîâëåíèå íà Ð 0.17 è Ð 0.18 ðåæèìà On-Chip pull-down resistor enabled |
Kovalev_D |
23:12e6183f04d4 | 246 | LPC_PINCON->PINMODE1 |= ((0x3<<2)|(0x3<<4));// ? óñòàíîâëåíèå íà Ð 0.17 è Ð 0.18 ðåæèìà On-Chip pull-down resistor enabled |
Kovalev_D |
23:12e6183f04d4 | 247 | |
Kovalev_D |
23:12e6183f04d4 | 248 | /* P0.6~0.9 as SSP1 */ |
Kovalev_D |
23:12e6183f04d4 | 249 | /* LPC_PINCON->PINSEL0 &= ~((0x3<<12)|(0x3<<14)|(0x3<<16)|(0x3<<18)); |
Kovalev_D |
23:12e6183f04d4 | 250 | LPC_PINCON->PINSEL0 |= ((0x2<<12)|(0x2<<14)|(0x2<<16)|(0x2<<18)); |
Kovalev_D |
23:12e6183f04d4 | 251 | LPC_PINCON->PINMODE0 &= ~((0x3<<16)|(0x3<<12)|(0x3<<14)|(0x3<<18)); |
Kovalev_D |
23:12e6183f04d4 | 252 | LPC_PINCON->PINMODE0 |= ((0x3<<16)|(0x3<<14)|(0x3<<18)); */ |
Kovalev_D |
23:12e6183f04d4 | 253 | |
Kovalev_D |
23:12e6183f04d4 | 254 | /* Set DSS data to 16-bit, Frame format TI, SCR is 2 */ |
Kovalev_D |
23:12e6183f04d4 | 255 | LPC_SSP0->CR0 = ((3<<8)|(0<<7)|(0<<4) |0xF); // (0xF)-óñòàíîâëåíèå DSS(Data sise select) â 16-áèòíûé ôîðìàò, (3<<8 scr - âûáîð ÷àñòîòû), |
Kovalev_D |
23:12e6183f04d4 | 256 | // íèçêèé óðîâåíü ëèíèè òàêòèðîâàíèÿ ìåæäó êàäðàìè, ïðèêðåïëåíèå ïåðåäà÷è ê ïåðâîìó íàðàñòàíèþ òàêòîâîãî ìèãíàëà |
Kovalev_D |
23:12e6183f04d4 | 257 | // ôîðìàò êàäðà TI. |
Kovalev_D |
23:12e6183f04d4 | 258 | // LPC_SSP1->CR0 = 0x0207; |
Kovalev_D |
23:12e6183f04d4 | 259 | |
Kovalev_D |
23:12e6183f04d4 | 260 | /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ |
Kovalev_D |
23:12e6183f04d4 | 261 | LPC_SSP0->CPSR = 0x2; // freq = CLK/(cpsdvr*(scr+1)) = 1.6 MHz |
Kovalev_D |
23:12e6183f04d4 | 262 | // LPC_SSP1->CPSR = 0x2; |
Kovalev_D |
23:12e6183f04d4 | 263 | |
Kovalev_D |
23:12e6183f04d4 | 264 | /*SSP enable, master mode */ |
Kovalev_D |
23:12e6183f04d4 | 265 | LPC_SSP0->CR1 = SSPCR1_SSE; |
Kovalev_D |
23:12e6183f04d4 | 266 | // LPC_SSP1->CR1 = SSPCR1_SSE; |
Kovalev_D |
23:12e6183f04d4 | 267 | |
Kovalev_D |
23:12e6183f04d4 | 268 | while (LPC_SSP0->SR & SSP_BUSY); |
Kovalev_D |
23:12e6183f04d4 | 269 | // while (LPC_SSP1->SR & SSP_BUSY); |
Kovalev_D |
23:12e6183f04d4 | 270 | |
Kovalev_D |
23:12e6183f04d4 | 271 | while (LPC_SSP0->SR & RX_SSP_notEMPT) /* clear the RxFIFO */ |
Kovalev_D |
23:12e6183f04d4 | 272 | Dummy = LPC_SSP0->DR; |
Kovalev_D |
23:12e6183f04d4 | 273 | //all pins after reset is in GPIO mode, so CS pins needn't to configure |
Kovalev_D |
23:12e6183f04d4 | 274 | LPC_GPIO0->FIODIR |= ADC; // P0.16 defined as CS for ADC |
Kovalev_D |
23:12e6183f04d4 | 275 | LPC_GPIO0->FIOSET |= ADC; // set CS for ADC |
Kovalev_D |
23:12e6183f04d4 | 276 | |
Kovalev_D |
23:12e6183f04d4 | 277 | LPC_GPIO0->FIODIR |= DAC; // P defined as CS for DAC |
Kovalev_D |
23:12e6183f04d4 | 278 | LPC_GPIO0->FIOCLR |= DAC; // set CS for DAC |
Kovalev_D |
23:12e6183f04d4 | 279 | /* while (LPC_SSP1->SR & RX_SSP_notEMPT) |
Kovalev_D |
23:12e6183f04d4 | 280 | Dummy = LPC_SSP1->DR;*/ /* clear the RxFIFO */ |
Kovalev_D |
23:12e6183f04d4 | 281 | } |
Kovalev_D |
23:12e6183f04d4 | 282 | /***************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 283 | ** Function name: DACInit |
Kovalev_D |
23:12e6183f04d4 | 284 | ** |
Kovalev_D |
23:12e6183f04d4 | 285 | ** Descriptions: initialize DAC channel |
Kovalev_D |
23:12e6183f04d4 | 286 | ** |
Kovalev_D |
23:12e6183f04d4 | 287 | ** parameters: None |
Kovalev_D |
23:12e6183f04d4 | 288 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 289 | ** |
Kovalev_D |
23:12e6183f04d4 | 290 | *****************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 291 | void DACInit( void ) |
Kovalev_D |
23:12e6183f04d4 | 292 | { |
Kovalev_D |
23:12e6183f04d4 | 293 | /* setup the related pin to DAC output */ |
Kovalev_D |
23:12e6183f04d4 | 294 | LPC_PINCON->PINSEL1 |= 0x00200000; /* óñòàíîâèòü p0.26 êàê âûõîä ÖÀÏ */ |
Kovalev_D |
23:12e6183f04d4 | 295 | // LPC_GPIO0->FIODIR |= (1<<26); |
Kovalev_D |
23:12e6183f04d4 | 296 | LPC_DAC->CNTVAL = 0; // êêàèåòî ïàðàìåòðû |
Kovalev_D |
23:12e6183f04d4 | 297 | LPC_DAC->CTRL = 0; // äëÿ ÄÌÀ |
Kovalev_D |
23:12e6183f04d4 | 298 | return; |
Kovalev_D |
23:12e6183f04d4 | 299 | } |
Kovalev_D |
23:12e6183f04d4 | 300 | /****************************************************************************** |
Kovalev_D |
23:12e6183f04d4 | 301 | ** Function name: Out_G_photo |
Kovalev_D |
23:12e6183f04d4 | 302 | ** |
Kovalev_D |
23:12e6183f04d4 | 303 | ** Descriptions: Start of potentiometer data writing process |
Kovalev_D |
23:12e6183f04d4 | 304 | ** |
Kovalev_D |
23:12e6183f04d4 | 305 | ** parameters: pointer to gain factors |
Kovalev_D |
23:12e6183f04d4 | 306 | ** Returned value: None |
Kovalev_D |
23:12e6183f04d4 | 307 | ** |
Kovalev_D |
23:12e6183f04d4 | 308 | ******************************************************************************/ |
Kovalev_D |
23:12e6183f04d4 | 309 | void Out_G_photo(uint32_t Ph_A, uint32_t Ph_B) |
Kovalev_D |
23:12e6183f04d4 | 310 | { |
Kovalev_D |
23:12e6183f04d4 | 311 | I2CMasterBuffer[2] = Ph_A;// çàïèñü â áóôåð I2C ìàñòåðà äàííûõ ñ À êàíàëà ôîòî äàò÷èêà.(óòî÷íèòü) |
Kovalev_D |
23:12e6183f04d4 | 312 | I2CMasterBuffer[5] = Ph_B;// çàïèñü â áóôåð I2C ìàñòåðà äàííûõ ñ  êàíàëà ôîòî äàò÷èêà.(óòî÷íèòü) |
Kovalev_D |
23:12e6183f04d4 | 313 | |
Kovalev_D |
23:12e6183f04d4 | 314 | LPC_I2C0->CONSET = I2CONSET_STA; // óñòàíîâèòü ñòàðò ôëàã. |
Kovalev_D |
23:12e6183f04d4 | 315 | I2CMasterState = I2C_BUSY; // óñòàíîâèòü ôëàã çàíÿòîé øèíû. |
Kovalev_D |
23:12e6183f04d4 | 316 | } |