cancel
Showing results for 
Search instead for 
Did you mean: 

No output on CCO pin even after CCOR is Enabled.

AVish.12
Associate

Dear Community Members,

I recently started my venture with STM8S Micro-controller. I bought an STM8S103F3P6 Chip. 

The very first thing i want to understand is Clock Control of the MCU.

Therefore i set the MCU to HSE 16MHz. Although I wanted to see if it really is working on 16MHz, I decided to use the controller's clock output capability.

Here's my main code:

#include <stdint.h>
#include "stm8s_system.h"
#include "delay.h"
 
#define F_CPU						16000000UL
 
#define RED_LED_PIN					4
#define GREEN_LED_PIN				6
#define BLUE_LED_PIN				5
 
#define DEBUG_PIN						3
#define CLOCK_OUTPUT_PIN		4
 
void main()
{
		PORTC_DDR|=(1<<CLOCK_OUTPUT_PIN);
		PORTC_CR1|=(1<<CLOCK_OUTPUT_PIN);
		PORTC_CR2|=(1<<CLOCK_OUTPUT_PIN);
		
		PORTC_DDR|=(1<<DEBUG_PIN);
		PORTC_CR1|=(1<<DEBUG_PIN);
		PORTC_CR2|=(1<<DEBUG_PIN);
		
		CLK_CCOR|=0x08;
		CLK_CCOR|=0x01;
		System_Clock_Init_External();
		
	
		
		PORTD_DDR|=(1<<GREEN_LED_PIN);
		PORTD_CR1|=(1<<GREEN_LED_PIN);
		PORTD_CR2|=(1<<GREEN_LED_PIN);
		
		while(1)
		{
				TOGGLE_PIN(PORTD_ODR,GREEN_LED_PIN);
				TOGGLE_PIN(PORTC_ODR,DEBUG_PIN);
				delay_ms(20);
		}
}

Here's how i am accessing registers:

#define OFFSET_ADDRESS			0x5000
#define SFR(addr)				(*(volatile unsigned char *)(OFFSET_ADDRESS + (addr)))
 
#define PORTC_ODR					SFR(0x0A)
#define PORTC_IDR					SFR(0x0B)
#define PORTC_DDR					SFR(0x0C)
#define PORTC_CR1					SFR(0x0D)
#define PORTC_CR2					SFR(0x0E)
 
#define CLK_ICKR					SFR(0xC0)
#define CLK_ECKR					SFR(0xC1)
#define CLK_CMSR					SFR(0xC3)
#define CLK_SWR						SFR(0xC4)
#define CLK_SWCR					SFR(0xC5)
#define CLK_CKDIVR				         aSFR(0xC6)
#define CLK_PCKENR1				SFR(0xC7)
#define CLK_CSSR					SFR(0xC8)
#define CLK_CCOR					SFR(0xC9)
#define CLK_PCKENR2				SFR(0xCA)
#define CLK_HSITRIMR			        SFR(0xCC)
#define CLK_SWIMCCR				SFR(0xCD)

Here's my external clock init function:

void System_Clock_Init_External(void)
{
	CLEAR_REGISTER(CLK_ICKR,0xFF);
	SET_BIT_IN_REGISTER(CLK_ECKR,0);
	while(!(READ_REGISTER_BIT(CLK_ECKR,1)));
	CLEAR_REGISTER(CLK_CKDIVR,0xFF);
	SET_REGISTER(CLK_PCKENR1,0xFF);
	SET_REGISTER(CLK_PCKENR2,0xFF);
	//CLEAR_REGISTER(CLK_CCOR,0xFF);
	CLEAR_REGISTER(CLK_HSITRIMR,0xFF);
	CLEAR_REGISTER(CLK_SWIMCCR,0xFF);
	CLEAR_REGISTER(CLK_SWCR,0xFF);
	SET_REGISTER(CLK_SWR,0xB4);
	SET_BIT_IN_REGISTER(CLK_SWCR,1);
	while((READ_REGISTER_BIT(CLK_SWCR,0)));
}

When i check the output on pin PC4 on an Oscilloscope, all i get 1.4V DC Voltage.

What is it that i am missing?

1 REPLY 1
DGoul
Associate

Do you mean to set HSE, or HSI. That is, do you actually have an external 16 MHz clock signal, or are you using the internal highspeed oscillator?