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