UART transmit works succesfully but reciever don't
The device I am using is F303K8T6.
I am trying to learn. I have no problem with transmitting.
But when it comes to receive data it don't works. Interrupt not rises.
But when I connect tx pin to rx pin it works well. Interrput rised.
The code and concerning images is as following.
void _baslat_(void);
void USART2_IRQHandler(void);
void _yaz_(uint8_t yaz);
char USART_Read(void);
char AAA = 0;
volatile int tetiklendim = 0;
void print_console(char *A){
int i;
for(i=0;A[i]!='\0';i++){
_yaz_(A[i]);
}
}
////////////////////////////////////// inside while loop
while (1)
{
/* USER CODE END WHILE */
if(tetiklendim){
print_console("Data Deteceted\n");
tetiklendim = 0;
}
else{
print_console("Failed to take\n");
}
HAL_Delay(1000);
/* USER CODE
* BEGIN 3 */
}
///////////////////////////////////////
void _baslat_(void){
//Activating Clocks
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_USART2_CLK_ENABLE();
//GPIO
GPIO_InitTypeDef decoy = {0};
decoy.Pin = GPIO_PIN_2|GPIO_PIN_3;
decoy.Alternate = GPIO_AF7_USART2;
decoy.Mode = GPIO_MODE_AF_PP;
decoy.Pull = GPIO_PULLUP;
decoy.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA,&decoy);
//USART2 settings
USART2->CR1 = 0;
USART2->BRR = (SystemCoreClock)/(9600);
USART2->CR1 |= (1<<5)|(1<<3)|(1<<2);
USART2->CR3 |= (1<<6);
USART2->CR1 |= 1;
//USART2 interrupts
NVIC_EnableIRQ(USART2_IRQn);
NVIC_SetPriority(USART2_IRQn,0);
}
volatile int trig = 0;
void USART2_IRQHandler(void){
trig ^= 1;
tetiklendim = 1;
AAA = USART_Read();
}
void _yaz_(uint8_t yaz){
//while (!(USART2->ISR & USART_ISR_TXE)); // Check to see if transmit data register is empty
USART2->TDR = (yaz & 0xFF); // Load TX data register with ch
int x = GPIOA->AFR;
while (!(USART2->ISR & (1<<6))); // Check to see if transmit data register is empty
}
char USART_Read(void)
{
//while (!(USART2->ISR & (1 << 5))){} // Check to see if recieve data register is empty
return USART2->RDR; // Load TX data register with ch
}
The picture above shows that transmisson works. But receiving don't works well.
The picture above shot when TX RX pin are shorted. Interrupts are rising.
Any idea why I can't receive data through my computer ?