2015-08-22 11:54 PM
Hi,
I am new to use STM8L controller.I am just trying to put Simple character on UART using STM8L discovery board.But I am failed to do this.Following is my code for this.void main(void){ u8 Data = 'N'; CLK_DeInit(); GPIO_DeInit(GPIOC); CLK_HSICmd(ENABLE); CLK_SYSCLKSourceConfig(CLK_RTCCLKSource_HSI); CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); GPIO_ExternalPullUpConfig(GPIOA, GPIO_Pin_3, ENABLE); GPIO_ExternalPullUpConfig(GPIOA, GPIO_Pin_2, ENABLE); USART_DeInit(USART1); CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE); USART_Init(USART1, 9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, USART_Mode_Tx | USART_Mode_Rx); USART_ClockInit(USART1, USART_Clock_Disable, USART_CPOL_Low, USART_CPHA_1Edge, USART_LastBit_Disable); USART_Cmd(USART1, ENABLE); while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET) // Wait for transmition to complete { } USART_SendData8(USART1, Data); GPIO_Init(GPIOC, GPIO_Pin_7, GPIO_Mode_Out_PP_High_Fast); // Init Blue LED// GPIO_Init(GPIOE, GPIO_Pin_7, GPIO_Mode_Out_PP_High_Fast); // Init Green LED /* Infinite loop */ while (1) { // Wait for transmition to complete { } USART_SendData8(USART1, Data); GPIO_SetBits(GPIOC, GPIO_Pin_7); delay_ms(1000); GPIO_ResetBits(GPIOC, GPIO_Pin_7); delay_ms(1000); }}I am using IAR workbetch for STM8 evolution version.2015-08-26 01:31 AM
There is a tutorial for using the UART on the STM8L-Discovery at
http://colecovision.eu/stm8/STM8L-DISCOVERY%20Serial.shtml it uses SDCC, but that shouldn't be a problem, since IAR and SDCC are the two most standard-compliant compielrs for the STM8, so porting between them is easy. Philipp P.S.: It seems in your code, you are trying to use the library provided by STM. I also tried to use that one a two years ago, but there was a bug in UART handling in there. Don't knwo if its fixed by now. The tutorial linked above does not use the library provided by STM.2015-09-03 06:53 AM
It is working..
Thanks..2016-10-04 06:00 AM
Hello Krause,
I am using STM8L051 with STVD Cosmic compiler + Std peripheral lib and have been successful at transmitting characters but I am having problem in receiving, both in Interrupt & polling modes. Can you plz state what is the library bug you were referring to? I am using versionV1.6.1 / 30-September-2014
of the library. I can see a change in the release notes for V1.6.0 / 28-June-2013 as:
stm8l15x_usart.c/.h Update ''USART_ClearITPendingBit()'' function and parameter list. I dont know if the bug is corrected by that. Anyway my polling code is as follows:void main(void)
{ GPIO_Init(GPIOA, GPIO_Pin_All ,GPIO_Mode_Out_PP_Low_Slow);
GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Slow);
//GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast); //UART Pins: PC5, PC6
GPIO_Init(GPIOD, GPIO_Pin_0, GPIO_Mode_Out_PP_Low_Slow);
//EXTI_SetPinSensitivity(EXTI_Pin_1, EXTI_Trigger_Falling); //Push Button
CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_5|GPIO_Pin_6, ENABLE);
//Pullups on PC5, PC6
USART_Init(USART1, 115200, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_Rx|USART_Mode_Tx));
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
enableInterrupts();
printf(
''UART Tx OK!
''
);
//working
/**/
while
(1)
{
while
(USART_GetFlagStatus(USART1,USART_FLAG_RXNE) == RESET);
//wait till Rxd ... HANGS HERE
temp8 = USART_ReceiveData8(USART1);
USART_ClearFlag(USART1, USART_FLAG_RXNE);
USART_SendData8(USART1, temp8);
while
(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
//wait till Txd
delay_ms(100);
}
while
(1)
//working
{ printf(
''Count: %d
''
, temp++);
delay_ms(1000);
}
}
//main() ends
char
putchar(
char
c)
//implementation for printf
{
USART_SendData8(USART1, c);
while
(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
//wait till Txd
}
When using Interrupts, the interrupt never comes. I am able to view waveforms on Rx pin of STM8, so I know data is going to it. What am I doing wrong?