вот мой код:
CODE
#include "stm32f10x.h"
void delay() {
unsigned long int i;
for(i = 0; i <= 200000; i = i + 1){};
}
void ADC_init() {
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div8;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_10Cycles;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Left;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvNone;
ADC_InitStructure.ADC_EXternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_Deinit(ADC1);
ADC_AnalogWatchdogCmd(ADC1, DISABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_Init(ADC1, &ADC_InitStructure);
}
void GPIO_init() {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void RCC_init() {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
}
void USARTinit() {
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART1);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ClearFlag(USART1, USART_FLAG_CTS | USART_FLAG_LBD | USART_FLAG_TC | USART_FLAG_RXNE);
USART_Cmd(USART1, ENABLE);
}
int main(void) {
unsigned char k=0;
RCC_init();
ADC_init();
GPIO_init();
USARTinit();
while (1) {
GPIO_SetBits(GPIOC, GPIO_Pin_9);
GPIO_ResetBits(GPIOC, GPIO_Pin_8);
k=k+1;
USART_SendData(USART1, 'k');
delay();
GPIO_ResetBits(GPIOC, GPIO_Pin_9);
GPIO_SetBits(GPIOC,GPIO_Pin_8);
USART_SendData(USART1, '5');
delay();
}
}
void delay() {
unsigned long int i;
for(i = 0; i <= 200000; i = i + 1){};
}
void ADC_init() {
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div8;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_10Cycles;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Left;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvNone;
ADC_InitStructure.ADC_EXternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_Deinit(ADC1);
ADC_AnalogWatchdogCmd(ADC1, DISABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_Init(ADC1, &ADC_InitStructure);
}
void GPIO_init() {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void RCC_init() {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
}
void USARTinit() {
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART1);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ClearFlag(USART1, USART_FLAG_CTS | USART_FLAG_LBD | USART_FLAG_TC | USART_FLAG_RXNE);
USART_Cmd(USART1, ENABLE);
}
int main(void) {
unsigned char k=0;
RCC_init();
ADC_init();
GPIO_init();
USARTinit();
while (1) {
GPIO_SetBits(GPIOC, GPIO_Pin_9);
GPIO_ResetBits(GPIOC, GPIO_Pin_8);
k=k+1;
USART_SendData(USART1, 'k');
delay();
GPIO_ResetBits(GPIOC, GPIO_Pin_9);
GPIO_SetBits(GPIOC,GPIO_Pin_8);
USART_SendData(USART1, '5');
delay();
}
}
у меня есть вопросы по usart
1) вот у меня допустим есть char k=91; как мне ее передать по уарту - USART_SendData(USART1,k) не работает
2) хочу запустить АЦП одиночное преобразование - пока столкнулся с такими ошибками
main.c: In function 'ADC_init':
main.c:10:1: error: 'ADC_CommonInitTypeDef' undeclared (first use in this function)
main.c:10:1: note: each undeclared identifier is reported only once for each function it appears in
main.c:10:24: error: 'ADC_CommonInitStructure' undeclared (first use in this function)
main.c:12:45: error: 'ADC_DMAAccessMode_Disabled' undeclared (first use in this function)
main.c:13:36: error: 'ADC_Mode_independent' undeclared (first use in this function)
main.c:14:41: error: 'ADC_Prescaler_Div8' undeclared (first use in this function)
main.c:15:48: error: 'ADC_TwoSamplingDelay_10Cycles' undeclared (first use in this function)
main.c:19:42: error: 'ADC_ExternalTrigConvNone' undeclared (first use in this function)
main.c:20:18: error: 'ADC_InitTypeDef' has no member named 'ADC_EXternalTrigConvEdge'
main.c:20:46: error: 'ADC_ExternalTrigConvEdge_None' undeclared (first use in this function)
main.c:22:18: error: 'ADC_InitTypeDef' has no member named 'ADC_NbrofChannel'
main.c:23:18: error: 'ADC_InitTypeDef' has no member named 'ADC_NbrOfConversion'
main.c:24:18: error: 'ADC_InitTypeDef' has no member named 'ADC_Resolution'
main.c:24:36: error: 'ADC_Resolution_8b' undeclared (first use in this function)
main.c:27:1: warning: implicit declaration of function 'ADC_Deinit'
main.c:30:1: warning: implicit declaration of function 'ADC_CommonInit'
make: *** [cc] Ошибка 1
в чем прикол? файлы ацп кинуты в проект и в конф файле раскоменчены...