K_A22_005 STM32-based drive 360-degree encoder module serial port and digital tube dual display

K_A22_005 is based on STM32 driving 360-degree encoder module, serial port and digital tube dual display

  • All resource navigation
  • 1. Resource description
  • 2. Basic parameters
    • Pin Description
  • 3. Driver instructions
    • Corresponding program:
  • Fourth, part of the code description
    • 1. Wiring pin definition
      • STM32F103C8T6 + 360 degree encoder module
  • 5. Basic knowledge learning and related data download
  • 6. Video effect display and program data acquisition
  • 7. Matters needing attention
  • 8. Wiring instructions
    • STM32F103C8T6

Please add a picture description

All resource navigation

Other data directory direct jump

1. Resource description

MCU model Test conditions Module name Code function
STM32F103C8T6 Crystal oscillator 8M/system clock 72M 360 degree encoder module STM32F103C8T6 drives 360-degree encoder module serial port and OLED0.96 dual display

2. Basic parameters

Pin description

360-degree encoder module pin description
VCC( + ) Positive pole 3.3-5V power supply
GND(-) GND power supply negative pole
A Signal output A
B Signal output B
C Connected to GND

3. Driver Description

Please add a picture description

Corresponding program:

STM32 program:

//Interrupt configuration:
/**
  * @brief Configure Nested Vectored Interrupt Controller NVIC
  * @param None
  * @retval None
  */
static void NVIC_Configuration(void)
{<!-- -->
  NVIC_InitTypeDef NVIC_InitStructure;
  
  /* Configure NVIC as priority group 1 */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  
  /* Configure interrupt source: button 1 */
  NVIC_InitStructure.NVIC_IRQChannel = ECC11_A_INT_EXTI_IRQ;
  /* Configure preemption priority */
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  /* Configure sub-priority */
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  /* Enable interrupt channel */
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init( &NVIC_InitStructure);
  
// /* Configure interrupt source: key 2, other use the above related configuration */
// NVIC_InitStructure.NVIC_IRQChannel = ECC11_B_INT_EXTI_IRQ;
// NVIC_Init( &NVIC_InitStructure);
}

 /**
  * @brief Configure IO as EXTI interrupt port, and set interrupt priority
  * @param None
  * @retval None
  */
void EXTI_Key_Config(void)
{<!-- -->
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;

/* Turn on the clock of the button GPIO port */
RCC_APB2PeriphClockCmd(ECC11_A_INT_GPIO_CLK,ENABLE);
\t\t\t\t\t\t\t\t\t\t\t\t
/* configure NVIC interrupt */
NVIC_Configuration();
\t
/*-------------------------ECC11_A Configuration------------------- ---------*/
/* Select the GPIO used by the button */
  GPIO_InitStructure.GPIO_Pin = ECC11_A_INT_GPIO_PIN;
  /* Configure as floating input */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(ECC11_A_INT_GPIO_PORT, & GPIO_InitStructure);

/* Select the signal source of EXTI */
  GPIO_EXTILineConfig(ECC11_A_INT_EXTI_PORTSOURCE, ECC11_A_INT_EXTI_PINSOURCE);
  EXTI_InitStructure.EXTI_Line = ECC11_A_INT_EXTI_LINE;
\t
/* EXTI is interrupt mode */
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
/* Falling edge interrupt */
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
  /* enable interrupt */
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init( & EXTI_InitStructure);
\t
// /*--------------------------ECC11_B configuration ------------------ -----------*/
// /* Select the GPIO used by the button */
  GPIO_InitStructure.GPIO_Pin = ECC11_B_INT_GPIO_PIN;
  /* Configure as floating input */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(ECC11_B_INT_GPIO_PORT, & GPIO_InitStructure);


  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  /* Configure as floating input */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, & GPIO_InitStructure);
}
Interrupt service function:
void ECC11_A_IRQHandler(void)
{<!-- -->
  //Ensure whether an EXTI Line interrupt is generated
if(EXTI_GetITStatus(ECC11_A_INT_EXTI_LINE) != RESET)
{<!-- -->

if(!(GPIO_ReadInputDataBit(ECC11_A_INT_GPIO_PORT, ECC11_A_INT_GPIO_PIN)))
{<!-- -->
A_B_Flag=1;
}
if((GPIO_ReadInputDataBit(ECC11_A_INT_GPIO_PORT, ECC11_A_INT_GPIO_PIN)) & amp; & amp; A_B_Flag)
{<!-- -->
EC11_flag=1;
A_B_Flag=0;
if(GPIO_ReadInputDataBit(ECC11_B_INT_GPIO_PORT, ECC11_B_INT_GPIO_PIN))
{<!-- -->
timer--;
if(timer>=255)
{<!-- -->
timer=0;
}
\t\t\t\t
}
else
{<!-- -->
timer + + ;
if(timer>=255)
{<!-- -->
timer=255;
}
\t\t\t\t
}
}
\t\t
    //clear interrupt flag
EXTI_ClearITPendingBit(ECC11_A_INT_EXTI_LINE);
}
}

4. Some code description

1. Wiring pin definition

If you need to customize the pin, you can change it here. If STM32 wants to customize the pin, you should also pay attention to the change of the pin clock enable

STM32F103C8T6 + 360-degree encoder module

//360 degree encoder module pin definition
//360 degree encoder module pin definition
#define ECC11_A_INT_GPIO_PORT GPIOA
#define ECC11_A_INT_GPIO_CLK (RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO)
#define ECC11_A_INT_GPIO_PIN GPIO_Pin_4

#define ECC11_B_INT_GPIO_PORT GPIOA
#define ECC11_B_INT_GPIO_CLK (RCC_APB2Periph_GPIOA)
#define ECC11_B_INT_GPIO_PIN GPIO_Pin_5

// pin definition of digital tube module
#define DIN_GPIO_PORT GPIOA /* GPIO port */
#define DIN_GPIO_CLK RCC_APB2Periph_GPIOA /* GPIO port clock */
#define DIN_GPIO_PIN GPIO_Pin_1

#define CS_GPIO_PORT GPIOA /* GPIO port */
#define CS_GPIO_CLK RCC_APB2Periph_GPIOA /* GPIO port clock */
#define CS_GPIO_PIN GPIO_Pin_2

#define CLK_GPIO_PORT GPIOA /* GPIO port */
#define CLK_GPIO_CLK RCC_APB2Periph_GPIOA /* GPIO port clock */
#define CLK_GPIO_PIN GPIO_Pin_3
//Passive buzzer pin definition PA6
GPIOA->ODR ^= GPIO_Pin_6;

5. Basic knowledge learning and related data download

1. STC89C52RC program download direct stamp jump

2. STM32F103C8T6 program download
(1) Serial port download direct stamp jump
(2) ST-LINK download direct stamp jump
(3) J-LINK download direct stamp jump
(4) DAP-LINK download direct stamp jump

3. OLED0.96 Program Instructions Direct Poke Jump

4. Download and use the serial port assistant
(1) Anxin Debugging Assistant uses direct poke to jump
(2) sscom33 serial port debugging assistant uses direct poke jump
(3) Use the STC-ISP serial port debugging assistant to jump directly

6. Video effect display and program data acquisition

Video link Directly click to jump
Data acquisition (scroll to the end to add a personal number)

7. Precautions

1. Do not connect VCC GND reversely, otherwise it is easy to burn
2. When the OLED display is abnormal, exclude the poor connection of the wiring

8. Wiring instructions

STM32F103C8T6

/********************************************** *****************************************
// Generation date: 2021-6-21
// Last Modified : 2021-11-21
// Function description: 360-degree encoder test program
// Test conditions: STM32F103C8T6 crystal oscillator 8M system clock 72M
wiring
360-degree encoder ------------------------------ STM32F103C8T6
VCC-----------------------------------3.3V
GND-----------------------------------GND
A -----------------------------------------PA4
B------------------------------------------PA5

Digital tube (MAX7219-------------------------STM32F103C8T6
VCC-----------------------------------5V
GND-----------------------------------GND
DIN- -------------------------------------- PA1 //
CS-- -----------------------------------PA2 //
CLK- -------------------------------------- PA3 //

Passive buzzer module ---------------------------STM32F103C8T6
VCC-----------------------------------5V
GND-----------------------------------GND
SCL- -------------------------------------- PA6 //SCL
***************************************************** *************************************/