comparison Small_CPU/Src/spi.c @ 82:a6f0881074a4 kittz

+i2c analog noise filtering spi more stable
author Dmitry Romanov <kitt@bk.ru>
date Tue, 20 Nov 2018 12:08:19 +0300
parents cd298de33783
children e6abbef57475
comparison
equal deleted inserted replaced
80:cc2bb7bb8456 82:a6f0881074a4
80 // limiter 80 // limiter
81 if(arrayInput[i] == 0xFF) 81 if(arrayInput[i] == 0xFF)
82 arrayInput[i] = 0xFE; 82 arrayInput[i] = 0xFE;
83 if(arrayInput[i] >= 15) 83 if(arrayInput[i] >= 15)
84 { 84 {
85 // copy - auslöse-schwelle 85 // copy - ausl�se-schwelle
86 rework[i+1] = arrayInput[i]; 86 rework[i+1] = arrayInput[i];
87 // wieder-scharf-schalte-schwelle 87 // wieder-scharf-schalte-schwelle
88 rework[i+3+1] = arrayInput[i] - 10; 88 rework[i+3+1] = arrayInput[i] - 10;
89 } 89 }
90 else 90 else
91 if(arrayInput[i] >= 10) 91 if(arrayInput[i] >= 10)
92 { 92 {
93 // copy - auslöse-schwelle 93 // copy - ausl�se-schwelle
94 rework[i+1] = arrayInput[i]; 94 rework[i+1] = arrayInput[i];
95 // wieder-scharf-schalte-schwelle 95 // wieder-scharf-schalte-schwelle
96 rework[i+3+1] = arrayInput[i] - 5; 96 rework[i+3+1] = arrayInput[i] - 5;
97 } 97 }
98 else 98 else
99 { 99 {
100 // copy - auslöse-schwelle 100 // copy - ausl�se-schwelle
101 rework[i+1] = 7; 101 rework[i+1] = 7;
102 // wieder-scharf-schalte-schwelle 102 // wieder-scharf-schalte-schwelle
103 rework[i+3+1] = 6; 103 rework[i+3+1] = 6;
104 } 104 }
105 } 105 }
337 } 337 }
338 338
339 339
340 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) 340 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
341 { 341 {
342 /* restart SPI */
343 if(hspi == &hspi1)
344 {
345
342 global.check_sync_not_running = 0; 346 global.check_sync_not_running = 0;
343 /* stop data exchange? */ 347 /* stop data exchange? */
344 if(global.mode == MODE_SHUTDOWN) 348 if(global.mode == MODE_SHUTDOWN)
345 { 349 {
346 global.mode = MODE_SLEEP; 350 global.mode = MODE_SLEEP;
351 } 355 }
352 356
353 /* data consistent? */ 357 /* data consistent? */
354 if(SPI_check_header_and_footer_ok()) 358 if(SPI_check_header_and_footer_ok())
355 { 359 {
356 GPIO_new_DEBUG_HIGH(); 360 // GPIO_new_DEBUG_HIGH(); //For debug.
357 global.dataSendToSlaveIsValid = 1; 361 global.dataSendToSlaveIsValid = 1;
358 global.dataSendToSlaveIsNotValidCount = 0; 362 global.dataSendToSlaveIsNotValidCount = 0;
359 } 363 }
360 else 364 else
361 { 365 {
362 GPIO_new_DEBUG_LOW(); 366 // GPIO_new_DEBUG_LOW(); //For debug.
363 global.dataSendToSlaveIsValid = 0; 367 global.dataSendToSlaveIsValid = 0;
364 global.dataSendToSlaveIsNotValidCount++; 368 global.dataSendToSlaveIsNotValidCount++;
365 } 369 }
366 global.dataSendToMaster.power_on_reset = 0; 370 global.dataSendToMaster.power_on_reset = 0;
367 global.deviceDataSendToMaster.power_on_reset = 0; 371 global.deviceDataSendToMaster.power_on_reset = 0;
368 /* no i2c or other time critical threads? */ 372 if(!global.dataSendToSlaveStopEval)
369 if(global.dataSendToSlaveIsValid)
370 {
371 if(!global.dataSendToSlaveStopEval)
372 { 373 {
373 scheduleSpecial_Evaluate_DataSendToSlave(); 374 scheduleSpecial_Evaluate_DataSendToSlave();
374 } 375 }
375 else 376 SPI_Start_single_TxRx_with_Master();
376 { 377 }
377 global.dataSendToSlavePending = 1;
378 }
379 }
380 else
381 {
382 global.dataSendToSlavePending = 0;
383 }
384
385 /* restart SPI */
386 if(hspi == &hspi1)
387 {
388 if(global.dataSendToSlaveIsValid)
389 SPI_Start_single_TxRx_with_Master();
390 }
391 } 378 }
392 379
393 380
394 static uint8_t SPI_check_header_and_footer_ok(void) 381 static uint8_t SPI_check_header_and_footer_ok(void)
395 { 382 {
413 return 1; 400 return 1;
414 } 401 }
415 402
416 static void SPI_Error_Handler(void) 403 static void SPI_Error_Handler(void)
417 { 404 {
418 while(1) 405 //The device is locks. Hard to recover.
419 { 406 // while(1)
420 } 407 // {
408 // }
421 } 409 }
422 410
423 /** 411 /**
424 * @} 412 * @}
425 */ 413 */