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