Encodeur rotatif sous STM32
Mise en oeuvre sur un STM32-F429ZI (nucleo-F429ZI)
-
Mise en oeuvre d'un codeur rotatif avec bouton central.
-
Mise en garde : désactiver l'ethernet qui s'il n'est pas configuré fait planter au démarrage.
-
Au niveau du Timer à utiliser
utiliser un timer qui permet le mode Encoder
Attention : Sur la nucleo-F429ZI le timer2 ne semble pas bien connecté sur PA0 et PA1 (A vérifier) -
Timer3 : PC7 et PA6. Testé avec succès.
-
GPIO : s'il n'y a pas de résistances de pull-up, les rajouter en interne.
Step 0 : configuration de l'USART3 histoire de communiquer avec le PC et putty (115200 8N1)
Step 1 : configuration des horloges du STM32
Step 2 : configuration du Timer 3
Step 3 : configuration du Timer 3, suite
Step 4 : et dans le main
// ne pas oublier
#include "stdio.h"
int main(void)
{
uint16_t EncVal = 0;
uint8_t msg[]="Encoder test with default settings of project\r\n";
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART3_UART_Init();
MX_TIM3_Init();
uint8_t Uart_Buf[70];
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
HAL_UART_Transmit(&huart3, msg, sizeof(msg), 1000);
while (1)
{
EncVal = (TIM3->CNT)>>2; //selon les valeurs configurées, pas nécessaire de faire une division par 4
// EncVal = __HAL_TIM_GET_COUNTER(&htim2);
int len = sprintf(Uart_Buf, "%d\r\n",EncVal);
HAL_UART_Transmit(&huart3, Uart_Buf, len, 1000);
HAL_Delay(100);
}
}
Step 5 : Hardware
Bibliographie
https://stm32world.com/wiki/STM32_Rotary_Encoder
https://stm32f4-discovery.net/2014/08/library-26-rotary-encoder-stm32f4/
Nucleo-F429ZI Schematic and pinout
foo@bar:~$ wget https://www.st.com/content/ccc/resource/technical/layouts_and_diagrams/schematic_pack/63/95/5c/0c/d6/af/4b/e2/nucleo_144pins_sch.zip/files/nucleo_144pins_sch.zip/jcr:content/translations/en.nucleo_144pins_sch.zip
Nucleo-F446RE Schematic and pinout
foo@bar:~$ wget https://www.st.com/content/ccc/resource/technical/layouts_and_diagrams/schematic_pack/71/1e/2a/ac/b5/c1/4b/a9/nucleo_64pins_sch.zip/files/nucleo_64pins_sch.zip/jcr:content/translations/en.nucleo_64pins_sch.zip
STM32F429ZI Reference Manual
https://www.st.com/resource/en/reference_manual/rm0090-stm32f405415-stm32f407417-stm32f427437-and-stm32f429439-advanced-armbased-32bit-mcus-stmicroelectronics.pdf
USB
-
Côté PC - programmation
https://geekthis.net/post/usb-sniffing-and-programming/ -
Avec WireShark
https://wiki.wireshark.org/CaptureSetup/USB