GPIO结构已定义,但在main中使用之前未初始化。一切正常但我仍然试图找到一个可以在GPIO_Init中使用的值。 GPIOx-> CR2与另一个值进行“或”运算,我不知道从哪里得到初始值GPIOx-> CR2。我唯一能想到的是该地址中有一个随机数。
这是固件附带的给定程序。我是C的新手,这可能是一个简单的问题。
谢谢,
克里斯
在Discovery微控制器附带的主要功能中。主要做的第一件事就是调用GPIO_Init。我把它包括在这里。
void GPIO_Init(GPIO_TypeDef * GPIOx,
uint8_t GPIO_Pin,
GPIO_Mode_TypeDef GPIO_Mode)
{
/ * * ---------------------- /
/ *检查参数* /
/ * ---------------------- * / assert_param(IS_GPIO_MODE(GPIO_Mode));
assert_param(IS_GPIO_PIN(GPIO_Pin)); / *将相应位重置为CR2寄存器中的GPIO_Pin * /
/ * * ----------------------------- /
/ *输入/输出模式选择* /
/ * ----------------------------- * / if((((uint8_t)(GPIO_Mode))&(uint8_t)0x80 )!=(uint8_t)0x00)/ *输出模式* /
{
if((((uint8_t)(GPIO_Mode))&(uint8_t)0x10)!=(uint8_t)0x00)/ *高级别* /
{
GPIOx-> ODR | = GPIO_Pin;
} else / *低级别* /
{
GPIOx-> ODR& =(uint8_t)(〜(GPIO_Pin));
}
/ *设置输出模式* /
GPIOx-> DDR | = GPIO_Pin;
} else / *输入模式* /
{
/ *设置输入模式* /
GPIOx-> DDR& =(uint8_t)(〜(GPIO_Pin));
}
我想你可以看到GPIOx-> CR2和GPIOx-> ODR和GPIOx-> DDR正被用来设置位。(用RED概述)我的想法是它们没有被函数GPIO_Init初始化,所以任何可以使用碰巧在该地址中的数字。
我是uC和C的初学者。感谢您的帮助。
克里斯
#infi
tize-a-structure#memory-mapped-peripherals
以上来自于谷歌翻译
以下为原文
The GPIO struct is defined but it is not initialized before it is used in main. Everything works but I am stuck with trying to find a value that I can use in GPIO_Init. GPIOx->CR2 is OR'd with another value and I don't know where to get the initial value GPIOx->CR2. The only thing I can think is that a random number is in that address.
This is in the given program that comes with the firmware. I am new to C and this is probably a simple problem.
Thanks,
Chris
In the main function that comes with the Discovery microcontroller. The first thing that main does is to call GPIO_Init. I have included it here.
void GPIO_Init(GPIO_TypeDef* GPIOx,
uint8_t GPIO_Pin,
GPIO_Mode_TypeDef GPIO_Mode)
{
/*----------------------*/
/* Check the parameters */
/*----------------------*/ assert_param(IS_GPIO_MODE(GPIO_Mode));
assert_param(IS_GPIO_PIN(GPIO_Pin)); /* Reset crresponding bit to GPIO_Pin in CR2 register */
/*-----------------------------*/
/* Input/Output mode selection */
/*-----------------------------*/ if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x80) != (uint8_t)0x00) /* Output mode */
{
if ((((uint8_t)(GPIO_Mode)) & (uint8_t)0x10) != (uint8_t)0x00) /* High level */
{
GPIOx->ODR |= GPIO_Pin;
} else /* Low level */
{
GPIOx->ODR &= (uint8_t)(~(GPIO_Pin));
}
/* Set Output mode */
GPIOx->DDR |= GPIO_Pin;
} else /* Input mode */
{
/* Set Input mode */
GPIOx->DDR &= (uint8_t)(~(GPIO_Pin));
}
I think you can see that GPIOx->CR2 and GPIOx->ODR and GPIOx->DDR are being used to set bits.(Outlined in RED) My thinking is that they are not initialized by the function GPIO_Init yet so any number that happens to be in that address could be used.
I am a beginner in both uC's and C. Thanks for your help.
Chris
#initialize-a-structure #memory-mapped-peripherals