hi eine Frage, ich nutze die cube mx und stm32 workbench for stm32 (eclipse). Ich benutze die HAL und habe 2 output pins um leds an/auszuschalten, was funktioniert. Jedoch hab ich einen Taster, der richtig angeschlossen ist. Sobald dieser gedrückt wird, liegt 0 V an, jedoch reagiert der uC nicht da drauf. Nutze die HAL_ReadPin Funktion. Es wird immer eine 1 gelesen. Eingestellt ist 'nopull'. Was mich ebenfalls verwundert ist, dass wenn ich einen Interrupt Pin in Cube MX einstelle, dass dann immer 0 gelesen wird, obwohl 3.3V anliegen. Ich habe eher den Eindruck, dass es ein Software Problem ist. Vielen Dank für Tips
Um welchen Pin handelt es sich denn? Manche Pins haben eine Defaultkonfiguration und ich weiß nicht, ob HAL diese entfernt wenn nicht explizit gefordert.
Ne Frage, wo finde ich diese Defaultkonfiguration. Unter Configuration finde ich nichts Aufälliges.
Beim ARM müssen die pins explizit auf Eingang geschaltet werden. Sonst steht im IDR nur Müll. Die pinread Funktion wird vmtl. einfach nur per bitmaskierung aus dem IDR lesen.
Soll ich die hochladen oder Bilder von der GUI machen. Hier ist der Code in Eclipse, sieht alles gut aus.
1 | |
2 | static void MX_GPIO_Init(void) |
3 | {
|
4 | |
5 | GPIO_InitTypeDef GPIO_InitStruct; |
6 | |
7 | /* GPIO Ports Clock Enable */
|
8 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
9 | |
10 | /*Configure GPIO pin : PB7 */
|
11 | GPIO_InitStruct.Pin = GPIO_PIN_7; |
12 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
13 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
14 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
15 | |
16 | }
|
Max D. schrieb: > Beim ARM müssen die pins explizit auf Eingang geschaltet werden. Sonst > steht im IDR nur Müll. Die pinread Funktion wird vmtl. einfach nur per > bitmaskierung aus dem IDR lesen. Die GPIOs der STM32 sind per default immer Eingang. GPIO7 ist bei diesem Controller schonmal nicht vorbelegt, daran kann es nicht liegen. Ist der Takt vom GPIOB aktiviert?
>> Ist der Takt vom GPIOB aktiviert? > __HAL_RCC_GPIOB_CLK_ENABLE(); Sieht danach aus, würde ich mal sagen.
Gibt es nun auch bald mal den ganzen Code, damit man auf das fehlende volatile hinweisen kann?
das ist echt seltsam, der liest immer nur ein HIGH, selbst wenn ich den taster drücke. Wie gesagt, habs gemessen, wenn ich drücke, liegt 0V am Pin an. Kann das sein, dass dieser chip schrott ist? habs bei digikey gekauft. Ich meine die uC sind super buggy, hardware und softwareseitig.
1 | /**
|
2 | ******************************************************************************
|
3 | * @file : main.c
|
4 | * @brief : Main program body
|
5 | ******************************************************************************
|
6 | ** This notice applies to any and all portions of this file
|
7 | * that are not between comment pairs USER CODE BEGIN and
|
8 | * USER CODE END. Other portions of this file, whether
|
9 | * inserted by the user or by software development tools
|
10 | * are owned by their respective copyright owners.
|
11 | *
|
12 | * COPYRIGHT(c) 2018 STMicroelectronics
|
13 | *
|
14 | * Redistribution and use in source and binary forms, with or without modification,
|
15 | * are permitted provided that the following conditions are met:
|
16 | * 1. Redistributions of source code must retain the above copyright notice,
|
17 | * this list of conditions and the following disclaimer.
|
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
19 | * this list of conditions and the following disclaimer in the documentation
|
20 | * and/or other materials provided with the distribution.
|
21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
|
22 | * may be used to endorse or promote products derived from this software
|
23 | * without specific prior written permission.
|
24 | *
|
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35 | *
|
36 | ******************************************************************************
|
37 | */
|
38 | /* Includes ------------------------------------------------------------------*/
|
39 | #include "main.h" |
40 | #include "stm32f0xx_hal.h" |
41 | |
42 | /* USER CODE BEGIN Includes */
|
43 | |
44 | /* USER CODE END Includes */
|
45 | |
46 | /* Private variables ---------------------------------------------------------*/
|
47 | |
48 | /* USER CODE BEGIN PV */
|
49 | /* Private variables ---------------------------------------------------------*/
|
50 | |
51 | /* USER CODE END PV */
|
52 | |
53 | /* Private function prototypes -----------------------------------------------*/
|
54 | void SystemClock_Config(void); |
55 | static void MX_GPIO_Init(void); |
56 | |
57 | /* USER CODE BEGIN PFP */
|
58 | /* Private function prototypes -----------------------------------------------*/
|
59 | |
60 | /* USER CODE END PFP */
|
61 | |
62 | /* USER CODE BEGIN 0 */
|
63 | |
64 | /* USER CODE END 0 */
|
65 | |
66 | /**
|
67 | * @brief The application entry point.
|
68 | *
|
69 | * @retval None
|
70 | */
|
71 | int main(void) |
72 | {
|
73 | /* USER CODE BEGIN 1 */
|
74 | // set_frequency();
|
75 | /* USER CODE END 1 */
|
76 | |
77 | /* MCU Configuration----------------------------------------------------------*/
|
78 | |
79 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
80 | HAL_Init(); |
81 | |
82 | /* USER CODE BEGIN Init */
|
83 | |
84 | |
85 | |
86 | /* USER CODE END Init */
|
87 | |
88 | /* Configure the system clock */
|
89 | SystemClock_Config(); |
90 | |
91 | /* USER CODE BEGIN SysInit */
|
92 | |
93 | /* USER CODE END SysInit */
|
94 | |
95 | /* Initialize all configured peripherals */
|
96 | MX_GPIO_Init(); |
97 | /* USER CODE BEGIN 2 */
|
98 | /*
|
99 | uint8_t check = SSD1306_Init(); // initialize the diaply
|
100 | |
101 | SSD1306_Fill(0); // fill the display with black color
|
102 | SSD1306_UpdateScreen(); // update screen
|
103 | |
104 | SSD1306_GotoXY(10,10); // goto 10, 10
|
105 | SSD1306_Puts("HELLO", &Font_11x18, 1); // print Hello
|
106 | |
107 | SSD1306_GotoXY(10, 30);
|
108 | SSD1306_Puts("WORLD !!", &Font_11x18, 1);
|
109 | |
110 | SSD1306_UpdateScreen(); // update screen
|
111 | */
|
112 | // char *msg = "Hello Nucleo Fun!\n\r";
|
113 | |
114 | /* USER CODE END 2 */
|
115 | |
116 | /* Infinite loop */
|
117 | /* USER CODE BEGIN WHILE */
|
118 | while (1) |
119 | {
|
120 | |
121 | /* USER CODE END WHILE */
|
122 | |
123 | /* USER CODE BEGIN 3 */
|
124 | |
125 | if (HAL_GPIO_ReadPin(GPIOB, 7) == 0) |
126 | {
|
127 | |
128 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, 1); |
129 | |
130 | }
|
131 | else
|
132 | {
|
133 | |
134 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, 0); |
135 | |
136 | }
|
137 | |
138 | }
|
139 | |
140 | /* USER CODE END 3 */
|
141 | |
142 | }
|
143 | |
144 | /**
|
145 | * @brief System Clock Configuration
|
146 | * @retval None
|
147 | */
|
148 | void SystemClock_Config(void) |
149 | {
|
150 | |
151 | RCC_OscInitTypeDef RCC_OscInitStruct; |
152 | RCC_ClkInitTypeDef RCC_ClkInitStruct; |
153 | |
154 | /**Initializes the CPU, AHB and APB busses clocks
|
155 | */
|
156 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; |
157 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; |
158 | RCC_OscInitStruct.HSICalibrationValue = 16; |
159 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; |
160 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
161 | {
|
162 | _Error_Handler(__FILE__, __LINE__); |
163 | }
|
164 | |
165 | /**Initializes the CPU, AHB and APB busses clocks
|
166 | */
|
167 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |
168 | |RCC_CLOCKTYPE_PCLK1; |
169 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; |
170 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
171 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
172 | |
173 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) |
174 | {
|
175 | _Error_Handler(__FILE__, __LINE__); |
176 | }
|
177 | |
178 | /**Configure the Systick interrupt time
|
179 | */
|
180 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
181 | |
182 | /**Configure the Systick
|
183 | */
|
184 | HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); |
185 | |
186 | /* SysTick_IRQn interrupt configuration */
|
187 | HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); |
188 | }
|
189 | |
190 | /** Configure pins as
|
191 | * Analog
|
192 | * Input
|
193 | * Output
|
194 | * EVENT_OUT
|
195 | * EXTI
|
196 | */
|
197 | static void MX_GPIO_Init(void) |
198 | {
|
199 | |
200 | GPIO_InitTypeDef GPIO_InitStruct; |
201 | |
202 | /* GPIO Ports Clock Enable */
|
203 | __HAL_RCC_GPIOF_CLK_ENABLE(); |
204 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
205 | |
206 | /*Configure GPIO pin Output Level */
|
207 | HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET); |
208 | |
209 | /*Configure GPIO pins : PF6 PF7 */
|
210 | GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; |
211 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
212 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
213 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
214 | HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); |
215 | |
216 | /*Configure GPIO pin : PB7 */
|
217 | GPIO_InitStruct.Pin = GPIO_PIN_7; |
218 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
219 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
220 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
221 | |
222 | }
|
223 | |
224 | /* USER CODE BEGIN 4 */
|
225 | |
226 | |
227 | /* USER CODE END 4 */
|
228 | |
229 | /**
|
230 | * @brief This function is executed in case of error occurrence.
|
231 | * @param file: The file name as string.
|
232 | * @param line: The line in file as a number.
|
233 | * @retval None
|
234 | */
|
235 | void _Error_Handler(char *file, int line) |
236 | {
|
237 | /* USER CODE BEGIN Error_Handler_Debug */
|
238 | /* User can add his own implementation to report the HAL error return state */
|
239 | while(1) |
240 | {
|
241 | }
|
242 | /* USER CODE END Error_Handler_Debug */
|
243 | }
|
244 | |
245 | #ifdef USE_FULL_ASSERT
|
246 | /**
|
247 | * @brief Reports the name of the source file and the source line number
|
248 | * where the assert_param error has occurred.
|
249 | * @param file: pointer to the source file name
|
250 | * @param line: assert_param error line source number
|
251 | * @retval None
|
252 | */
|
253 | void assert_failed(uint8_t* file, uint32_t line) |
254 | {
|
255 | /* USER CODE BEGIN 6 */
|
256 | /* User can add his own implementation to report the file name and line number,
|
257 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
258 | /* USER CODE END 6 */
|
259 | }
|
260 | #endif /* USE_FULL_ASSERT */ |
261 | |
262 | /**
|
263 | * @}
|
264 | */
|
265 | |
266 | /**
|
267 | * @}
|
268 | */
|
269 | |
270 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
> Ich meine die uC sind super buggy, hardware und softwareseitig. Wenn man nicht programmieren kann, schiebt man erstmal alles auf die Hard- und Software. So ist es richtig. Die STM32 sind absolut nicht buggy, zumindest nicht hardwareseitig. Die HAL... die lasse ich lieber weg bei meinen Projekten. Darauf würde ich mich nicht verlassen. Bare-Metal ist hier angesagt. Wenn Du "NOPULL" eingestellt hast, ist denn dann wenigstens ein Pullup-Widerstand am Pin dran? Wo soll denn sonst der High-Pegel herkommen?
OT: Ohne HAL wären das für mich keine 10 Zeilen Code gewesen.
ich hab leider 2. mal die ioc drin. hab noch den schaltplan mithochgeladen. sw ist der Switch, also der Taster. Vielen dank für eure Mühe.
richtig, im layout ist ein pull up. haha, jaa, ich überlege auch die hal zu lassen. das ding ist bloss in meinen vorherigen projekten hat es immer damit wunderbar geklappt.
hey jungs, glaub weiss woran das liegt, ich kann das nicht mit 0 und 1 vergleichen, die funktion returnt kein int.
Probiere mal folgendes, sofern du die Header + CMSIS richtig im Projekt eingefügt hast. Ist zwar nicht ganz die saubere Art mit manchen Bitmasken, darum gehts jetzt aber nicht:
1 | #include "stm32f0xx.h" |
2 | |
3 | int main(){ |
4 | RCC->AHBENR |= RCC_AHBENR_GPIOBEN; |
5 | RCC->AHBENR |= RCC_AHBENR_GPIOFEN; |
6 | GPIOF->MODER |= (0b01 << (2 * 7)); |
7 | GPIOB->OTYPER |= (1<<7); |
8 | |
9 | while(1){ |
10 | if(GPIOB->IDR & (1<<7)){ |
11 | GPIOF->ODR |= (1<<7); |
12 | }
|
13 | else{ |
14 | GPIOF->ODR &= ~(1<<7); |
15 | }
|
16 | }
|
17 | |
18 | return 0; |
19 | }
|
es hat geklappt! alter.... danke dir, vielen dank. die hal scheint irgendwas komisch zu machen. danke dir, ich werd auf die hal verzichten und auf registerebene weiter machen!
und danke für deine präzision. danke liebes forum, super hilfe!
Moin, eugen schrieb: > if (HAL_GPIO_ReadPin(GPIOB, 7) == 0) Man müsste die HAL Funktion nur mit dem korrekten Parameter aufrufen. * @param GPIO_Pin: specifies the port bit to read. * This parameter can be GPIO_PIN_x where x can be (0..15). Und GPIO_PIN_7 ist vom HAL definiert als: #define GPIO_PIN_7 ((uint16_t)0x0080U) /* Pin 7 selected */ Dann würde es auch mit HAL funktionieren (denke ich). Aber ich mag HAL auch nicht so richtig. Vielleicht hab ich angst, er bringt mich irgendwann mal um.
du hast recht, es war die ganze zeit mein fehler :D. anstatt die 5 reinzugeben, muss ich natürlich GPIO_PIN_7 nehmen. Leider war ich zu verballert selbst dadrauf zu kommen. Vielen lieben Dank euch:D
> Die STM32 sind absolut nicht buggy, zumindest nicht hardwareseitig. Demnach dürfte es kein Errata Dokument geben. > Die HAL... die lasse ich lieber weg bei meinen Projekten. Darauf würde > ich mich nicht verlassen. Bare-Metal ist hier angesagt. Ja, sehe ich auch so. > Aber ich mag HAL auch nicht so richtig. Vielleicht hab ich angst, er > bringt mich irgendwann mal um. Meinst du Hal Faber von Heise? Wieso abstrahiert die HAL eigentlich solch primitive Sachen? Damit erreicht man doch nichts. Ein Programm, das darauf aufbaut ist kein bisschen unabhängig von der Hardware, als wenn man direkt auf die Register (über die #defines der CMSIS) zugreifen würde. Ganz im Gegenteil, die HAL mach Abhängig von ST, was die CMSIS nicht tut.
Max D. schrieb: > Beim ARM müssen die pins explizit auf Eingang geschaltet werden. Sonst > steht im IDR nur Müll. Die pinread Funktion wird vmtl. einfach nur per > bitmaskierung aus dem IDR lesen. Da bin ich mir ziemlich sicher, dass das nicht für alle STM32 gilt. Vielleicht gilt es für manche (F1? bin mir nicht sicher). Grundsätzlich kann man das IDR auch auslesen wenn der Port als Output konfiguriert ist. Zum testen einfach mal eine LED blinken lassen, ab und zu mit dem Debugger anhalten und das entsprechende IDR checken.
Es gibt zu JEDEM µC von JEDEM Hersteller ein errata und es gibt KEINEN fehlerfreien µC von irgendeinem Hersteller. Darüber sollte man sich im klaren sein. Aber die meisten µC aller Hersteller sind in 99% ihrer Funktionalität fehlerfrei. eugen schrieb: > danke dir, ich werd auf die hal verzichten und auf registerebene weiter > machen! Das ist eine weise Entscheidung. So lernst du wirklich, was da passiert und kannst fehlerfrei, sowie optimierend programmieren.
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.