cancel
Showing results for 
Search instead for 
Did you mean: 

I have written USART driver on STM8al3168. but i am not getting interrupt whenever data available on Receiving pin.

PKUMA.15
Associate

Hi,

here incoming data will be in the below format and on its basis i have done usart initialization for STM8AL3168 on required 9600 baud rate.

void USART1_Init(void)
{
	UART_DeInitialization(USART1);
	
	// Remap USART1 to Port A
	SYSCFG_REMAPPinConfig(REMAP_Pin_USART1TxRxPortA, ENABLE);
	
	/* Enable USART1 CLOCK */
    CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
	
	// Configure USART1 I/O pin's
	GPIO_Init(GPIOA, GPIO_Pin_2, GPIO_Mode_Out_PP_High_Fast) ; 	// PA2 -> WUC_UART_TX
	GPIO_Init(GPIOA, GPIO_Pin_3, GPIO_Mode_In_PU_No_IT) ; 		// PA3 -> WUC_UART_RX	
	
	// Since there is a 10 k resistor pull-up used in our Circuit 
	GPIO_ExternalPullUpConfig(GPIOA, GPIO_Pin_2, ENABLE);
       GPIO_ExternalPullUpConfig(GPIOA, GPIO_Pin_3, ENABLE);
	
	/* Set the word length bit according to USART_WordLength value */
	/* Set the Parity Control bit to USART_Parity value */
	USART1->CR1 = 0x14;		// word length = 1 Start bit, 9 Data bits, 1 STOP bit, parity control enable
	
	/* Set the STOP bits number according to USART_StopBits value */
	USART1->CR3 = 0x00;	// 1 stop bit
	
	// Baudrate
    // fMASTER = 16 MHz
    // Baudrate = 9600
    // => div = 16 000 000 / 9600 = 1667 = 0x0683
    //                                     0x 68    => BRR1
    //                                     0x0  3   => BRR2
    // Error % = (Calculated - Desired)BaudRate / Desired Baud Rate ----> (0.02%)
    // filled the BRR2 register 1st as per datasheet description
	USART1->BRR2 = 0x03;
	USART1->BRR1 = 0x68;
	
	/* Set TEN and REN bits according to USART_Mode value */
	/* Enable the UART Receive interrupt: this interrupt is generated when the UART
	receive data register is not empty */	
	USART1->CR2 = 0xAC;		// 1010 1100
	
	// Enable USART1
	USART1->CR1 &= (uint8_t)(~0x20);	// make USARTD bit low to start USART1
}

interrupt handler code:

INTERRUPT_HANDLER(USART1_RX_TIM5_CC_IRQHandler, 28)
{
  if(USART_GetFlagStatus(USART1 ,USART_FLAG_RXNE) == SET)		
  {
	// Clear the USART1's RXNE flags
	USART_ClearFlag(USART1,USART_FLAG_RXNE);
	// Read the USART DATA into a global variable
	global_var = USART_ReceiveData9(USART1);
	//USART1->DR = global_var ;			/* loopback same Data again just for verification */
  }
}

i am trying to get the data into one global variable and want to take some decisions on the basis of that data. but my code is not jumping into ISR.

please suggest me what should i do or initialization is right or not?

Thanks.

3 REPLIES 3
S.Meneses
Associate

Hello, did you finally solve this problem?

Having the same...

Cristian Gyorgy
Senior III

Hi!

How exactly are you sending data on the RX pin? I see you want to use a 9th parity bit, is this bit also transmitted correctly?

Try to activate the parity error interrupt to see if you have parity errors. Try to read the USART_SR, and you can see what is happening on your USART.

Validate in polled mode. Check and clear any flagging errors.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..