This commit is contained in:
crinq
2014-12-18 15:12:44 +01:00
3 changed files with 34 additions and 33 deletions

View File

@@ -234,38 +234,6 @@ void TIM5_IRQHandler(void){ //5KHz
}
}
void usart_init(){
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
//USART TX
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOC, &GPIO_InitStruct);
//USART RX
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOC, &GPIO_InitStruct);
USART_InitStruct.USART_BaudRate = 2000000;//2000000
USART_InitStruct.USART_WordLength = USART_WordLength_9b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStruct);
/* Enable the USART */
USART_Cmd(USART3, ENABLE);
}
#define DATALENGTH 3
typedef union{
@@ -341,7 +309,6 @@ int main(void)
link_hal_pins("pwm2uart0.vout", "net0.v");
link_hal_pins("pwm2uart0.wout", "net0.w");
usart_init();
data_t data;
while(1) // Do not exit

View File

@@ -54,6 +54,7 @@ void setup(){
setup_adc();
//setup_dma();
setup_pid_timer();
setup_usart();
// systick timer
time = 0;
@@ -69,6 +70,38 @@ void setup(){
#endif
}
void setup_usart(){
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
//USART TX
GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOD, &GPIO_InitStruct);
//USART RX
GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOD, &GPIO_InitStruct);
USART_InitStruct.USART_BaudRate = 2000000;//2000000
USART_InitStruct.USART_WordLength = USART_WordLength_9b;
USART_InitStruct.USART_StopBits = USART_StopBits_1;
USART_InitStruct.USART_Parity = USART_Parity_No;
USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3, &USART_InitStruct);
/* Enable the USART */
USART_Cmd(USART3, ENABLE);
}
void setup_pid_timer(){
/* TIM5 clock enable */

View File

@@ -48,6 +48,7 @@ void setup();
void setup_adc();
void setup_pwm();
void setup_pid_timer();
void setup_usart();
void setup_dma();
void SysTick_Handler(void);