123
Fork of LG by
InputOutput.c@22:12e6183f04d4, 2016-02-03 (annotated)
- Committer:
- Kovalev_D
- Date:
- Wed Feb 03 10:44:42 2016 +0300
- Revision:
- 22:12e6183f04d4
- Parent:
- 21:bc8c1cec3da6
- Child:
- 88:b5c1d9d338d1
[thyz
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 | |
igor_v | 21:bc8c1cec3da6 | 244 | /* P0.6~0.9 as SSP1 */ |
igor_v | 21:bc8c1cec3da6 | 245 | /* LPC_PINCON->PINSEL0 &= ~((0x3<<12)|(0x3<<14)|(0x3<<16)|(0x3<<18)); |
igor_v | 21:bc8c1cec3da6 | 246 | LPC_PINCON->PINSEL0 |= ((0x2<<12)|(0x2<<14)|(0x2<<16)|(0x2<<18)); |
igor_v | 21:bc8c1cec3da6 | 247 | LPC_PINCON->PINMODE0 &= ~((0x3<<16)|(0x3<<12)|(0x3<<14)|(0x3<<18)); |
igor_v | 21:bc8c1cec3da6 | 248 | LPC_PINCON->PINMODE0 |= ((0x3<<16)|(0x3<<14)|(0x3<<18)); */ |
igor_v | 0:8ad47e2b6f00 | 249 | |
igor_v | 21:bc8c1cec3da6 | 250 | /* Set DSS data to 16-bit, Frame format TI, SCR is 2 */ |
igor_v | 21:bc8c1cec3da6 | 251 | LPC_SSP0->CR0 = ((3<<8)|(0<<7)|(0<<4) |0xF); // (0xF)-ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ DSS(Data sise select) Π² 16-Π±ΠΈΡΠ½ΡΠΉ ΡΠΎΡΠΌΠ°Ρ, (3<<8 scr - Π²ΡΠ±ΠΎΡ ΡΠ°ΡΡΠΎΡΡ), |
igor_v | 21:bc8c1cec3da6 | 252 | // Π½ΠΈΠ·ΠΊΠΈΠΉ ΡΡΠΎΠ²Π΅Π½Ρ Π»ΠΈΠ½ΠΈΠΈ ΡΠ°ΠΊΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ ΠΌΠ΅ΠΆΠ΄Ρ ΠΊΠ°Π΄ΡΠ°ΠΌΠΈ, ΠΏΡΠΈΠΊΡΠ΅ΠΏΠ»Π΅Π½ΠΈΠ΅ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠΈ ΠΊ ΠΏΠ΅ΡΠ²ΠΎΠΌΡ Π½Π°ΡΠ°ΡΡΠ°Π½ΠΈΡ ΡΠ°ΠΊΡΠΎΠ²ΠΎΠ³ΠΎ ΠΌΠΈΠ³Π½Π°Π»Π° |
igor_v | 21:bc8c1cec3da6 | 253 | // ΡΠΎΡΠΌΠ°Ρ ΠΊΠ°Π΄ΡΠ° TI. |
igor_v | 21:bc8c1cec3da6 | 254 | // LPC_SSP1->CR0 = 0x0207; |
igor_v | 0:8ad47e2b6f00 | 255 | |
igor_v | 21:bc8c1cec3da6 | 256 | /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ |
igor_v | 21:bc8c1cec3da6 | 257 | LPC_SSP0->CPSR = 0x2; // freq = CLK/(cpsdvr*(scr+1)) = 1.6 MHz |
igor_v | 21:bc8c1cec3da6 | 258 | // LPC_SSP1->CPSR = 0x2; |
igor_v | 0:8ad47e2b6f00 | 259 | |
igor_v | 21:bc8c1cec3da6 | 260 | /*SSP enable, master mode */ |
igor_v | 21:bc8c1cec3da6 | 261 | LPC_SSP0->CR1 = SSPCR1_SSE; |
igor_v | 0:8ad47e2b6f00 | 262 | // LPC_SSP1->CR1 = SSPCR1_SSE; |
igor_v | 0:8ad47e2b6f00 | 263 | |
igor_v | 21:bc8c1cec3da6 | 264 | while (LPC_SSP0->SR & SSP_BUSY); |
igor_v | 0:8ad47e2b6f00 | 265 | // while (LPC_SSP1->SR & SSP_BUSY); |
igor_v | 0:8ad47e2b6f00 | 266 | |
igor_v | 21:bc8c1cec3da6 | 267 | while (LPC_SSP0->SR & RX_SSP_notEMPT) /* clear the RxFIFO */ |
igor_v | 21:bc8c1cec3da6 | 268 | Dummy = LPC_SSP0->DR; |
igor_v | 21:bc8c1cec3da6 | 269 | //all pins after reset is in GPIO mode, so CS pins needn't to configure |
igor_v | 21:bc8c1cec3da6 | 270 | LPC_GPIO0->FIODIR |= ADC; // P0.16 defined as CS for ADC |
igor_v | 21:bc8c1cec3da6 | 271 | LPC_GPIO0->FIOSET |= ADC; // set CS for ADC |
igor_v | 0:8ad47e2b6f00 | 272 | |
igor_v | 21:bc8c1cec3da6 | 273 | LPC_GPIO0->FIODIR |= DAC; // P defined as CS for DAC |
igor_v | 21:bc8c1cec3da6 | 274 | LPC_GPIO0->FIOCLR |= DAC; // set CS for DAC |
igor_v | 21:bc8c1cec3da6 | 275 | /* while (LPC_SSP1->SR & RX_SSP_notEMPT) |
igor_v | 21:bc8c1cec3da6 | 276 | Dummy = LPC_SSP1->DR;*/ /* clear the RxFIFO */ |
igor_v | 0:8ad47e2b6f00 | 277 | } |
igor_v | 0:8ad47e2b6f00 | 278 | /***************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 279 | ** Function name: DACInit |
igor_v | 0:8ad47e2b6f00 | 280 | ** |
igor_v | 0:8ad47e2b6f00 | 281 | ** Descriptions: initialize DAC channel |
igor_v | 0:8ad47e2b6f00 | 282 | ** |
igor_v | 0:8ad47e2b6f00 | 283 | ** parameters: None |
igor_v | 0:8ad47e2b6f00 | 284 | ** Returned value: None |
igor_v | 21:bc8c1cec3da6 | 285 | ** |
igor_v | 0:8ad47e2b6f00 | 286 | *****************************************************************************/ |
igor_v | 0:8ad47e2b6f00 | 287 | void DACInit( void ) |
igor_v | 0:8ad47e2b6f00 | 288 | { |
igor_v | 21:bc8c1cec3da6 | 289 | /* setup the related pin to DAC output */ |
igor_v | 21:bc8c1cec3da6 | 290 | LPC_PINCON->PINSEL1 |= 0x00200000; /* ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ p0.26 ΠΊΠ°ΠΊ Π²ΡΡ ΠΎΠ΄ Π¦ΠΠ */ |
igor_v | 21:bc8c1cec3da6 | 291 | // LPC_GPIO0->FIODIR |= (1<<26); |
igor_v | 21:bc8c1cec3da6 | 292 | LPC_DAC->CNTVAL = 0; // ΠΊΠΊΠ°ΠΈΠ΅ΡΠΎ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ |
igor_v | 21:bc8c1cec3da6 | 293 | LPC_DAC->CTRL = 0; // Π΄Π»Ρ ΠΠΠ |
igor_v | 21:bc8c1cec3da6 | 294 | return; |
igor_v | 0:8ad47e2b6f00 | 295 | } |
igor_v | 0:8ad47e2b6f00 | 296 | /****************************************************************************** |
igor_v | 0:8ad47e2b6f00 | 297 | ** Function name: Out_G_photo |
igor_v | 0:8ad47e2b6f00 | 298 | ** |
igor_v | 0:8ad47e2b6f00 | 299 | ** Descriptions: Start of potentiometer data writing process |
igor_v | 0:8ad47e2b6f00 | 300 | ** |
igor_v | 0:8ad47e2b6f00 | 301 | ** parameters: pointer to gain factors |
igor_v | 0:8ad47e2b6f00 | 302 | ** Returned value: None |
igor_v | 21:bc8c1cec3da6 | 303 | ** |
igor_v | 0:8ad47e2b6f00 | 304 | ******************************************************************************/ |
igor_v | 0:8ad47e2b6f00 | 305 | void Out_G_photo(uint32_t Ph_A, uint32_t Ph_B) |
igor_v | 0:8ad47e2b6f00 | 306 | { |
igor_v | 21:bc8c1cec3da6 | 307 | I2CMasterBuffer[2] = Ph_A;// Π·Π°ΠΏΠΈΡΡ Π² Π±ΡΡΠ΅Ρ I2C ΠΌΠ°ΡΡΠ΅ΡΠ° Π΄Π°Π½Π½ΡΡ Ρ Π ΠΊΠ°Π½Π°Π»Π° ΡΠΎΡΠΎ Π΄Π°ΡΡΠΈΠΊΠ°.(ΡΡΠΎΡΠ½ΠΈΡΡ) |
igor_v | 21:bc8c1cec3da6 | 308 | I2CMasterBuffer[5] = Ph_B;// Π·Π°ΠΏΠΈΡΡ Π² Π±ΡΡΠ΅Ρ I2C ΠΌΠ°ΡΡΠ΅ΡΠ° Π΄Π°Π½Π½ΡΡ Ρ Π ΠΊΠ°Π½Π°Π»Π° ΡΠΎΡΠΎ Π΄Π°ΡΡΠΈΠΊΠ°.(ΡΡΠΎΡΠ½ΠΈΡΡ) |
igor_v | 0:8ad47e2b6f00 | 309 | |
igor_v | 21:bc8c1cec3da6 | 310 | LPC_I2C0->CONSET = I2CONSET_STA; // ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ ΡΡΠ°ΡΡ ΡΠ»Π°Π³. |
igor_v | 21:bc8c1cec3da6 | 311 | I2CMasterState = I2C_BUSY; // ΡΡΡΠ°Π½ΠΎΠ²ΠΈΡΡ ΡΠ»Π°Π³ Π·Π°Π½ΡΡΠΎΠΉ ΡΠΈΠ½Ρ. |
igor_v | 21:bc8c1cec3da6 | 312 | } |
igor_v | 0:8ad47e2b6f00 | 313 |