Skip to main content
Visitor II
May 14, 2018
Solved

STM8S103F3 PC4 problem

  • May 14, 2018
  • 5 replies
  • 2134 views
Posted on May 14, 2018 at 19:23

I am using cheap Chinese board with STM8103F3 chip.

I want to use PC4,PC5,PC6 and PC7 pins as inputs connected do keys.

With PC5-PC7 there is no problem. I configured them as pull-up input with interrupt, but PC4 is different.

If I set interrupt for this pin, my program hungs.

I unset interrupt and read GPIOC->IDR = 0xe8, which means that PC4 IDR bit is always 0.

I read also CLK->CCOR =0x00 and TIM1->CR1 =0x00 so TIM1 and output clock is disabled.

But earlier I use ADC1 with analog input 3 (port D2; ADC1->CSR|=0x03;)

I don't use analog input 2 which is alternate function for PC4.

I checked voltage on the pin = 3,29V (so pull-up works).

So how to force PC4 to work like other PC5-PC7 pins with working ADC1 on another channel?

    This topic has been closed for replies.
    Best answer by Artur IWANICKI
    Posted on May 17, 2018 at 07:13

    Hello,

    I have identified a guilty guy During your ADC configuration you have disabled Schmitt trigger for all analog input channels instead of turning it off only for used ones. In this case PC4 has disabled this option as well. If you have a look at reference manual (GPIO section, port block diagram) you will see that once Schmitt trigger is disabled, no signal is coming from the pin to input data register nor to external interrupt controller.

    And please have a look at the description of those registers in ADC section (24.11.10 in reference manual):

    'Bits 7:0 TD[7:0] Schmitt trigger disable low

          These bits are set and cleared by software. When a TDx bit is set, it disables the I/O port input

          Schmitt trigger of the corresponding ADC input channel x even if this channel is not being converted.

          This is needed to lower the static power consumption of the I/O port.

          0: Schmitt trigger enabled

          1: Schmitt trigger disabled'

    As a solution please replace lines:

    ADC1->TDRH=0xff;// Schmitt trigger disabled high

    ADC1->TDRL=0xff;// Schmitt Trigger disabled low

    with those ones:

    ADC1->TDRH=0xff;// Schmitt trigger disabled high

    ADC1->TDRL=0xfb;// Schmitt Trigger disabled low (except ADC_CH2 - PC4)

    It should help.

    Best regards,

    Artur

    5 replies

    ST Employee
    May 15, 2018
    Posted on May 15, 2018 at 09:01

    Hello,

    Would it be possible for you to share with me part of not working code, please (IO configuration)? How does look your configuration of alternate functions of this MCU (option bytes settings)?

    Thank you in advance,

    Best Regards,

    Artur

    Visitor II
    May 15, 2018
    Posted on May 15, 2018 at 16:58

    The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6vI&d=%2Fa%2F0X0000000by3%2FyfI6qEYnl0Skl5Cx.iM4swNUFpgzmyX2SvqF5ZooGWk&asPdf=false
    Visitor II
    May 15, 2018
    Posted on May 15, 2018 at 22:03

    Check the datasheet to see what other functions may be active on that pin, by default or via the option bytes 

    Visitor II
    May 16, 2018
    Posted on May 16, 2018 at 20:12

    I didn't change option bytes, but I read them all: OPT->OPT0 to OPT->OPT7 equals 0x00 which mean no alternate functions is turned on.

    PIN 14 main function (after reset) is PC4 and alternate function: configurable clock output/ Timer 1 -channel 4 /Analog input 2. I don't use TIM1 and clock output, Enabling bytes I mentioned in first post.

    IO pin configuration is simple:

    #define LEFT_PIN 0x10

    GPIOC->DDR&=~LEFT_PIN ;//set as input

    GPIOC->CR1|=LEFT_PIN;//pull-up input

    // GPIOC->CR2|=LEFT_PIN;  <- problematic line enabling interrupt

    I missed something, but what?

    ST Employee
    May 17, 2018
    Posted on May 17, 2018 at 07:13

    Hello,

    I have identified a guilty guy During your ADC configuration you have disabled Schmitt trigger for all analog input channels instead of turning it off only for used ones. In this case PC4 has disabled this option as well. If you have a look at reference manual (GPIO section, port block diagram) you will see that once Schmitt trigger is disabled, no signal is coming from the pin to input data register nor to external interrupt controller.

    And please have a look at the description of those registers in ADC section (24.11.10 in reference manual):

    'Bits 7:0 TD[7:0] Schmitt trigger disable low

          These bits are set and cleared by software. When a TDx bit is set, it disables the I/O port input

          Schmitt trigger of the corresponding ADC input channel x even if this channel is not being converted.

          This is needed to lower the static power consumption of the I/O port.

          0: Schmitt trigger enabled

          1: Schmitt trigger disabled'

    As a solution please replace lines:

    ADC1->TDRH=0xff;// Schmitt trigger disabled high

    ADC1->TDRL=0xff;// Schmitt Trigger disabled low

    with those ones:

    ADC1->TDRH=0xff;// Schmitt trigger disabled high

    ADC1->TDRL=0xfb;// Schmitt Trigger disabled low (except ADC_CH2 - PC4)

    It should help.

    Best regards,

    Artur

    Visitor II
    May 17, 2018
    Posted on May 17, 2018 at 18:12

    Hello,

    That's correct answer.

    Thank You very much !