cancel
Showing results for 
Search instead for 
Did you mean: 

STM8L152C6T6 USART1 Interrupt mode

sushil
Associate II
Posted on January 13, 2015 at 08:22

Hi,

I am trying to transfer and read data from USART1 in interrupt mode but failed to do so. I successfully communicated with the polled method. I am not able to run any interrupt.

No interrupt is executed as I write in ISR to on led but not reached to interrupt handler. that means inerrupt is not executed.

My codes are

void USART_init(unsigned int BaudRate);

void USART_Tx_Buffer(char *Str);

main()

{

        DeInitClock();

DeInitGPIO(); 

/* Select HSI as system clock source */

&sharpifdef USE_HSI

CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);

CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);

&sharpelse

CLK_SYSCLKSourceSwitchCmd(ENABLE);

/* Select 2MHz HSE as system clock source */

CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSE);

CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_4);

CLK_HSICmd(DISABLE);

&sharpendif

RS232_ON();

UART_PORT_PIN_HIGH();

USART_init(9600);

enableInterrupts();

USART_Tx_Buffer(''t'');

}

void USART_init(unsigned int BaudRate)

{

 USART_Cmd(USART1,ENABLE);

 USART_DeInit(USART1); 

 CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);  

 USART_Init(USART1,BaudRate,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,USART_Mode_Tx|USART_Mode_Rx); 

 USART_ClockInit(USART1,USART_Clock_Enable,USART_CPOL_Low, USART_CPHA_1Edge,USART_LastBit_Disable); 

 USART_ReceiverWakeUpCmd(USART1,SET);

 USART_ITConfig(USART1,USART_IT_RXNE|USART_IT_TXE,ENABLE); 

}

void USART_Tx_Buffer(char *Str)

    char Str_Length=0,i=0;

 Str_Length=strlen(Str);

for(i=0;i<=Str_Length;i++)

{

while(USART_GetFlagStatus(USART1,USART_FLAG_TXE) == RESET);  

USART_SendData8(USART1,*Str++);  

while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);

//Rx_Data_Buffer[i] = USART_ReceiveData8(USART1);    

 }

}

In stm8it.c file

INTERRUPT_HANDLER(USART1_RX_IRQHandler,28)

{

/* In order to detect unexpected events during development,

   it is recommended to set a breakpoint on the following instruction.

*/

  //while (1);

portB_led=ON;

}

#stm8l152c6t6-usart1-interrupt-mo
0 REPLIES 0