Skip to main content
Visitor II
February 27, 2014
Question

STM8S003F PD4 doesn't work as GPIO

  • February 27, 2014
  • 4 replies
  • 1752 views
Posted on February 27, 2014 at 14:44

Hi all!

I am using STM8S003F microcontroller with UART in async mode. I want to use UART1_CK pin as regular GPIO in push-pull mode. This pin is PD4. When peripherals are configured as below:

    PD_DDR_DDR4 = 1;   //  Pin PD4 (EN) is output

    PD_CR1_C14 = 1;    //  Pin PD4 is set to P-P mode.

    PD_CR2_C24 = 1;    //  Pin PD4 can run up to 10 MHz.

    UART1_CR3_CKEN = 1;

and byte is transmitted via UART, I see clock meander appearing on PD4 on each byte transmission. Then I disable UART clock output by writing:

   UART1_CR3_CKEN = 0;

After that pin PD4 goes low, and writing

 

  PD_ODR_ODR4 = 1;

gives nothing. High logic level doesn't appear on PD4 pin.

What's wrong with my code? What else should I check?

#stm8s003f3 #pd4 #push-pull
    This topic has been closed for replies.

    4 replies

    Visitor II
    February 27, 2014
    Posted on February 27, 2014 at 15:32

    I am not experienced, but check if it is needed to disable UART ( not just turning its clock off ) to cancel its control over the connected pins

    kiroidAuthor
    Visitor II
    February 27, 2014
    Posted on February 27, 2014 at 16:15

    The problem is that I need the UART =) In my circuit PD4 is intended for driving ENABLE pin of RS485 chip.

    kiroidAuthor
    Visitor II
    March 3, 2014
    Posted on March 03, 2014 at 20:36

    It seems that's because of TIM2_CH1, which could be mapped to PD4. Investigation is in process =)

    kiroidAuthor
    Visitor II
    March 11, 2014
    Posted on March 11, 2014 at 11:59

    Solved. TIM2_CH1 output is mapped to PD4 by default. I had to remap this output to PC5 by setting AFR0 option bit.