2018-05-14 10:23 AM
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?
Solved! Go to Solution.
2018-05-16 10:13 PM
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 lowwith 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
2018-05-15 12:01 AM
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
2018-05-15 07:58 AM
2018-05-15 01:03 PM
Check the datasheet to see what other functions may be active on that pin, by default or via the option bytes
2018-05-16 11:12 AM
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 interruptI missed something, but what?
2018-05-16 10:13 PM
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 lowwith 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
2018-05-17 11:12 AM
Hello,
That's correct answer.
Thank You very much !