firstTest

This commit is contained in:
2024-08-20 22:26:27 +03:00
parent eefbc336fa
commit 2c2ebd7137
15 changed files with 930 additions and 25 deletions

View File

@ -23,6 +23,11 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "usbd_cdc_if.h"
#include "pca9685.h"
#include "IR.h"
#include "EEPROM.h"
#include "Print.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -51,6 +56,40 @@ UART_HandleTypeDef huart3;
/* USER CODE BEGIN PV */
uint8_t txdata[64];
uint8_t rxdata[64];
uint8_t velosety[600];
uint8_t rxcomlite = 0;
uint8_t initcomlete = 0;
unsigned char Shiftreg[3];
uint8_t rejim[60]; // 0 - chislo rejimov, 1-6 - rejim1, 7-12 - rejim2...
uint8_t avto = 0; // vkl/otkl avtomaticheskoi raboti
uint8_t rejim_number = 1; // nomer tekyshego rejima
uint8_t Vz1 = 100;
uint8_t Vz2 = 100;
uint16_t vi = 0;
uint16_t timing1 = 0;
uint16_t timing2 = 0;
uint8_t MYIR_command = 0;
volatile uint32_t millisCounter = 0;
uint32_t previousMillis = 0;
struct StructShot BufShots[MAX_NUMBER_SHOTS];
struct StructProgram BufPrograms;
struct StructMacro BufMacro;
extern PCD_HandleTypeDef hpcd_USB_FS;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@ -94,7 +133,15 @@ int main(void)
SystemClock_Config();
/* USER CODE BEGIN SysInit */
// Установка приоритета прерывания
// NVIC_SetPriority(SysTick_IRQn, 0);
// Настройка SysTick таймера на 1 мс
SysTick->LOAD = 479999; // 1ms Sys timer
// SysTick_Config(SystemCoreClock / 1000);
__HAL_RCC_USB_FORCE_RESET();
HAL_Delay(10);
__HAL_RCC_USB_RELEASE_RESET();
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
@ -107,12 +154,151 @@ int main(void)
MX_USART3_UART_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); //PA8
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2); //PA9
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); //PA0
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2); //PA1
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3); //PA2
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); //PA3
initPCA9685();
//BufShots[0].countRepeatShot = 5;
//BufShots[0].speedRollerTop = 120;
//BufShots[0].speedRollerBottom = 130;
//BufShots[0].speedScrew = 50;
//BufShots[0].rotationAxial = 90;
//BufShots[0].rotationHorizontal = 90;
//BufShots[0].rotationVertical = 90;
// SaveShot(0, &BufShots[0]);
// BufShots[1] = GetShot(0);
initcomlete = 1;
Shiftreg[0] = 0x00; Shiftreg[1] = 0x44; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x00; Shiftreg[1] = 0x66; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x00; Shiftreg[1] = 0x77; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x01; Shiftreg[1] = 0x77; Shiftreg[2] = 0x01; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x03; Shiftreg[1] = 0x77; Shiftreg[2] = 0x03; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x07; Shiftreg[1] = 0x77; Shiftreg[2] = 0x07; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x0F; Shiftreg[1] = 0x77; Shiftreg[2] = 0x0F; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x1F; Shiftreg[1] = 0x77; Shiftreg[2] = 0x1F; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x3F; Shiftreg[1] = 0x77; Shiftreg[2] = 0x3F; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x7F; Shiftreg[1] = 0x77; Shiftreg[2] = 0x7F; SetShiftReg(Shiftreg); HAL_Delay(10);
Shiftreg[0] = 0x00; Shiftreg[1] = 0x00; Shiftreg[2] = 0x00; SetShiftReg(Shiftreg); HAL_Delay(10);
HAL_TIM_IC_Start_IT(&htim3, TIM_CHANNEL_1); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1 <20>6 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> PA0 PA1
HAL_TIM_Base_Start_IT(&htim3);
HAL_NVIC_EnableIRQ(TIM3_IRQn);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if (IRStatus == STATUS_REPEAT) {
if (IR_Address == 0x01) MYIR_command = IR_Command;
CDC_Transmit_FS(&MYIR_command, 1);
ClearIRStatus();
}
if (rxcomlite == 1) {
txdata[0] = 'O'; txdata[1] = 'K'; txdata[2] = '?';
switch (rxdata[0]) {
case 1: { SetServo(0, rxdata[1] ); txdata[0] = 'O'; txdata[1] = 'K';
txdata[2] = '1'; CDC_Transmit_FS(txdata, 3); break; }
case 2: { SetServo(1, rxdata[1] ); txdata[0] = 'O'; txdata[1] = 'K';
txdata[2] = '2'; CDC_Transmit_FS(txdata, 3); break; }
case 3: { SetServo(2, rxdata[1] ); txdata[0] = 'O'; txdata[1] = 'K';
txdata[2] = '3'; CDC_Transmit_FS(txdata, 3); break; }
case 4: { SetServo(0, rxdata[1] ); SetServo(1, rxdata[2] ); SetServo(2, rxdata[3] );
Vz1 = rxdata[4]; //rolic verh 0..200
Vz2 = rxdata[5]; //rolic niz 0..200
vi = 0;
//shnek 0..100
if (rxdata[6] < 101) { TIM1->CCR1 = 0; TIM1->CCR2 = (uint16_t)(40*rxdata[6]); } else
{ TIM1->CCR1 = 0; TIM1->CCR2 = 4000;}
txdata[0] = 'O'; txdata[1] = 'K'; txdata[2] = '4'; CDC_Transmit_FS(txdata, 3); break; }
case 5: {txdata[0] = LOBYTE(timing1) ; txdata[1] = HIBYTE(timing1) ;
CDC_Transmit_FS(txdata, 3); break; }
case 6: { CDC_Transmit_FS(velosety, 600); break; }
case 7: { rejim[0] = rxdata[1];
// copy to buffer
for (uint8_t i = 0; i < rejim[0]; i++)
{
rejim[(i*6)+1] = rxdata[(i*6)+2];
rejim[(i*6)+2] = rxdata[(i*6)+3];
rejim[(i*6)+3] = rxdata[(i*6)+4];
rejim[(i*6)+4] = rxdata[(i*6)+5];
rejim[(i*6)+5] = rxdata[(i*6)+6];
rejim[(i*6)+6] = rxdata[(i*6)+7];
}
// set rejim #1
SetServo(0, rejim[1] );
SetServo(1, rejim[2] );
SetServo(2, rejim[3] );
Vz1 = rejim[4];
Vz2 = rejim[5];
TIM1->CCR1 = 0; TIM1->CCR2 = (uint16_t)(40*rejim[6]);
// set avto
rejim_number = 1;
avto = 1;
break; }
case 8: { // stop avto
avto = 0; rejim_number = 1;
// stop mecanics
SetServo(0, 90);
SetServo(1, 90);
SetServo(2, 90);
Vz1 = 100;
Vz2 = 100;
TIM1->CCR1 = 0; TIM1->CCR2 = 0;
break; }
case 9: { txdata[0] = avto ;
txdata[1] = rejim_number;
CDC_Transmit_FS(txdata, 3);
break; }
default: break;
}
rxcomlite = 0;
// // HAL_Delay(1000);
}
uint32_t currentMillis = millisCounter;
if (currentMillis - previousMillis >= 500) {
previousMillis = currentMillis;
GPIOC->ODR ^= GPIO_PIN_13;
// unsigned char text[] = "Hello\n";
// printNumber(SysTick->LOAD);
// CDC_Transmit_FS(text, sizeof(text));
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
@ -359,7 +545,7 @@ static void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
__HAL_RCC_TIM3_CLK_ENABLE();
/* USER CODE END TIM3_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
@ -463,7 +649,7 @@ static void MX_GPIO_Init(void)
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, LED_DATA_Pin|LED_CLK_Pin, GPIO_PIN_RESET);
@ -518,8 +704,10 @@ void Error_Handler(void)
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
// GPIOC->ODR &= ~GPIO_PIN_13;
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}