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