USART1 - STM32L100 Discovery
- July 28 2014
- STM32F4, STM32F7, STM32L1, STM32F3, Nucleo, Discovery
- 6782x Přečteno
Pokud jste program správně opravili, tak ve Flash -> Configure Flash Tools -> Debug -> Settings (u výběru programátoru) -> Vypíše hlášku v okně SW Device: se vám objeví váš mikrokontrolér. Přejdeme k další chybě a to je nastavení registru AFR - tedy nastavení alternativních funkcí. Podle níže zobrazeného obrázku vidíte, že USART1 se nachází na AF7, což znamená, že nastavení PINu pro alternativní funkci musíte nastavit na hodnotu 7. Protože každý PIN může mít až 16 (0 - 15) alternativních funkcí, jsou každému PINu vyhrazeny 4 bity v 32 bit registru AFR. Registr AFR[0] je registr pro PINy 0 - 7 a AFR[1] je pro PINy 8 - 15. A nakonec poslední problém byl správné nastavení BRR tedy Baud rate register. Registr se dělí na dvě části - 4 bity pro tzv. Fraction a 12 bitů pro tzv. Mantissu. Vzorec je jednoduchý a naleznete ho zde: http://joudove.8u.cz Použijte naši kalkulačku na výpočet Baud Rate! A nakonec celý kód pro USART - mikrokontrolér přijme znak a pošle ho zpátky. MAIN.C a ještě system_stm32l1xx.c <#EN>If you program microcontrollers by STM (STM32F4, STM32F0, STM32L1) with Standard Peripheral Library your code is bigger than without Standard Peripheral Library. It is motivation why we can program of microcontrollers without Standard Peripheral Library. Nevertheless, if you program without Standard Peripheral Library, the support will be wrong for you. More people don't work without Standard Peripheral Library. Now, I describe USART1 for STM32L100, but you can this code transfer on the other microcontrollers. For example STM32F053, STM32L152, STM32L303 and more. The article is inspired by joudove.8u.cz (Czech language). The basic information about USART you can find on the wikipedia. You find the description some bits on the registers on the datasheet (reference manual). My first mistake: missing character | You set the pins straight. But, On this PORT is programming interface - SWD. The Integrated Development Environment (IDE) Keil send Waring in the terminal. Internal command error If you load your code, send warning: No target connected and next Error: Flash Download failed - Target DLL has been cancelled If you open Flash -> Configure Flash Tools -> Debug -> Settings (programmer) -> SW Device: No Cortex-M SW Device Found In this moment is not the microcontroller visible. You have to repair it. If you use the Attolic TrueStudio, it send warning: Remote failure reply: E31, but the atollic ask you if you want kill process. Push "y" - yes. The microcontroller is visible and you have to repair your code. Back to our problem. How to repair it in IDE Keil? You use Atollic TrueStudio OR you use ST-LINK utility and you check Target -> Settings -> Mode: Connect Under Reset OR last possibility. You repair your code and once you load the code to the microcontroller, push the reset on the development board. More precisely. You press the RESET button and you press "Load" button in the Keil then realease RESET button. Note from comments: You can choose "Connect under reset" in the Keil - programmer settings. Thanks.
If you reapair the code and load code to the microcontroller, in the Flash -> Configure Flash Tools -> Debug -> Settings (programmer) -> SW Device: you will see your microcontroller. Following mistake. Bad setting alternate function: On this picture is setting of the register AFR - setting alternate function. Each PIN can have up to 16 alternate functions and each PINs are reserved 4 bits in 32 bits register AFR. The register AFR[0] is register for PINs 0 - 7 and AFR[1] is PINs for 8 - 15. And last problem. How to set right Baud Rate. The register is divided into 2 parts. 4 bits for Fraction and 12 bits for Mantissu. The formule is easy and you can find on the website: http://joudove.8u.cz Use this calculator for Baud Rate calculation ! Complete code for USART - the microcontroller get char and send it back. MAIN.C and system_stm32l1xx.c