cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S003F PD4 doesn't work as GPIO

kiroid
Associate II
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
4 REPLIES 4
abbas
Associate II
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

kiroid
Associate II
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.

kiroid
Associate II
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 =)

kiroid
Associate II
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.