2018-08-09 09:12 AM
Hi Technical team,
UART2 is always sending garbage value rather required(correct) value.
Hardware used : STM8S discovery with 5V
IDE used : IAR
The below shows the code ,
// STM8S105 discovery
#include "stdio.h"
#include "string.h"
#include "stm8s.h"
#include "hyperterminal.h"
#define _UART2 1
void main(void)
{
/*High speed internal clock prescaler: 1 i.e. Fmaster = 16MHz*/
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
UART2_DeInit();
UART2_Init((u32)9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1, UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE);
/*Main loop*/
while (1){
SerialPutString("\r\n STM8S-Discovery r\n");
}
}
Please suggest your thought to solve this problem
or please give me proper link
2018-08-10 01:32 AM
You can try the code from the tutorial at
http://www.colecovision.eu/stm8/STM8S-DISCOVERY%20Serial.shtml
It uses UART2 on the STM82-Discovery and works for me. I tried it using the SDCC compiler, but since it is all standard C, it should work unmodified for IAR, too.
This might help decide if there is a problem with your hardwware vs. your code.
Philipp
2018-08-11 03:08 AM
Hi,
Thanks for your reply
Please find the below response for your reply
1.As putchar is not taking in IAR , i renamed that function name as "send" and compiled successfully in IAR IDE .
2. As main is only having printf, it is not printing anything on terminal.
3. I have modified loop as below but still it is printing as garbage value only
for(;;)
{
send('1');send('2');send('3');
printf("Hello World!\n");
for(i = 0; i < 147456; i++); // Sleep
}
My questions are
2018-08-12 10:38 PM
On second look, the putchar() inthe tutorial is not so standard, and should be updated for current SDCC (and IAR).
int putchar(int c)
{
while(!(UART2_SR & UART_SR_TXE));
UART2_DR = c;
return(c);
}
would be a standard putchar().
Could you try with this one?
Is your serial cable okay? Does it work with other boards?
Philipp
P.S.: On my board I see the "Hello, world!" output, compiled with SDCC (older version of SDCC for the putchar() in the tutorial, current SDCC for the putchar() in this post).
2018-08-13 10:17 AM
Hi,
Thanks for your response
I have modified code as per your suggestion, it was compiled successfully in IAR but still output is printing garbage values only in terminal.
I have used two type of terminal software to test this
1. TeraTerm
2. Realterm
Both terminals are printing garbage values only but Realterm terminal software gives below warning message
"Break condition received" (refer attached image file )
"UART receiver framing Error" (refer attached image file)
I have tested my serial cable in two methods
Method1 : tested with other microcontroller, it is working
Method2 : shorted both TX & RX in serial cable, it is working (refer attached image file)
Please refer the attached image file for more understanding
My Questions are
1. Whether my STM8S105C6 discovery board is get damaged with UART functionalities alone (because led blinking program is workinng)?
2. Have any other way to check UART?
Please share your idea to solve this problem.