Stm32f103 Usart Parity Sorunu

Başlatan ugurer, 06 Mart 2018, 14:08:43

ugurer

Merhaba arkadaşlar, keil ve stm32f103 ile usart kullanıyorum. Proje gereği baudrate 9600 ve parity even olmalı. Fakat usart parity even seçtiğimde saçmalıyor.
Deneme amaçlı sadece kesme fonksiyonu olan bir fonksiyon yazdım gönderdiğim değeri geri okuyorum. Fakat hex olarak 01'i 81 02'yi 82 olarak gönderiyor. Fakat 03'ü düzgün şekilde gönderiyor ve bu sıkıntı sadece parity even olduğunda geçerli diğer durumlarda bir sorun yok. Kullandığım kodlar aşağıdadır.
void init_USART1(int baudrate)
{
	GPIO_InitTypeDef GPIO_InitStruct;
	USART_InitTypeDef USART_InitStruct;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
	
	GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
	GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
	GPIO_InitStruct.GPIO_Speed =GPIO_Speed_50MHz;
	GPIO_Init(GPIOA,&GPIO_InitStruct);
	
	USART_InitStruct.USART_BaudRate = baudrate;
	USART_InitStruct.USART_WordLength = USART_WordLength_8b;
	USART_InitStruct.USART_StopBits = USART_StopBits_1;
	USART_InitStruct.USART_Parity = USART_Parity_Even;
	USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
	USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	USART_Init(USART1, &USART_InitStruct);
	
	USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
	
	NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);	
	
	USART_Cmd(USART1,ENABLE);
}
void USART1_IRQHandler(void){
	
	// check if the USART1 receive interrupt flag was set
	if( USART_GetITStatus(USART1, USART_IT_RXNE) ){
		
		static uint8_t cnt = 0; // this counter is used to determine the string length
		char t = USART1->DR; // the character from the USART1 data register is saved in t
		
		// check if the received character is not the LF character (used to determine end of string) 
		// or the if the maximum string length has been been reached 
//		if( (t != '\n') && (cnt < MAX_STRLEN) ){ 
//			received_string[cnt] = t;
//			cnt++;
//		}
//		else{ // otherwise reset the character counter and print the received string
			cnt = 0;
			USART_SendData(USART1,t); //USART_puts(USART1, received_string);
			while( !(USART1->SR & 0x00000040) ); 
//		}
	}
}


ugurer