打印
[STM8]

STM8S208C8芯片的GPIOC.4管脚是否比较特殊

[复制链接]
2409|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
目前用STM8S208C8芯片,发现初始化GPIOC.4管脚为推挽输出,程序运行出错提示:error:gdi-error[40127]:flash memory not accessible while core is running.
把GPIOC.4管脚设置为上拉输出,程序运行部报错,但是输出不了高电平;
把GPIOC.4管脚设置为推挽输出,去掉外围电路,又正常了

代码:
    GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT_PP_HIGH_FAST;//GPIO_MODE_OUT_OD_LOW_FAST;//
    GPIO_InitStructure.GPIO_Pin = GPIO_PC4;
    GPIO_Init(GPIOC, &GPIO_InitStructure);

void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Init_TypeDef* GPIO_InitStruct)
{

  /*----------------------*/
  /* Check the parameters */
  /*----------------------*/

        assert_param(IS_GPIO_MODE_OK(GPIO_InitStruct->GPIO_Mode));
        assert_param(IS_GPIO_PIN_OK(GPIO_InitStruct->GPIO_Pin));

  /*-----------------------------*/
  /* Input/Output mode selection */
  /*-----------------------------*/

        if ((((u8)(GPIO_InitStruct->GPIO_Mode)) & (u8)0x80) != (u8)0x00) /* Output mode */
        {
                if ((((u8)(GPIO_InitStruct->GPIO_Mode)) & (u8)0x10) != (u8)0x00) /* High level */
                {
                        GPIOx->ODR |= GPIO_InitStruct->GPIO_Pin;
                }
                else /* Low level */
                {
                        GPIOx->ODR &= (u8)(~(GPIO_InitStruct->GPIO_Pin));
                }
    /* Set Output mode */
                GPIOx->DDR |= GPIO_InitStruct->GPIO_Pin;
        }
        else /* Input mode */
        {
        /* Set Input mode */
                GPIOx->DDR &= (u8)(~(GPIO_InitStruct->GPIO_Pin));
        }

  /*------------------------------------------------------------------------*/
  /* Pull-Up/Float (Input) or Push-Pull/Open-Drain (Output) modes selection */
  /*------------------------------------------------------------------------*/

        if ((((u8)(GPIO_InitStruct->GPIO_Mode)) & (u8)0x40) != (u8)0x00) /* Pull-Up or Push-Pull */
        {
                GPIOx->CR1 |= GPIO_InitStruct->GPIO_Pin;
        }
        else /* Float or Open-Drain */
        {
                GPIOx->CR1 &= (u8)(~(GPIO_InitStruct->GPIO_Pin));
        }

  /*-----------------------------------------------------*/
  /* Interrupt (Input) or Slope (Output) modes selection */
  /*-----------------------------------------------------*/

        if ((((u8)(GPIO_InitStruct->GPIO_Mode)) & (u8)0x20) != (u8)0x00) /* Interrupt or Slow slope */
        {
                GPIOx->CR2 |= GPIO_InitStruct->GPIO_Pin;
        }
        else /* No external interrupt or No slope control */
        {
                GPIOx->CR2 &= (u8)(~(GPIO_InitStruct->GPIO_Pin));
        }

}

出错代码:GPIOx->CR1 |= GPIO_InitStruct->GPIO_Pin;

电路:
沙发
zhzzh18|  楼主 | 2015-6-8 11:44 | 只看该作者
附上GPIOC.4的外围电路

Image 2.png (18.19 KB )

Image 2.png

使用特权

评论回复
板凳
zhzzh18|  楼主 | 2015-6-8 11:47 | 只看该作者
再说一个,就是这个代码在STM8S208R8上没问题,原先是用R8芯片的,程序运行没问题,现在要用C8芯片替换,代码是不变的。

使用特权

评论回复
地板
mmuuss586| | 2015-6-8 12:26 | 只看该作者
把GPIOC.4管脚设置为推挽输出,去掉外围电路,又正常了

这个感觉是硬件问题,多焊几块板子看看;

使用特权

评论回复
5
zhzzh18|  楼主 | 2015-6-8 13:50 | 只看该作者
to:mmuuss586
已经焊了两块,两块都一样的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

10

主题

34

帖子

1

粉丝