![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork
Fork of LG by
Global.c@199:2728719cdc64, 2016-10-20 (annotated)
- Committer:
- Kovalev_D
- Date:
- Thu Oct 20 09:32:25 2016 +0000
- Revision:
- 199:2728719cdc64
- Parent:
- 198:fb22ba6aad54
- Child:
- 200:1df682165694
lkmp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igor_v | 0:8ad47e2b6f00 | 1 | #include "Global.h" |
igor_v | 0:8ad47e2b6f00 | 2 | |
igor_v | 0:8ad47e2b6f00 | 3 | |
igor_v | 0:8ad47e2b6f00 | 4 | |
Kovalev_D | 89:a0d344db227e | 5 | unsigned int VibroReg = 0; //регистр состаяния вибропривода. |
Kovalev_D | 89:a0d344db227e | 6 | unsigned long Global_Time, Time_UART,Time_Sec,Time_vibro,Time_1kHz; |
Kovalev_D | 197:7a05523bf588 | 7 | float t1; |
Kovalev_D | 89:a0d344db227e | 8 | unsigned char BuffTemp[100]; |
Kovalev_D | 199:2728719cdc64 | 9 | unsigned char Time[1000]; |
Kovalev_D | 86:398da56ef751 | 10 | unsigned int Event1Hz; |
Kovalev_D | 124:9ae09249f842 | 11 | unsigned int Event500Hz; |
Kovalev_D | 88:b5c1d9d338d1 | 12 | unsigned int Event1K ; |
Kovalev_D | 88:b5c1d9d338d1 | 13 | unsigned int Event100K; |
Kovalev_D | 88:b5c1d9d338d1 | 14 | unsigned int EventVibro; |
Kovalev_D | 124:9ae09249f842 | 15 | |
Kovalev_D | 197:7a05523bf588 | 16 | unsigned int Time250Hz; |
Kovalev_D | 197:7a05523bf588 | 17 | unsigned int Event250Hz; |
Kovalev_D | 197:7a05523bf588 | 18 | |
Kovalev_D | 124:9ae09249f842 | 19 | unsigned int Time100K; |
Kovalev_D | 88:b5c1d9d338d1 | 20 | unsigned int Time1K; |
Kovalev_D | 124:9ae09249f842 | 21 | unsigned int Time500Hz; |
Kovalev_D | 88:b5c1d9d338d1 | 22 | unsigned int Time1Hz; |
Kovalev_D | 88:b5c1d9d338d1 | 23 | unsigned int Clock1Hz; |
Kovalev_D | 86:398da56ef751 | 24 | unsigned int ShiftD; |
Kovalev_D | 86:398da56ef751 | 25 | unsigned int ShiftL; |
Kovalev_D | 197:7a05523bf588 | 26 | unsigned int EventMod; |
Kovalev_D | 140:1fbf117fc120 | 27 | |
Kovalev_D | 139:1716152517aa | 28 | |
Kovalev_D | 134:caf4c9cd5052 | 29 | __asm void boot_jump( uint32_t address ){ |
Kovalev_D | 134:caf4c9cd5052 | 30 | LDR SP, [R0] ;Load new stack pointer address |
Kovalev_D | 134:caf4c9cd5052 | 31 | LDR R0, [R0, #4] ;Load new program counter address |
Kovalev_D | 134:caf4c9cd5052 | 32 | BX R0 |
Kovalev_D | 134:caf4c9cd5052 | 33 | } |
Kovalev_D | 134:caf4c9cd5052 | 34 | |
Kovalev_D | 86:398da56ef751 | 35 | void GLD_Init(void) |
Kovalev_D | 197:7a05523bf588 | 36 | { |
Kovalev_D | 197:7a05523bf588 | 37 | InitMOD(); |
Kovalev_D | 183:7e200f4d9b16 | 38 | Gyro.DropDelayGLD = DropDelayGLD_0;//задержка на выдачу 45 микросекунд для любого адреса ГЛД |
Kovalev_D | 90:d9b6a4bc5065 | 39 | int Dummy; // инициализация мусорки для очистки буфера приема. |
Kovalev_D | 89:a0d344db227e | 40 | ///////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 41 | ///////////инициализация таймеров//////////// |
Kovalev_D | 89:a0d344db227e | 42 | ///////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 43 | Init_TIM1(TIME_INTERVAL ); //Timer 1: CCLK / 7812 = 12800.819Hz; Vibro: Timer1/32 = 400.025Hz; 10ms??? |
Kovalev_D | 89:a0d344db227e | 44 | Init_TIM2(); //Timer 2: CCLK / 4 / 250 = 100kHz |
Kovalev_D | 89:a0d344db227e | 45 | ///////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 46 | ///////////////////////////////////////////// |
Kovalev_D | 104:ab1cb4ff56b2 | 47 | Gyro.RgConA = 0xffff; |
Kovalev_D | 104:ab1cb4ff56b2 | 48 | Gyro.RgConB = 0xffff; |
Kovalev_D | 86:398da56ef751 | 49 | ///////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 50 | ///////////обнуление счетчиков/////////////// |
Kovalev_D | 86:398da56ef751 | 51 | ///////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 52 | Global_Time = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 53 | Time_UART = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 54 | Time_Sec = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 55 | Time_vibro = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 56 | Time_1kHz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 57 | Event1Hz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 58 | Event1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 59 | Event100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 60 | EventVibro = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 61 | Time1K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 62 | Time100K = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 63 | Time1Hz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 64 | Clock1Hz = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 65 | ShiftD = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 66 | ShiftL = 0; |
Kovalev_D | 124:9ae09249f842 | 67 | Event500Hz = 0; |
Kovalev_D | 124:9ae09249f842 | 68 | Time500Hz = 0; |
Kovalev_D | 139:1716152517aa | 69 | |
Kovalev_D | 86:398da56ef751 | 70 | ///////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 71 | ///////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 72 | |
Kovalev_D | 197:7a05523bf588 | 73 | // ModArray[]=[32,64,96,128,256,384,448,480,496,512,512]; |
Kovalev_D | 88:b5c1d9d338d1 | 74 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 75 | /////////////обнуление переменых для///////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 76 | ///////////расчета значений буферов ВП/////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 77 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 78 | /////////////инициализация переменных в структ вибро///////////////// |
Kovalev_D | 197:7a05523bf588 | 79 | |
Kovalev_D | 132:2c7bec5cf6fe | 80 | Gyro.FlashMod=0; |
Kovalev_D | 196:f76dbc081e63 | 81 | Gyro.FrqHZ=388; |
Kovalev_D | 88:b5c1d9d338d1 | 82 | Gyro.Frq = Gyro.FrqHZ<<16; |
Kovalev_D | 189:8a16378724c4 | 83 | Gyro.FrqHZmin = 350<<16; |
Kovalev_D | 189:8a16378724c4 | 84 | Gyro.FrqHZmax = 450<<16; |
Kovalev_D | 196:f76dbc081e63 | 85 | Gyro.FrqChengSpeed=100; |
Kovalev_D | 197:7a05523bf588 | 86 | Gyro.ModAmp=250; |
Kovalev_D | 191:40028201ddad | 87 | Gyro.AmpPer=40; |
Kovalev_D | 197:7a05523bf588 | 88 | Gyro.AmpPerMin = 5; |
Kovalev_D | 189:8a16378724c4 | 89 | Gyro.AmpPerMax = 90; |
Kovalev_D | 189:8a16378724c4 | 90 | Gyro.AmpSpeed = 1; |
Kovalev_D | 196:f76dbc081e63 | 91 | Gyro.AmpPerDel=10; |
Kovalev_D | 197:7a05523bf588 | 92 | Gyro.AmpTarget =8000;// целевая амплитуда ВП |
Kovalev_D | 196:f76dbc081e63 | 93 | Gyro.Amp = 30*65535; |
Kovalev_D | 196:f76dbc081e63 | 94 | Gyro.AmpMin =15;// минимальное значение AmpT;5 |
Kovalev_D | 196:f76dbc081e63 | 95 | Gyro.AmpTD =30;//////////////////////////////////////////////////////// |
Kovalev_D | 106:250ddd8629c6 | 96 | Gyro.CuruAngle = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 97 | Pulse_8Point = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 98 | Pulse_16Point = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 99 | Pulse_16PointD = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 100 | Pulse_32Point = 0; |
Kovalev_D | 195:bcc769f5292b | 101 | |
Kovalev_D | 196:f76dbc081e63 | 102 | Gyro.flag=1; |
Kovalev_D | 88:b5c1d9d338d1 | 103 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 104 | /////////////предварительное заполнение////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 105 | ////////////////буферов вибропривода///////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 106 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 107 | for (int i = 0; i < 32; i++ ) { |
Kovalev_D | 88:b5c1d9d338d1 | 108 | Buff_16Point[i] = 0x00; |
Kovalev_D | 88:b5c1d9d338d1 | 109 | Buff_8Point[i] = 0x00; |
Kovalev_D | 88:b5c1d9d338d1 | 110 | Buff_32Point[i] = 0x00; |
Kovalev_D | 88:b5c1d9d338d1 | 111 | Buff_16PointD[i] = 0x00; |
Kovalev_D | 197:7a05523bf588 | 112 | GyroP.Array[i] = 0x00; |
Kovalev_D | 129:406995a91322 | 113 | } |
Kovalev_D | 197:7a05523bf588 | 114 | for (int i = 0; i < 64; i++ ) { |
Kovalev_D | 197:7a05523bf588 | 115 | BuffADC_16Point[CountV64]=0x00; |
Kovalev_D | 197:7a05523bf588 | 116 | BuffADC_32Point[CountV64]=0x00; |
Kovalev_D | 197:7a05523bf588 | 117 | BuffADC_32PointD[CountV64]=0x00; |
Kovalev_D | 197:7a05523bf588 | 118 | BuffADC_64Point[CountV64]=0x00; |
Kovalev_D | 197:7a05523bf588 | 119 | } |
Kovalev_D | 197:7a05523bf588 | 120 | PulseADC_64Point=0; |
Kovalev_D | 88:b5c1d9d338d1 | 121 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 122 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 123 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 124 | /////////////обнуление переменых для///////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 125 | //////////////////переменных АЦП///////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 126 | ///////////////////////////////////////////////////// |
Kovalev_D | 96:1c8536458119 | 127 | Temp_AMP64P=0; |
Kovalev_D | 88:b5c1d9d338d1 | 128 | Temp_ADC_2=0; |
Kovalev_D | 88:b5c1d9d338d1 | 129 | Temp_ADC_3=0; |
Kovalev_D | 88:b5c1d9d338d1 | 130 | Temp_ADC_4=0; |
Kovalev_D | 88:b5c1d9d338d1 | 131 | Temp_ADC_5=0; |
Kovalev_D | 197:7a05523bf588 | 132 | |
Kovalev_D | 197:7a05523bf588 | 133 | |
Kovalev_D | 197:7a05523bf588 | 134 | |
Kovalev_D | 197:7a05523bf588 | 135 | Gyro.Gain_Sin =115; |
Kovalev_D | 197:7a05523bf588 | 136 | Gyro.Gain_Cos =175; |
Kovalev_D | 197:7a05523bf588 | 137 | |
Kovalev_D | 197:7a05523bf588 | 138 | |
Kovalev_D | 196:f76dbc081e63 | 139 | |
Kovalev_D | 88:b5c1d9d338d1 | 140 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 141 | /////////////предварительное заполнение////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 142 | /////////////////////буферов АЦП///////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 143 | ///////////////////////////////////////////////////// |
Kovalev_D | 95:dd51e577e114 | 144 | for (int i = 0; i < 32; i++ ) { |
Kovalev_D | 88:b5c1d9d338d1 | 145 | Buff_ADC_1[i] = 0; // ампл ацп. |
Kovalev_D | 88:b5c1d9d338d1 | 146 | Buff_ADC_2[i] = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 147 | Buff_ADC_3[i] = 0; |
Kovalev_D | 88:b5c1d9d338d1 | 148 | Buff_ADC_4[i] = 0; |
Kovalev_D | 95:dd51e577e114 | 149 | } |
Kovalev_D | 95:dd51e577e114 | 150 | for (int i = 0; i < 256; i++ ) { |
Kovalev_D | 95:dd51e577e114 | 151 | Buff_ADC_5[i]= 0; |
Kovalev_D | 88:b5c1d9d338d1 | 152 | } |
Kovalev_D | 96:1c8536458119 | 153 | for (int i = 0; i < 256; i++ ) { |
Kovalev_D | 96:1c8536458119 | 154 | Buff_AMP64P[i]= 0; |
Kovalev_D | 96:1c8536458119 | 155 | } |
Kovalev_D | 96:1c8536458119 | 156 | for (int i = 0; i < 256; i++ ) { |
Kovalev_D | 96:1c8536458119 | 157 | Buff_AMP[i]= 0; |
Kovalev_D | 96:1c8536458119 | 158 | } |
Kovalev_D | 88:b5c1d9d338d1 | 159 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 160 | //////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 161 | |
Kovalev_D | 88:b5c1d9d338d1 | 162 | Gyro.SOC_Out=0xDD; |
Kovalev_D | 188:4c523cc373cc | 163 | Gyro.Firmware_Version = 0x11; //версия программы |
Kovalev_D | 163:affb5706d191 | 164 | Gyro.GLD_Serial = 0xD7; //серийный номер |
Kovalev_D | 182:ebcd2bc3be8f | 165 | Gyro.My_Addres = 0; //адрес глд |
Kovalev_D | 92:c892f0311aa7 | 166 | |
Kovalev_D | 188:4c523cc373cc | 167 | switch(Gyro.My_Addres){//смещение поджига и подсветки в зависимости от адреса ГЛД |
Kovalev_D | 188:4c523cc373cc | 168 | case 0: |
Kovalev_D | 188:4c523cc373cc | 169 | Gyro.Discharg = StartDischarg << ShiftStart0; |
Kovalev_D | 188:4c523cc373cc | 170 | Gyro.BackLight = StartBackLight << ShiftStart0; |
Kovalev_D | 188:4c523cc373cc | 171 | break; |
Kovalev_D | 188:4c523cc373cc | 172 | case 1: |
Kovalev_D | 188:4c523cc373cc | 173 | Gyro.Discharg = StartDischarg << ShiftStart1; |
Kovalev_D | 188:4c523cc373cc | 174 | Gyro.BackLight = StartBackLight << ShiftStart1; |
Kovalev_D | 188:4c523cc373cc | 175 | break; |
Kovalev_D | 188:4c523cc373cc | 176 | case 2: |
Kovalev_D | 188:4c523cc373cc | 177 | Gyro.Discharg = StartDischarg << ShiftStart2; |
Kovalev_D | 188:4c523cc373cc | 178 | Gyro.BackLight = StartBackLight << ShiftStart2; |
Kovalev_D | 188:4c523cc373cc | 179 | break; |
Kovalev_D | 188:4c523cc373cc | 180 | case 3: |
Kovalev_D | 188:4c523cc373cc | 181 | Gyro.Discharg = StartDischarg << ShiftStart3; |
Kovalev_D | 188:4c523cc373cc | 182 | Gyro.BackLight = StartBackLight << ShiftStart3; |
Kovalev_D | 188:4c523cc373cc | 183 | break; |
Kovalev_D | 188:4c523cc373cc | 184 | } |
Kovalev_D | 89:a0d344db227e | 185 | |
Kovalev_D | 88:b5c1d9d338d1 | 186 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 187 | //////инициализация цап_LPC (р0.26 цап выход)//////// |
Kovalev_D | 88:b5c1d9d338d1 | 188 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 189 | LPC_PINCON->PINSEL1 = 0x00200000; |
Kovalev_D | 88:b5c1d9d338d1 | 190 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 191 | ////////////начальное значение для цап/////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 192 | //////////////////середина шкалы///////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 193 | ///////////////////////////////////////////////////// |
Kovalev_D | 159:38f39c0c143f | 194 | |
Kovalev_D | 196:f76dbc081e63 | 195 | Gyro.Ktermo=1;// K° |
Kovalev_D | 197:7a05523bf588 | 196 | Gyro.TermoNKU=44700;//48824*0,0061-273=25 С° |
Kovalev_D | 197:7a05523bf588 | 197 | Spi.DAC_A = 41000; |
Kovalev_D | 197:7a05523bf588 | 198 | |
Kovalev_D | 197:7a05523bf588 | 199 | Spi.DAC_B = 35220; |
Kovalev_D | 158:0c8342e1837a | 200 | |
Kovalev_D | 196:f76dbc081e63 | 201 | Gyro.StrayHZ = 200; |
Kovalev_D | 159:38f39c0c143f | 202 | Gyro.StrayHZ_flag = 0; |
Kovalev_D | 159:38f39c0c143f | 203 | Gyro.LogHZ = 0; |
Kovalev_D | 199:2728719cdc64 | 204 | |
Kovalev_D | 192:d32c8cf7bcd9 | 205 | Gyro.StrayPLC_Pls = 1000; |
Kovalev_D | 159:38f39c0c143f | 206 | Gyro.StrayPLC_Mns = -1000; |
Kovalev_D | 159:38f39c0c143f | 207 | Gyro.StrayPLC_2Mode = 2000; |
Kovalev_D | 159:38f39c0c143f | 208 | Gyro.StrayPLC_flag = 0; |
Kovalev_D | 159:38f39c0c143f | 209 | Gyro.LogPLC = 0; |
Kovalev_D | 159:38f39c0c143f | 210 | Gyro.PLC_Lern = 0; |
Kovalev_D | 168:f4a6abb18358 | 211 | Gyro.ModJump = 0; |
Kovalev_D | 197:7a05523bf588 | 212 | Gyro.PLC_Error2Mode =1400; //для записи мод |
Kovalev_D | 159:38f39c0c143f | 213 | //Gyro.PLC_Error2Mode = 65; //стандартное включение прибора регулировка (65 начальная задержка для поиска АМП мах) |
Kovalev_D | 86:398da56ef751 | 214 | //////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 215 | /////////////поправочный коэффициент///////////////// |
Kovalev_D | 86:398da56ef751 | 216 | /////////для цапов (граници +-12.5 вольт)//////////// |
Kovalev_D | 86:398da56ef751 | 217 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 218 | K_DAC=65535.0/(65535.0+(deltaDAC+deltaDAC/2)); |
Kovalev_D | 86:398da56ef751 | 219 | K_DAC=0.8; |
Kovalev_D | 88:b5c1d9d338d1 | 220 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 221 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 222 | |
Kovalev_D | 86:398da56ef751 | 223 | secPuls =0;// переменная для конопки поджига аск глд(временная) |
Kovalev_D | 88:b5c1d9d338d1 | 224 | |
Kovalev_D | 86:398da56ef751 | 225 | ///////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 226 | /////////////обнуление переменых для///////////////// |
Kovalev_D | 86:398da56ef751 | 227 | ///////////////переменных энкодера/////////////////// |
Kovalev_D | 86:398da56ef751 | 228 | ///////////////////////////////////////////////////// |
Kovalev_D | 112:4a96133a1311 | 229 | Gyro.CaunPlus =0; |
Kovalev_D | 112:4a96133a1311 | 230 | Gyro.CaunMin =0; |
Kovalev_D | 88:b5c1d9d338d1 | 231 | Cur_QEI=0; |
Kovalev_D | 86:398da56ef751 | 232 | Last_QEI=0; |
Kovalev_D | 86:398da56ef751 | 233 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 234 | /////////////инициализация энкодера////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 235 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 236 | LPC_SC->PCONP |= (1<<18);//0x00040000; включение квадратурного энкодера. |
Kovalev_D | 170:d099c3025f87 | 237 | LPC_SC->PCLKSEL1 |= 0x00000001; // выбор частоты для кв.э. CLK=103MHz |
Kovalev_D | 87:7e575d26d6d0 | 238 | LPC_PINCON->PINSEL3 &= ~0x4100; |
Kovalev_D | 87:7e575d26d6d0 | 239 | LPC_PINCON->PINSEL3 |= 0x4100; //P1.20, p1.23 установить как входы кв.э |
Kovalev_D | 89:a0d344db227e | 240 | LPC_PINCON->PINMODE3 |= 0x3C300; //P1.20, p1.23 |
Kovalev_D | 86:398da56ef751 | 241 | |
Kovalev_D | 98:95b8e79f13e1 | 242 | |
Kovalev_D | 87:7e575d26d6d0 | 243 | LPC_QEI->MAXPOS = MAX_QEI_CNT; //LPC_QEI->"регистор максимального положения" = 2147483646 |
Kovalev_D | 89:a0d344db227e | 244 | LPC_QEI->FILTER = 2; // фильтр( ?? ) |
Kovalev_D | 87:7e575d26d6d0 | 245 | LPC_QEI->CON = 0xF; //сбросить в ноль все счетчики кв.э. (скорость, направление, позицию и тд) |
Kovalev_D | 87:7e575d26d6d0 | 246 | LPC_QEI->CONF = (0<<2) |(0<<1); //Quadrature inputs, no inverting,only A pulses are counted |
Kovalev_D | 87:7e575d26d6d0 | 247 | |
Kovalev_D | 87:7e575d26d6d0 | 248 | LPC_QEI->CLR = 0x1fff; //r. сбросить все прерывания |
Kovalev_D | 87:7e575d26d6d0 | 249 | LPC_QEI->IEC = 0x1fff; //r. запретить прерывание при изменении направления |
Kovalev_D | 87:7e575d26d6d0 | 250 | |
Kovalev_D | 98:95b8e79f13e1 | 251 | /*NVIC_SetPriority(QEI_IRQn, 0); |
Kovalev_D | 98:95b8e79f13e1 | 252 | NVIC_EnableIRQ(QEI_IRQn);*/ |
Kovalev_D | 88:b5c1d9d338d1 | 253 | ////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 254 | ////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 255 | |
Kovalev_D | 88:b5c1d9d338d1 | 256 | |
Kovalev_D | 89:a0d344db227e | 257 | ////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 258 | ///////////////////////I2C//////////////////////////// |
Kovalev_D | 89:a0d344db227e | 259 | ////////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 260 | |
Kovalev_D | 89:a0d344db227e | 261 | LPC_SC->PCONP |= (1 << 19);//включение интерфейса I2C. |
Kovalev_D | 88:b5c1d9d338d1 | 262 | |
Kovalev_D | 89:a0d344db227e | 263 | /* set PIO0.27 and PIO0.28 to I2C0 SDA and SCK */ |
Kovalev_D | 89:a0d344db227e | 264 | /* function to 01 on both SDA and SCK. */ |
Kovalev_D | 89:a0d344db227e | 265 | LPC_PINCON->PINSEL1 &= ~0x03C00000; //P0.27 - SDA. |
Kovalev_D | 89:a0d344db227e | 266 | LPC_PINCON->PINSEL1 |= 0x01400000; //P0.28 - SCK. |
Kovalev_D | 86:398da56ef751 | 267 | |
Kovalev_D | 89:a0d344db227e | 268 | // подтверждение Флаг флаг разрешения |
Kovalev_D | 89:a0d344db227e | 269 | /*сброс флагоф флага прерывания I2C старта интерфейса I2C */ |
Kovalev_D | 89:a0d344db227e | 270 | LPC_I2C0->CONCLR = I2CONCLR_AAC | I2CONCLR_SIC | I2CONCLR_STAC | I2CONCLR_I2ENC; // установка микроконтроллера в режим мастера |
Kovalev_D | 86:398da56ef751 | 271 | |
Kovalev_D | 89:a0d344db227e | 272 | /*--- Reset registers ---*/ |
Kovalev_D | 89:a0d344db227e | 273 | LPC_I2C0->SCLL = I2SCLL_SCLL; // - счетчик scl low time period |
Kovalev_D | 89:a0d344db227e | 274 | LPC_I2C0->SCLH = I2SCLH_SCLH; // - счетчик scl high time period |
Kovalev_D | 99:3d8f206ceac2 | 275 | |
Kovalev_D | 99:3d8f206ceac2 | 276 | I2CMasterBuffer[0] = A_ADDRESS; |
Kovalev_D | 99:3d8f206ceac2 | 277 | I2CMasterBuffer[1] = WRITE_CMD; |
Kovalev_D | 99:3d8f206ceac2 | 278 | I2CMasterBuffer[3] = B_ADDRESS; |
Kovalev_D | 99:3d8f206ceac2 | 279 | I2CMasterBuffer[4] = WRITE_CMD; |
Kovalev_D | 99:3d8f206ceac2 | 280 | |
Kovalev_D | 89:a0d344db227e | 281 | LPC_I2C0->CONSET = I2CONSET_I2EN; //включение интерфейса I2C. |
Kovalev_D | 89:a0d344db227e | 282 | ////////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 283 | ////////////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 284 | |
Kovalev_D | 86:398da56ef751 | 285 | |
Kovalev_D | 86:398da56ef751 | 286 | |
Kovalev_D | 92:c892f0311aa7 | 287 | |
Kovalev_D | 92:c892f0311aa7 | 288 | |
Kovalev_D | 92:c892f0311aa7 | 289 | |
Kovalev_D | 92:c892f0311aa7 | 290 | /////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 291 | /////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 292 | //////////////////////////SPI////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 293 | /////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 294 | Dummy = Dummy; |
Kovalev_D | 92:c892f0311aa7 | 295 | |
Kovalev_D | 92:c892f0311aa7 | 296 | /* Enable AHB clock to the SSP0, SSP1 */ |
Kovalev_D | 92:c892f0311aa7 | 297 | LPC_SC->PCONP |= (0x1<<21); // включение SSP0. |
Kovalev_D | 92:c892f0311aa7 | 298 | |
Kovalev_D | 92:c892f0311aa7 | 299 | /* выбор частоты для переферии используем по умолчания с делителем основной на 4 */ |
Kovalev_D | 92:c892f0311aa7 | 300 | LPC_SC->PCLKSEL1 &= ~(0x3<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/8 |
Kovalev_D | 92:c892f0311aa7 | 301 | LPC_SC->PCLKSEL1 |= (0x0<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/ |
Kovalev_D | 92:c892f0311aa7 | 302 | |
Kovalev_D | 92:c892f0311aa7 | 303 | // P0.15~0.18 as SSP0 |
Kovalev_D | 92:c892f0311aa7 | 304 | LPC_PINCON->PINSEL0 &= ~(0x3UL<<30); //установит Р 0.15 |
Kovalev_D | 92:c892f0311aa7 | 305 | LPC_PINCON->PINSEL0 |= (0x2UL<<30); //частота для синхронизациии Master - slave |
Kovalev_D | 92:c892f0311aa7 | 306 | |
Kovalev_D | 92:c892f0311aa7 | 307 | LPC_PINCON->PINSEL1 &= ~((0x3<<0)|(0x3<<2)|(0x3<<4)); // устанивоить Р 0.17 и Р 0.18 |
Kovalev_D | 92:c892f0311aa7 | 308 | LPC_PINCON->PINSEL1 |= ((0x2<<2)|(0x2<<4)); // как MISO0 и MOSI0 |
Kovalev_D | 92:c892f0311aa7 | 309 | |
Kovalev_D | 92:c892f0311aa7 | 310 | LPC_PINCON->PINMODE0 &= ~(0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 311 | LPC_PINCON->PINMODE0 |= (0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 312 | |
Kovalev_D | 92:c892f0311aa7 | 313 | LPC_PINCON->PINMODE1 &= ~((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 314 | LPC_PINCON->PINMODE1 |= ((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 92:c892f0311aa7 | 315 | |
Kovalev_D | 92:c892f0311aa7 | 316 | LPC_SSP0->CR0 = ((3<<8)|(0<<7)|(0<<4) |0xF); // (0xF)-установление DSS(Data sise select) в 16-битный формат, (3<<8 scr - выбор частоты), |
Kovalev_D | 92:c892f0311aa7 | 317 | // низкий уровень линии тактирования между кадрами, прикрепление передачи к первому нарастанию тактового мигнала |
Kovalev_D | 92:c892f0311aa7 | 318 | // формат кадра TI. |
Kovalev_D | 92:c892f0311aa7 | 319 | |
Kovalev_D | 92:c892f0311aa7 | 320 | /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ |
Kovalev_D | 92:c892f0311aa7 | 321 | LPC_SSP0->CPSR = 0x2; // freq = CLK/(cpsdvr*(scr+1)) = 1.6 MHz |
Kovalev_D | 92:c892f0311aa7 | 322 | |
Kovalev_D | 92:c892f0311aa7 | 323 | /*SSP enable, master mode */ |
Kovalev_D | 92:c892f0311aa7 | 324 | LPC_SSP0->CR1 = SSPCR1_SSE; |
Kovalev_D | 92:c892f0311aa7 | 325 | // LPC_SSP1->CR1 = SSPCR1_SSE; |
Kovalev_D | 190:289514f730ee | 326 | while (LPC_SSP0->SR & SSP_BUSY); |
Kovalev_D | 92:c892f0311aa7 | 327 | while (LPC_SSP0->SR & RX_SSP_notEMPT) /* clear the RxFIFO */ |
Kovalev_D | 92:c892f0311aa7 | 328 | Dummy = LPC_SSP0->DR; |
Kovalev_D | 92:c892f0311aa7 | 329 | //all pins after reset is in GPIO mode, so CS pins needn't to configure |
Kovalev_D | 92:c892f0311aa7 | 330 | LPC_GPIO0->FIODIR |= (1<<16); // P0.16 defined as CS for ADC |
Kovalev_D | 92:c892f0311aa7 | 331 | LPC_GPIO0->FIOSET |= (1<<16); // set CS for ADC |
Kovalev_D | 92:c892f0311aa7 | 332 | |
Kovalev_D | 92:c892f0311aa7 | 333 | LPC_GPIO0->FIODIR |= (1<<23); // P defined as CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 334 | LPC_GPIO0->FIOCLR |= (1<<23); // set CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 335 | while (LPC_SSP1->SR & RX_SSP_notEMPT) |
Kovalev_D | 92:c892f0311aa7 | 336 | Dummy = LPC_SSP1->DR; /* clear the RxFIFO */ |
Kovalev_D | 92:c892f0311aa7 | 337 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 338 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 339 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
Kovalev_D | 92:c892f0311aa7 | 340 | |
Kovalev_D | 92:c892f0311aa7 | 341 | |
Kovalev_D | 92:c892f0311aa7 | 342 | |
Kovalev_D | 92:c892f0311aa7 | 343 | |
Kovalev_D | 86:398da56ef751 | 344 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 345 | /////////////////инициализация ног/////////////////// |
Kovalev_D | 86:398da56ef751 | 346 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 347 | |
Kovalev_D | 89:a0d344db227e | 348 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 349 | Gyro.PinRegOld = 0xffffffff; |
Kovalev_D | 88:b5c1d9d338d1 | 350 | Gyro.PinReg = 0; // всЁ выключенно |
Kovalev_D | 88:b5c1d9d338d1 | 351 | PinCheng(); |
Kovalev_D | 89:a0d344db227e | 352 | ///////////////////////////////////////////////////// |
Kovalev_D | 193:a0fe8bfc97e4 | 353 | Gyro.ModeOut=0; |
Kovalev_D | 87:7e575d26d6d0 | 354 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 355 | //////////////отладочный светодиод/////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 356 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 357 | |
Kovalev_D | 98:95b8e79f13e1 | 358 | LPC_PINCON->PINSEL0 &= ~(0x00<<28); |
Kovalev_D | 190:289514f730ee | 359 | LPC_PINCON->PINSEL0 |= (0x00<<28); // а нужно, ведь по умолчаниб у них 0 функция. попробоввать без них потом убрать |
Kovalev_D | 190:289514f730ee | 360 | LPC_PINCON->PINMODE0 |= (0x3<<28); |
Kovalev_D | 190:289514f730ee | 361 | LPC_GPIO1->FIODIR |= (1<<30); |
Kovalev_D | 87:7e575d26d6d0 | 362 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 363 | ///////////////////////////////////////////////////// |
Kovalev_D | 193:a0fe8bfc97e4 | 364 | NVIC_EnableIRQ(EINT3_IRQn); |
Kovalev_D | 193:a0fe8bfc97e4 | 365 | // LPC_GPIOINT->IO0IntEnF |= (1<<1); /* enable falling edge irq */ |
Kovalev_D | 193:a0fe8bfc97e4 | 366 | LPC_GPIOINT->IO0IntEnR |= (1<<1); /* enable rasing edge irq */ |
Kovalev_D | 87:7e575d26d6d0 | 367 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 368 | ////////////////управление уартом//////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 369 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 370 | LPC_GPIO2->FIODIR |= (1<<7);//направление ноги uart enable |
Kovalev_D | 87:7e575d26d6d0 | 371 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 372 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 373 | |
Kovalev_D | 88:b5c1d9d338d1 | 374 | |
Kovalev_D | 88:b5c1d9d338d1 | 375 | |
Kovalev_D | 87:7e575d26d6d0 | 376 | ///////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 377 | ///////////////////////поджиг//////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 378 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 379 | LPC_PINCON->PINSEL0 &= ~(3<<8); //e. P0.4 is GPIO pin (запись ( 00 ) в 9:8 бит PISEL0 выбор P0.4 как GPIO) |
Kovalev_D | 98:95b8e79f13e1 | 380 | LPC_PINCON->PINMODE0 |= (3<<8); //e. P0.4 is GPIO pin (запись ( 11 ) в 9:8 бит PINMODE0 "для включения подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 381 | LPC_GPIO0->FIODIR |= (1<<4); //e. P0.4 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.4 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 382 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 383 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 384 | |
Kovalev_D | 88:b5c1d9d338d1 | 385 | |
Kovalev_D | 88:b5c1d9d338d1 | 386 | |
Kovalev_D | 87:7e575d26d6d0 | 387 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 388 | /////////////////////вибро 1///////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 389 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 390 | LPC_PINCON->PINSEL3 &= ~(0x00<<18); //e. P1.25 is GPIO pin |
Kovalev_D | 98:95b8e79f13e1 | 391 | LPC_PINCON->PINSEL3 |= (0x00<<18); //e. P1.25 is GPIO pin |
Kovalev_D | 87:7e575d26d6d0 | 392 | LPC_PINCON->PINMODE3 |= (3<<18); //e. P1.25 (включениe подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 393 | LPC_GPIO1->FIODIR |= (1<<25); //e. P0.5 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.5 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 394 | LPC_GPIO1->FIOCLR |= (1<<25); |
Kovalev_D | 88:b5c1d9d338d1 | 395 | ////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 396 | //////////////////////вибро 2///////////////////////// |
Kovalev_D | 89:a0d344db227e | 397 | ////////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 398 | LPC_PINCON->PINSEL3 &= ~(0x00<<24); //e. P1.28 is GPIO pin |
Kovalev_D | 98:95b8e79f13e1 | 399 | LPC_PINCON->PINSEL3 |= (0x00<<24); //e. P1.28 is GPIO pin |
Kovalev_D | 87:7e575d26d6d0 | 400 | LPC_PINCON->PINMODE3 |= (3<<24); //e. P1.28 is GPIO pin (запись ( 11 ) в бит PINMODE0 "для включения подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 401 | LPC_GPIO1->FIODIR |= (1<<28); //e. P1.28 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.5 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 402 | LPC_GPIO1->FIOCLR |= (1<<28); |
Kovalev_D | 87:7e575d26d6d0 | 403 | ///////////////////////////////////////////////////// |
Kovalev_D | 87:7e575d26d6d0 | 404 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 405 | |
Kovalev_D | 88:b5c1d9d338d1 | 406 | |
Kovalev_D | 88:b5c1d9d338d1 | 407 | |
Kovalev_D | 87:7e575d26d6d0 | 408 | ///////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 409 | /////////////инициализация подсветки///////////////// |
Kovalev_D | 87:7e575d26d6d0 | 410 | ///////////////////////////////////////////////////// |
Kovalev_D | 98:95b8e79f13e1 | 411 | LPC_PINCON->PINSEL2 &= ~(0x00<<24); |
Kovalev_D | 98:95b8e79f13e1 | 412 | LPC_PINCON->PINSEL2 |= (0x00<<24); //e. P2.12 is GPIO pin |
Kovalev_D | 87:7e575d26d6d0 | 413 | LPC_PINCON->PINMODE3 |= (3<<24); //e. P1.28 is GPIO pin (запись ( 11 ) в бит PINMODE0 "для включения подтягивающего резистора") |
Kovalev_D | 87:7e575d26d6d0 | 414 | LPC_GPIO2->FIODIR |= (1<<12); //e. P1.28 is output (запись ( 1 ) в 5 бит FIODIR выбор P0.5 как выход) |
Kovalev_D | 87:7e575d26d6d0 | 415 | LPC_GPIO2->FIOCLR |= (1<<12); |
Kovalev_D | 88:b5c1d9d338d1 | 416 | /////////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 417 | /////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 418 | |
Kovalev_D | 88:b5c1d9d338d1 | 419 | |
Kovalev_D | 88:b5c1d9d338d1 | 420 | /////////////////////////////////////////////////////// |
Kovalev_D | 88:b5c1d9d338d1 | 421 | /////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 422 | ///////////////////включение таймеров////////////////// |
Kovalev_D | 89:a0d344db227e | 423 | /////////////////////////////////////////////////////// |
Kovalev_D | 86:398da56ef751 | 424 | enable_timer1(); |
Kovalev_D | 86:398da56ef751 | 425 | enable_timer2(); |
Kovalev_D | 89:a0d344db227e | 426 | /////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 427 | |
Kovalev_D | 89:a0d344db227e | 428 | ////////////////////////////////////////////////////////////////// |
Kovalev_D | 89:a0d344db227e | 429 | // LPC_GPIO0->FIOCLR = (1<<5);/////////////отключение поджига |
Kovalev_D | 90:d9b6a4bc5065 | 430 | |
Kovalev_D | 90:d9b6a4bc5065 | 431 | |
Kovalev_D | 90:d9b6a4bc5065 | 432 | |
Kovalev_D | 90:d9b6a4bc5065 | 433 | /////////////////////////////////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 434 | /////////////////////////////////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 435 | //////////////////////////SPI////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 436 | /////////////////////////////////////////////////////// |
Kovalev_D | 90:d9b6a4bc5065 | 437 | Dummy = Dummy; |
Kovalev_D | 90:d9b6a4bc5065 | 438 | |
Kovalev_D | 90:d9b6a4bc5065 | 439 | /* Enable AHB clock to the SSP0, SSP1 */ |
Kovalev_D | 90:d9b6a4bc5065 | 440 | LPC_SC->PCONP |= (0x1<<21); // включение SSP0. |
Kovalev_D | 90:d9b6a4bc5065 | 441 | |
Kovalev_D | 90:d9b6a4bc5065 | 442 | /* выбор частоты для переферии используем по умолчания с делителем основной на 4 */ |
Kovalev_D | 90:d9b6a4bc5065 | 443 | LPC_SC->PCLKSEL1 &= ~(0x3<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/8 |
Kovalev_D | 90:d9b6a4bc5065 | 444 | LPC_SC->PCLKSEL1 |= (0x0<<10); //00 CLK/4; 1 CLK; 2 CLK/2; 3 CLK/ |
Kovalev_D | 90:d9b6a4bc5065 | 445 | |
Kovalev_D | 90:d9b6a4bc5065 | 446 | // P0.15~0.18 as SSP0 |
Kovalev_D | 90:d9b6a4bc5065 | 447 | LPC_PINCON->PINSEL0 &= ~(0x3UL<<30); //установит Р 0.15 |
Kovalev_D | 90:d9b6a4bc5065 | 448 | LPC_PINCON->PINSEL0 |= (0x2UL<<30); //частота для синхронизациии Master - slave |
Kovalev_D | 90:d9b6a4bc5065 | 449 | |
Kovalev_D | 90:d9b6a4bc5065 | 450 | LPC_PINCON->PINSEL1 &= ~((0x3<<0)|(0x3<<2)|(0x3<<4)); // устанивоить Р 0.17 и Р 0.18 |
Kovalev_D | 90:d9b6a4bc5065 | 451 | LPC_PINCON->PINSEL1 |= ((0x2<<2)|(0x2<<4)); // как MISO0 и MOSI0 |
Kovalev_D | 90:d9b6a4bc5065 | 452 | |
Kovalev_D | 90:d9b6a4bc5065 | 453 | LPC_PINCON->PINMODE0 &= ~(0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 454 | LPC_PINCON->PINMODE0 |= (0x3UL<<30);// ? установление на Р 0.15 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 455 | |
Kovalev_D | 90:d9b6a4bc5065 | 456 | LPC_PINCON->PINMODE1 &= ~((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 457 | LPC_PINCON->PINMODE1 |= ((0x3<<2)|(0x3<<4));// ? установление на Р 0.17 и Р 0.18 режима On-Chip pull-down resistor enabled |
Kovalev_D | 90:d9b6a4bc5065 | 458 | |
Kovalev_D | 90:d9b6a4bc5065 | 459 | LPC_SSP0->CR0 = ((3<<8)|(0<<7)|(0<<4) |0xF); // (0xF)-установление DSS(Data sise select) в 16-битный формат, (3<<8 scr - выбор частоты), |
Kovalev_D | 90:d9b6a4bc5065 | 460 | // низкий уровень линии тактирования между кадрами, прикрепление передачи к первому нарастанию тактового мигнала |
Kovalev_D | 90:d9b6a4bc5065 | 461 | // формат кадра TI. |
Kovalev_D | 90:d9b6a4bc5065 | 462 | |
Kovalev_D | 90:d9b6a4bc5065 | 463 | /* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */ |
Kovalev_D | 90:d9b6a4bc5065 | 464 | LPC_SSP0->CPSR = 0x2; // freq = CLK/(cpsdvr*(scr+1)) = 1.6 MHz |
Kovalev_D | 90:d9b6a4bc5065 | 465 | |
Kovalev_D | 90:d9b6a4bc5065 | 466 | /*SSP enable, master mode */ |
Kovalev_D | 90:d9b6a4bc5065 | 467 | LPC_SSP0->CR1 = SSPCR1_SSE; |
Kovalev_D | 90:d9b6a4bc5065 | 468 | // LPC_SSP1->CR1 = SSPCR1_SSE; |
Kovalev_D | 90:d9b6a4bc5065 | 469 | while (LPC_SSP0->SR & SSP_BUSY); |
Kovalev_D | 170:d099c3025f87 | 470 | while (LPC_SSP0->SR & RX_SSP_notEMPT) /* clear the RxFIFO */ |
Kovalev_D | 90:d9b6a4bc5065 | 471 | Dummy = LPC_SSP0->DR; |
Kovalev_D | 90:d9b6a4bc5065 | 472 | //all pins after reset is in GPIO mode, so CS pins needn't to configure |
Kovalev_D | 90:d9b6a4bc5065 | 473 | LPC_GPIO0->FIODIR |= (1<<16); // P0.16 defined as CS for ADC |
Kovalev_D | 90:d9b6a4bc5065 | 474 | LPC_GPIO0->FIOSET |= (1<<16); // set CS for ADC |
Kovalev_D | 90:d9b6a4bc5065 | 475 | |
Kovalev_D | 92:c892f0311aa7 | 476 | LPC_GPIO0->FIODIR |= (1<<23); // P defined as CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 477 | LPC_GPIO0->FIOCLR |= (1<<23); // set CS for DAC |
Kovalev_D | 92:c892f0311aa7 | 478 | while (LPC_SSP1->SR & RX_SSP_notEMPT) |
Kovalev_D | 92:c892f0311aa7 | 479 | Dummy = LPC_SSP1->DR; /* clear the RxFIFO */ |
Kovalev_D | 90:d9b6a4bc5065 | 480 | |
Kovalev_D | 86:398da56ef751 | 481 | } |
igor_v | 13:e2a1d18677b8 | 482 | |
igor_v | 0:8ad47e2b6f00 | 483 | |
igor_v | 0:8ad47e2b6f00 | 484 | |
igor_v | 0:8ad47e2b6f00 | 485 | |
igor_v | 0:8ad47e2b6f00 | 486 |