Cov txheej txheem:

STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx): 5 Kauj Ruam
STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx): 5 Kauj Ruam

Video: STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx): 5 Kauj Ruam

Video: STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx): 5 Kauj Ruam
Video: STM32F4Discovery Tutorial 1 - Introduction 2024, Hlis ntuj nqeg
Anonim
STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx)
STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx)
STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx)
STM32F4 Discovery Board thiab Python USART Kev Sib Txuas Lus (STM32CubeMx)

Nyob zoo! Hauv qhov kev qhia no peb yuav sim tsim USART kev sib txuas lus ntawm STM32F4 ARM MCU thiab Python (nws tuaj yeem hloov los ntawm lwm yam lus). Yog li, cia peb pib:)

Kauj Ruam 1: Kev Xav Tau Software thiab Kho Vajtse

Hais txog kho vajtse koj xav tau:

  • STM32F4 Discovery Board (lossis lwm yam STM32 board)
  • Konvertiere USB in TXL

Hais txog software:

  • STM32CubeMX
  • Keil uVision 5
  • Nab hab sej nrog cov tsev qiv ntawv txuas

Kauj ruam 2: STM32CubeMX Configuration

Ua ntej cia peb nkag siab tias peb xav ua dab tsi. Peb xav xa cov ntaub ntawv mus rau pawg thawj coj ntawm Python hla USART thiab tshawb xyuas yog tias peb muaj cov ntaub ntawv raug thiab hloov pauv coj. Yog li, peb xav tau kev pab USART thiab Led.

  • Pab kom USART2 los ntawm Kev Sib Txuas tab.

    • Hloov hom rau Asynchoronous
    • Baud tus nqi mus rau 9600 Bit/s
    • Lo lus ntev txog 8 Khoom yam tsis muaj qhov sib npaug
    • Tsis muaj parity me ntsis
    • Los ntawm DMA teeb tsa ntxiv USART2_RX hauv hom cicular
    • Los ntawm NVIC Chaw pab kom USART2 cuam tshuam thoob ntiaj teb
  • Pab kom LED los ntawm txhaj rau PD12

Tom qab ntawd tsim cov cai:)

Kauj Ruam 3: Keil Kev Txhim Kho Software

#suav nrog

#suav nrog

Cov tsev qiv ntawv no yuav xav tau hauv txoj haujlwm ua haujlwm thiab txhawm rau txheeb xyuas qhov sib txawv boolean.

/ *USER CODE BEGIN 2 */ HAL_UART_Receive_DMA (& huart2, (uint8_t *) data_buffer, 1); / * USER CODE KAWG 2 */

Ntawm no, UART tau txais nrog DMA pib.

/ *USER CODE BEGIN 4 */void HAL_UART_RxCpltCallback (UART_HandleTypeDef *huart) {/ *Tiv thaiv kom tsis txhob siv cov lus sib cav (s) sau ua ke ceeb toom */UNUSED (huart); / * NCO TSEG: Qhov haujlwm no yuav tsum tsis raug hloov kho, thaum xav tau kev hu rov qab, HAL_UART_RxCpltCallback tuaj yeem ua tiav hauv tus neeg siv cov ntaub ntawv */ yog (data_buffer [0]! = '\ N') {data_full [index_] = data_buffer [0]; index _ ++; } lwm {index_ = 0; tiav = 1; } // HAL_UART_Transmit (& huart2, data_buffer, 1, 10); } / * USER CODE KAWG 4 * /

Qhov no yog ISR uas tau qhib thaum peb tau txais ib byte ntawm tus ua cim. Yog li peb tau txais cov byte thiab sau nws mus rau data_full uas muaj cov ntaub ntawv tau txais tag nrho kom txog thaum peb tau txais '\ n'. Thaum peb tau txais '\ n' peb ua tiav tus chij 1 thiab thaum lub voj:

thaum (1) { / * USER CODE END WHILE * / yog (ua tiav) {yog (strcmp (data_full, cmp_) == 0) {HAL_GPIO_TogglePin (GPIOD, GPIO_PIN_12); } memset (data_full, '\ 0', strlen (data_full)); tiav = 0; } lwm {_NOP (); } / * USER CODE BEGIN 3 * /}

Yog ua tiav tus chij yog HIGH peb sib piv cov ntsiab lus ntawm cov ntaub ntawv tau txais thiab cov ntaub ntawv peb xav tau thiab yog tias lawv sib npaug peb toggle coj. Tom qab ntawd peb tshem tawm tus chij tiav thiab tos rau cov ntaub ntawv tshiab thiab tseem tshem tawm cov ntaub ntawv tagful kom tsis txhob rov sau dua rau kab lus.

Kauj ruam 4: Python Software Development

Yog li, ntawm no peb xav xa peb tus lej nrog '/n' thaum kawg, vim Keil software yuav xav pom nws txhawm rau paub qhov kawg.

ntshuam ntshuam

ser = serial. Serial ('COM17') #khij qhov chaw nres nkoj ntawm koj lub cuab yeej los ntawm Device Manager

ser.write (b'24 / n ')

Koj yuav tsum pom tias LED toggles txhua lub sijhawm koj xa '24 / n '. Yog tias koj xa lwm yam ntxiv nws yuav tsum tsis cuam tshuam rau nws.

Kauj Ruam 5: Xaus

Peb tau mus txog qhov kawg ntawm kev qhia. yog tias koj muaj teeb meem lossis lus nug thov tsis txhob ua siab deb nug. Kuv yuav sim pab ntau npaum li kuv ua tau. Ua tsaug ntau ntau:)

Pom zoo: