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