cancel
Showing results for 
Search instead for 
Did you mean: 

Some GPIOs in the STM8S003FS isn't working in the normal PP_OUT mode

Aatif Shaikh1
Associate III

Hello,

I'm working on a project in which I want to generate some trigger output ( which is connected to a sound chip APR33A3). Hence, I'm using the controller STM8S003FS GPIOs to generate the trigger output. Unfortunately, for an unknown reason, some of the GPIOs are not working properly in the normal push-pull out mode. I've marked them in the Image attached below. The output of these GPIOs is staying unchanged (checked physically via multi-meter).

I'm also adding the snippet of my code, so, if I made any mistake please let me know.

The nor working pins are as follows:

  1. PA3 (HS)/[SPI_NSS] TIM2_CH3
  2. PD3 (HS)/AIN4/TIM2_CH2/ADC_ETR
  3. PD4 (HS)/UART1_CK/TIM2_CH1/BEEP
/* Includes ------------------------------------------------------------------*/
#include "stm8s.h"
#include "stm8s_conf.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <intrinsics.h>
 
 
/* GLOBAL DEFINITION ----------------------------------------------------------*/
  #define _KEY_0_PORT  ( GPIOD )
  #define _KEY_0_PIN     ( GPIO_PIN_2 )
 
  #define _KEY_1_PORT  ( GPIOD )
  #define _KEY_1_PIN     ( GPIO_PIN_3 )
 
//  #define _KEY_1_PORT  ( GPIOA )
//  #define _KEY_1_PIN     ( GPIO_PIN_3 )
 
//  #define _KEY_1_PORT  ( GPIOD )
//  #define _KEY_1_PIN     ( GPIO_PIN_4 )
 
  #define _KEY_2_PORT  ( GPIOC )
  #define _KEY_2_PIN     ( GPIO_PIN_3 )
 
  #define _KEY_3_PORT  ( GPIOC )
  #define _KEY_3_PIN     ( GPIO_PIN_4 )
 
  #define _KEY_4_PORT  ( GPIOC )
  #define _KEY_4_PIN     ( GPIO_PIN_5 )
 
  #define _KEY_5_PORT  ( GPIOC )
  #define _KEY_5_PIN     ( GPIO_PIN_6 )
 
  #define _KEY_6_PORT  ( GPIOC )
  #define _KEY_6_PIN     ( GPIO_PIN_7 )
 
 
 
/* GLOBAL VARIABLE ------------------------------------------------------------*/
ErrorStatus enClkInitstatus  = ERROR;
FlagStatus  enClkSetStatus   = RESET;  
uint32_t    ucClkFrequency   = RESET;
 
 
 
/* FUNCTION DEFINITION --------------------------------------------------------*/
/** 
  * @brief  FnCLKinit program.
  * @param  None
  * @retval None
  */
void FnCLKinit (void)
{
  
  /* CLK Deinit */  
     CLK_DeInit( );
 
  /* Configure the HSI prescaler to the optimal value */
     CLK_SYSCLKConfig( CLK_PRESCALER_HSIDIV1 ); 
     CLK_HSIPrescalerConfig( CLK_PRESCALER_HSIDIV1 );
  
  /* Configure the system clock to use HSI clock source and to run at 16Mhz */
     enClkInitstatus = CLK_ClockSwitchConfig( CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI,
     				  DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);   
     if(enClkInitstatus == ERROR) while(SET){ };
    
  /* Enable the HSI*/
     CLK_HSICmd( ENABLE );
     ucClkFrequency = CLK_GetClockFreq( );
     while ( (enClkSetStatus = CLK_GetFlagStatus(CLK_FLAG_HSIRDY)) != SET  ){  } ; 
}
 
/* FUNCTION DEFINITION --------------------------------------------------------*/
/**
  * @brief FnGPIOValueWrite
  * @param 
  * @retval None
  */
void FnGPIOValueWrite(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins,BitStatus bitst)
{
    if ( bitst == SET )
         GPIOx->ODR |= (uint8_t)PortPins;
    else GPIOx->ODR &= (uint8_t)(~PortPins);
}
 
 
/* FUNCTION DEFINITION --------------------------------------------------------*/
/**
  * @brief FnUsart1Send
  * @param ucData
  * @retval None
  */
void FnUsart1Send(char *ucData)
{
   uint16_t ucCnt = RESET ; 
    while (ucData[ucCnt] != NULL )
      {
       /* Write a character to the UART1 */
           UART1_SendData8(ucData[ucCnt]);
 
       /* Loop until the end of transmission */
           while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);
       /* Increament the counter */
           ucCnt++; 
      }     
}
 
 
/* FUNCTION DEFINITION --------------------------------------------------------*/
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main()
{
/* Configure the */
    FnCLKinit();
       
GPIO_DeInit(GPIOA); 
GPIO_DeInit(GPIOB); 
GPIO_DeInit(GPIOC); 
GPIO_DeInit(GPIOD);
 
/* Initialize I/Os in Output Mode */
GPIO_Init( _KEY_0_PORT, _KEY_0_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);    
GPIO_Init( _KEY_1_PORT, _KEY_1_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);    
GPIO_Init( _KEY_2_PORT, _KEY_2_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);    
GPIO_Init( _KEY_3_PORT, _KEY_3_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);    
GPIO_Init( _KEY_4_PORT, _KEY_4_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);    
GPIO_Init( _KEY_5_PORT, _KEY_5_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);    
GPIO_Init( _KEY_6_PORT, _KEY_6_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);      
        
FnGPIOValueWrite(_KEY_0_PORT,_KEY_0_PIN, RESET);
FnGPIOValueWrite(_KEY_1_PORT,_KEY_1_PIN, RESET);
FnGPIOValueWrite(_KEY_2_PORT,_KEY_2_PIN, RESET);
FnGPIOValueWrite(_KEY_3_PORT,_KEY_3_PIN, RESET);
FnGPIOValueWrite(_KEY_4_PORT,_KEY_4_PIN, RESET);   
FnGPIOValueWrite(_KEY_5_PORT,_KEY_5_PIN, RESET);
FnGPIOValueWrite(_KEY_6_PORT,_KEY_6_PIN, RESET);     
        
UART1_DeInit();
/* UART1 configuration ------------------------------------------------------*/
/* UART1 configured as follow:
  - BaudRate = 115200 baud   - Word Length = 8 Bits
  - One Stop Bit  - No parity
  - Receive and transmit enabled
  - UART1 Clock disabled
*/
 
UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1,
UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE,
UART1_MODE_TXRX_ENABLE); 
FnUsart1Send("TW_VOICE!\n\r");
	 
 while (SET)       
	  {
	      
	  }
}

5 REPLIES 5

First i would check if all pins of IC are properly connected/soldered to "board".

Next I would investigate real status of pin. By connecting external pullup or pulldown resistors you can identify if output is in Low, High, or HiZ configuration. And check if there is any dependency on selected GPIO_MODE_)

You can also check status of all configuration registers (CR1,CR2,DDR,ODR) if contains right values.

BTW: All mentioned pins are Timer 2 outputs - strange coincidence - suggesting check timer2 configuration (if it doesnt control pins).

Hello, I found the issue! for an unknown reason, some definitions were not successfully getting added during the preprocessing stage. So, I personally modified the definitions in the "stm8s.h" header file by uncommenting the #define STM8S003.

At top of block with these macros is line:

/* Uncomment the line below according to the target STM8S or STM8A device used in your

  application. */

Everybody who want use "Standad libraries" should uncomment one line to select target STM8 family.

You don't need to uncomment or modify the libraries if you can add the definition in the preprocessor. But as I mentioned earlier, for an unknown reason, even adding the definition in the preprocessor wasn't good enough. 0693W000006FQ30QAG.png

You are right. Adding preprocessor definition works for me (using STVD and Cosmic).