EasyManuals Logo

STMicroelectronics STM8 User Manual

STMicroelectronics STM8
126 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #122 background imageLoading...
Page #122 background image
Finally, the last segment enables/disables peripheral clocks:
CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, DISABLE);
This segment is very important and should always be rechecked. Different chips have different internal
hardware peripheral and so this segment will be different. For instance, STM8S105 has no UART1
module but it has UART2 instead. Research which hardware are available in your target micro and
then code this segment. I ended up with several wasted hours of finding trouble in various cases only
to find that I didn’t enable the required hardware.
Configuring Similar Stuffs Quickly
Sometimes you may end up doing the same stuff over and over again while you could have done it
simply with one or two lines of code. For example, in the LCD library, the GPIOs that connect with the
LCD share the same configurations. All are fast push-pull outputs.
GPIO_Init(LCD_PORT, LCD_RS, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(LCD_PORT, LCD_EN, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(LCD_PORT, LCD_DB4, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(LCD_PORT, LCD_DB5, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(LCD_PORT, LCD_DB6, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(LCD_PORT, LCD_DB7, GPIO_MODE_OUT_PP_HIGH_FAST);
This can be done in a more simplistic manner with just one line of code:
GPIO_Init(LCD_PORT, ((GPIO_Pin_TypeDef)(LCD_RS | LCD_EN | LCD_DB4 | LCD_DB5 | LCD_DB6 | LCD_DB7)),
GPIO_MODE_OUT_PP_HIGH_FAST);
As you can see it is just a bunch of logical OR operation. The same method is applicable for other
peripherals that share the same initialization function.
Some Stuffs About Cosmic C and SPL
Functions, variables and definitions in Cosmic C are case sensitive.
Functions with no arguments must not have empty argument areas. For example, you
cannot write:
void setup ();
You should write it as:
void setup (void);

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the STMicroelectronics STM8 and is the answer not in the manual?

STMicroelectronics STM8 Specifications

General IconGeneral
BrandSTMicroelectronics
ModelSTM8
CategoryMicrocontrollers
LanguageEnglish

Related product manuals