2021-08-05 07:07 AM
Hi,
I generate 2 mhz from the PORT / PIN C4 (CCO).
The problem is that instead of a square signal, I get a triangle signal.
What could be the reason????
On PORT / PIN A3 i can generate a square signal, but not on C4
I Use the STM8-SO8-DISCO Board in which the STM8S001JM3 is installed
Here is the Code.:
#include "stm8s.h"
#include "stm8s_gpio.h"
#include "stm8s_clk.h"
#define GPIO_PORT (GPIOA)
#define GPIO_PINS (GPIO_PIN_3)
#ifdef _COSMIC_
#define ASM _asm
#endif
#define STARTUP_SWIM_DELAY_5S \
{ \
ASM(" PUSHW X \n" \
" PUSH A \n" \
" LDW X, #0xFFFF \n" \
"loop1: LD A, #50 \n" \
\
"loop2: DEC A \n" \
" JRNE loop2 \n" \
\
" DECW X \n" \
" JRNE loop1 \n" \
\
" POP A \n" \
" POPW X " ); \
}
#define CONFIG_UNUSED_PINS_STM8S001 \
{ \
GPIOA->DDR |= GPIO_PIN_2; \
GPIOB->DDR |= GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_6 | GPIO_PIN_7; \
GPIOC->DDR |= GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7; \
GPIOD->DDR |= GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_7; \
GPIOE->DDR |= GPIO_PIN_5; \
GPIOF->DDR |= GPIO_PIN_4; \
}
void GPIO_Config(void);
void CLK_Config(void);
void main(void)
{
CLK_Config();
GPIO_Config();
/* delay for SWIM connection: ~5seconds */
STARTUP_SWIM_DELAY_5S;
/* configure unbonded pins */
CONFIG_UNUSED_PINS_STM8S001;
while(1)
{
GPIO_WriteLow(GPIOA,GPIO_PIN_3); // only for reading the frequency on another port
GPIO_WriteHigh(GPIOA,GPIO_PIN_3);
}
}
void GPIO_Config(void)
{
GPIO_Init(GPIO_PORT,GPIO_PINS, GPIO_MODE_OUT_PP_LOW_FAST );
GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_HIGH_FAST );
}
void CLK_Config(void)
{
CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
CLK_CCOConfig(CLK_OUTPUT_CPU);
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
CLK_CCOCmd(ENABLE);
}
2021-08-12 11:56 PM
Look at schematic. PC4 is connected to "user button" and bypassed by 100nF Capacitor (C12).
signal "STM8S001J3_USER_B"
2021-08-13 01:17 AM
thank you mdudka9,
i solved it last week, but thats is the correct answer !
thx again !