STM8运行卡在“while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)”
ADC、UART、中断都配置好了,但是运行时,卡停在UART返回函数里return status;有知道是什么问题吗?请赐教!
//这是主函数部分
#include "stm8s.h"
#include "stdio.h"
void ALL_Config(void);
void Light_ADC_Config(void);
void USART1_Config(void);
void USART1_SendByte(u8 data);
char putchar(char ch);
void Delay(uint16_t time);
main()
{
enableInterrupts();
ALL_Config();
while (1){
printf("发送%d\r\n");
}
}
//这是ADC、UART配置文件部分
/*************************************
*所有功能初始化
*************************************/
void ALL_Config(void)
{
Light_ADC_Config();
LIGHT_GPIO_Config();
USART1_Config();
}
/*************************************
*ADC功能配置
*AIN:4
*PORT:PD3
*参数:连续性、通道4、分频2、右对齐
*************************************/
void Light_ADC_Config(void)
{
GPIO_Init(GPIOD, GPIO_PIN_3, GPIO_MODE_IN_FL_NO_IT);
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS, ADC1_CHANNEL_4, ADC1_PRESSEL_FCPU_D2, ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4, DISABLE);
ADC1_ITConfig(ADC1_IT_EOCIE, ENABLE);
ADC1_Cmd(ENABLE);
//ADC功能转换开启
ADC1_StartConversion();
}
/*************************************
*USART功能配置
*9600、8、1、NO
*************************************/
void USART1_Config(void)
{
UART1_DeInit();
UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
UART1_Cmd(ENABLE);
}
/*************************************
*USART发送信息
*************************************/
void USART1_SendByte(u8 data)
{
UART1_SendData8(data);
while(UART1_GetFlagStatus(UART1_FLAG_TC) == RESET);
}
/*************************************
*USART打印信息(Printf)
*************************************/
char putchar(char ch)
{
USART1_SendByte((u8)ch);
return (ch);
}
/*************************************
*粗略延时
*************************************/
void Delay(uint16_t time)
{
while(time != 0){
nop();
time -- ;
}
}
@far @interrupt void ADC1_IRQ(void)
{
u16 ADC_Value;
float ADC_Vin;
ADC1_ClearITPendingBit(ADC1_IT_EOC);
ADC1_ClearFlag(ADC1_FLAG_EOC);
ADC_Value = ADC1_GetConversionValue();
printf("ADC_Value:%d\r\n",(uint16_t)ADC_Value);
ADC_Vin = ( ADC_Value / 1024 ) * 3.3;
printf("ADC_Vin:%.2f\r\n",ADC_Vin);
}
//中断文件部分
@far @interrupt void ADC1_IRQ(void);
typedef void @far (*interrupt_handler_t)(void);
struct interrupt_vector {
unsigned char interrupt_instruction;
interrupt_handler_t interrupt_handler;
};
@far @interrupt void NonHandledInterrupt (void)
{
/* in order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction
*/
return;
}
extern void _stext(); /* startup routine */
struct interrupt_vector const _vectab[] = {
{0x82, (interrupt_handler_t)_stext}, /* reset */
{0x82, NonHandledInterrupt}, /* trap */
{0x82, NonHandledInterrupt}, /* irq0 */
............................
{0x82, NonHandledInterrupt}, /* irq21 */
{0x82, ADC1_IRQ}, /* irq22 */
{0x82, NonHandledInterrupt}, /* irq23 */
............................
};
串口的引脚gpio时钟和串口时钟都没打开,而且gpio都没做复用配置,肯定数据发送不出去啦。