2020-01-26 03:27 AM
Hello,
Using STM8L050j3, ST LINK/V2 ISOL, STVD.
I am studying the UART and i have connected MCU and ST LINK/V2 ISOL.
They use SWIM with USART TX / RX Pin.
A problem is that PC don't receive the any text.
I think that cording is fine(easy example) but i suspect that the PC and MCU are properly connected.
Checked the USART parameters(Baudrate,Wordlength,stopbits,Parity...) on S/W and cording.
Used the various terminal S/W.
Swaped the MCU.
Please let me know how to use UART.
best regards.
-- cord --
#include "stm8l15x.h"
#ifdef _RAISONANCE_
#define PUTCHAR_PROTOTYPE int putchar (char c)
#define GETCHAR_PROTOTYPE int getchar (void)
#elif defined (_COSMIC_)
#define PUTCHAR_PROTOTYPE char putchar (char c)
#define GETCHAR_PROTOTYPE char getchar (void)
#else /* _IAR_ */
#define PUTCHAR_PROTOTYPE int putchar (int c)
#define GETCHAR_PROTOTYPE int getchar (void)
#endif /* _RAISONANCE_ */
void delay(uint16_t n);
void main(void)
{
char ans;
delay(300);
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
CLK_PeripheralClockConfig(CLK_Peripheral_USART1,ENABLE);
GPIO_Init(GPIOC,GPIO_Pin_5,GPIO_Mode_Out_PP_High_Fast);
GPIO_Init(GPIOC,GPIO_Pin_6,GPIO_Mode_In_PU_No_IT);
GPIO_ExternalPullUpConfig(GPIOC,GPIO_Pin_5 | GPIO_Pin_6,ENABLE);
USART_Init(USART1, (uint32_t)115200, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));
GPIO_Init(GPIOB, GPIO_Pin_6 | GPIO_Pin_5 , GPIO_Mode_Out_PP_Low_Slow);
USART_Cmd(USART1, ENABLE);
while(1)
{
GPIO_ToggleBits(GPIOB, GPIO_Pin_5);
delay(100);
USART_SendData8(USART1, 'A');
//ans = getchar();
}
}
PUTCHAR_PROTOTYPE
{
/* Write a character to the USART */
USART_SendData8(USART1, c);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
return (c);
}
GETCHAR_PROTOTYPE
{
int c = 0;
/* Loop until the Read data register flag is SET */
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);
c = USART_ReceiveData8(USART1);
return (c);
}
void delay(uint16_t n)
{
uint16_t i,j;
for (i=0; i<n; ++i) {
for (j=0; j<3050; ++j) { _asm("nop"); }
}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{}
}
#endif
2020-01-27 09:20 PM
should be enable interrupt