Hallo, ich bin Einsteiger was STM32 betrifft und habe zu Beginn mal ein einfaches Programm mit CooCox programmiert. Es soll ein Zeichen über die RS232 Schnittstelle senden. Es sendet jedoch mit der doppelten Baudrate als ich eingestellt habe und ich verstehe nicht warum. Main.c sieht wie folgt aus: #include "stm32f4xx_hal.h" #include "stm32f4xx_hal_rcc.h" #include "stm32f4xx_hal_gpio.h" #include "stm32f4xx_hal_uart.h" int main(void) { int i=0; HAL_Init(); SystemInit(); //************ UART CONFIG *****************************// UART_HandleTypeDef uart_config; __USART1_CLK_ENABLE(); uart_config.Instance=USART1; uart_config.Init.BaudRate=9600; uart_config.Init.WordLength=UART_WORDLENGTH_8B; uart_config.Init.StopBits=UART_STOPBITS_1; uart_config.Init.Parity=UART_PARITY_NONE; uart_config.Init.Mode=UART_MODE_TX_RX; uart_config.Init.HwFlowCtl=UART_HWCONTROL_NONE; HAL_UART_Init(&uart_config); //**********************************************************// //************ UART GPIO CONFIG *********************// GPIO_InitTypeDef uart_gpio; __GPIOA_CLK_ENABLE(); uart_gpio.Pin=GPIO_PIN_9 | GPIO_PIN_10; uart_gpio.Mode=GPIO_MODE_AF_PP; uart_gpio.Pull=GPIO_NOPULL; uart_gpio.Speed=GPIO_SPEED_FAST; uart_gpio.Alternate=GPIO_AF7_USART1; HAL_GPIO_Init(GPIOA, &uart_gpio); //******************************************************// //************ LED ****************************// GPIO_InitTypeDef gpio_led; __GPIOG_CLK_ENABLE(); gpio_led.Pin=GPIO_PIN_12; gpio_led.Mode=GPIO_MODE_OUTPUT_PP; gpio_led.Pull=GPIO_NOPULL; gpio_led.Speed=GPIO_SPEED_FAST; HAL_GPIO_Init(GPIOG, &gpio_led); //***********************************************// while(1) { HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, 0); for (i=0; i<=500000; i++); HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, 1); for (i=0; i<=500000; i++); HAL_UART_Transmit(&uart_config, "A", 1, 0x0f); } } Eine LED wird noch getoggelt, sollte aber keinen Einfluss darauf haben. Kann mir da bitte jemand weiterhelfen. Danke schonmal
Und die LED blinkt auch langsam und leuchtet nicht "durchgängig"? Moderne Compiler optimieren das hier vollständig weg:
1 | for (i=0; i<=500000; i++); |
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.