之前内有用过STM8 一会再用STM32 做一个小项目时 觉得STM8也有库应该很方便就直接选了它,结果调试的时候各种心酸,本想着一天解决的任务,结果拖了三天。接下来介绍一下遇到的主要问题 以及解决方法。
1、IAR无法下载程序问题
首先关于芯片型号设置就不说了 网上一大堆,主要是Vcap 引脚对地电容的取值,网上普遍说1uF, 由于我做了两个板子 一个PCB一个覆铜板 PCB没问题 ,但是覆铜板1uF 就下不进去程序,后来改成0.1uF才可以。如果软件配置对了,现在不进去很有可能是这个电容的问题。
2、定时器进不去中断问题
尝试了TIM2 TIM4 都进不去,我是用的是风驰 分享的STM8s207寄存器版本的例程,其他都好 就是定时器不管用,各种都尝试了,就是进不去。后来对比发现 头文件对定时器地址定义不同,大家可以对比看一下 首先是stm8s103.h的头文件中对TIM2的定义
/*-------------------------------------------------------------------------其次是stm8s207头文件对TIM2的定义
* TIM2 register definitions
*-----------------------------------------------------------------------*/
/* TIM2 control register 1 */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char CEN : 1;
unsigned char UDIS : 1;
unsigned char URS : 1;
unsigned char OPM : 1;
unsigned char : 3;
unsigned char ARPE : 1;
} __BITS_TIM2_CR1;
#endif
__IO_REG8_BIT(TIM2_CR1, 0x5300, __READ_WRITE, __BITS_TIM2_CR1);
/* TIM2 Interrupt enable register */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char UIE : 1;
unsigned char CC1IE : 1;
unsigned char CC2IE : 1;
unsigned char CC3IE : 1;
unsigned char : 2;
unsigned char TIE : 1;
} __BITS_TIM2_IER;
#endif
__IO_REG8_BIT(TIM2_IER, 0x5303, __READ_WRITE, __BITS_TIM2_IER);
/* TIM2 status register 1 */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char UIF : 1;
unsigned char CC1IF : 1;
unsigned char CC2IF : 1;
unsigned char CC3IF : 1;
unsigned char : 2;
unsigned char TIF : 1;
} __BITS_TIM2_SR1;
#endif
__IO_REG8_BIT(TIM2_SR1, 0x5304, __READ_WRITE, __BITS_TIM2_SR1);
/*-------------------------------------------------------------------------
* TIM2 register definitions
*-----------------------------------------------------------------------*/
/* TIM2 control register 1 */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char CEN : 1;
unsigned char UDIS : 1;
unsigned char URS : 1;
unsigned char OPM : 1;
unsigned char : 3;
unsigned char ARPE : 1;
} __BITS_TIM2_CR1;
#endif
__IO_REG8_BIT(TIM2_CR1, 0x5300, __READ_WRITE, __BITS_TIM2_CR1);
/* TIM2 interrupt enable register */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char UIE : 1;
unsigned char CC1IE : 1;
unsigned char CC2IE : 1;
unsigned char CC3IE : 1;
unsigned char : 2;
unsigned char TIE : 1;
} __BITS_TIM2_IER;
#endif
__IO_REG8_BIT(TIM2_IER, 0x5301, __READ_WRITE, __BITS_TIM2_IER);
/* TIM2 status register 1 */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char UIF : 1;
unsigned char CC1IF : 1;
unsigned char CC2IF : 1;
unsigned char CC3IF : 1;
unsigned char : 2;
unsigned char TIF : 1;
} __BITS_TIM2_SR1;
#endif
__IO_REG8_BIT(TIM2_SR1, 0x5302, __READ_WRITE, __BITS_TIM2_SR1);
/* TIM2 status register 2 */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char : 1;
unsigned char CC1OF : 1;
unsigned char CC2OF : 1;
unsigned char CC3OF : 1;
} __BITS_TIM2_SR2;
#endif
__IO_REG8_BIT(TIM2_SR2, 0x5303, __READ_WRITE, __BITS_TIM2_SR2);
/* TIM2 event generation register */
#ifdef __IAR_SYSTEMS_ICC__
typedef struct
{
unsigned char UG : 1;
unsigned char CC1G : 1;
unsigned char CC2G : 1;
unsigned char CC3G : 1;
unsigned char : 2;
unsigned char TG : 1;
} __BITS_TIM2_EGR;
#endif
__IO_REG8_BIT(TIM2_EGR, 0x5304, __WRITE, __BITS_TIM2_EGR);