cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to establish UART communication between ESP8266 and STM8 Nucleo 32 board. However successful UART communication over COM Port.

APant.1
Associate II

Hi,

I am working with an STM8 Nucleo 32 board based on the STM8s207K8 microcontroller. I am trying to receive data from a NodeMCU dev board via UART. The NodeMCU board successfully receives data from the server, and transmits it, however when I try to receive data using the STM8 dev board, I am not successful in doing so. I am able to transmit and receive the data via COM Port to STM8s, I have made sure that the baud rates of both the microcontrollers are same as well. Can someone please help me with this.

Thanks

#include	"stm8s.h"
#include	"string.h"
#include	"delay.h"
 
#define LED_PORT	(GPIOC)					//GPIO Port C defined as LED port
#define LED_PIN	(GPIO_PIN_5)			//GPIO Pin 5 defined as LED pin
 
uint8_t i;					//Integer i declared for ececution of for loop
 
char OUTPUT_DATA[16];					//Character array OUTPUT_DATA of size 15 is declared to transmit feedback via UART
 
void main(void)
{
	GPIO_DeInit(LED_PORT);					//GPIO Port C de-initialised
	UART3_DeInit();									//UART-3 Port de-initialised
	
	GPIO_Init(LED_PORT,	LED_PIN,	GPIO_MODE_OUT_PP_LOW_SLOW);					//GPIO Port C pin5 declared as output push-pull with initial state as slow
	UART3_Init((uint32_t)115200,	UART3_WORDLENGTH_8D,								//UART-3 initialised with baud rate set as 115200
	UART3_STOPBITS_1,	UART3_PARITY_NO,
	UART3_MODE_TXRX_ENABLE);
	
  while (1)
  {
		char INPUT_DATA[15]	=	"";					//character array INPUT_DATA of size 15 is declared to receive data via UART
		for(i=0;	i<14;	i++){							//Data from UART is taken bit by bit and stored in INPUT_DATA
			while(UART3_GetFlagStatus(UART3_FLAG_RXNE)	==	RESET){
			}
			INPUT_DATA[i]	+=	UART3_ReceiveData8();
		}
		delay(100);
		if(strcmp("Appliance 1 01",	INPUT_DATA)	==	0){										//Checks if INPUT_DATA is "Appliance 1 01"
			GPIO_WriteHigh(LED_PORT,	LED_PIN);															//If INPUT_DATA matches set condition GPIO pin is triggered high
			strcpy(OUTPUT_DATA,	"Appliance 1 ON");													//"Appliance 1 ON" is copied to OUTPUT_DATA string which was initially empty
			for(i=0;	i<=14;	i++){																 					//Data stored in OUTPUT_DATA is transmitted bit by bit via UART for feedback 
				while(UART3_GetFlagStatus(UART3_FLAG_TXE)	==	RESET){
				}
				UART3_SendData8(OUTPUT_DATA[i]);
			}
			while(UART3_GetFlagStatus(UART3_FLAG_TXE)	==	RESET){
			}
			UART3_SendData8((uint8_t)'\n');																	//A new line is transmitted
		}
		else if(strcmp("Appliance 1 00",	INPUT_DATA)	==	0){							//Checks if INPUT_DATA is "Appliance 1 01"
			GPIO_WriteLow(LED_PORT,	LED_PIN);																//If INPUT_DATA matches set condition GPIO pin ia triggered low
			strcpy(OUTPUT_DATA,	"Appliance 1 OFF");													//"Appliance 1 OF" is copied to OUTPUT_DATA string which was initially empty
			for(i=0;	i<=15;	i++){																					//Data stored in OUTPUT_DATA is transmitted bit by bit via UART for feedback
				while(UART3_GetFlagStatus(UART3_FLAG_TXE)	==	RESET){
				}
				UART3_SendData8(OUTPUT_DATA[i]);
			}
			while(UART3_GetFlagStatus(UART3_FLAG_TXE)	==	RESET){
			}
			UART3_SendData8((uint8_t)'\n');																	//A new line is transmitted
		}
		UART3_ReceiveData8();																							//UART-3 data receive register is set empty
		delay(100);
  }
  
}
 
#ifdef USE_FULL_ASSERT
 
void assert_failed(u8* file, u32 line)
{
  while (1)
  {
  }
}
#endif

4 REPLIES 4

Should probably use method of receiving that don't block.

How's the 15 character input going to synchronize or escape? Perhap use CR or LF to terminate input

You should check for error status on the UART, and clear those errors. Overflow, framing, noise type errors.

How do you NUL terminate the string?

+= ??

INPUT_DATA[i] += UART3_ReceiveData8();

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

Do you receive nothing or receive wrong data from NodeMCU?

if nothing, you may check HW points firstly:

  1. if the TX/RX are connected correctly TX<->RX and RX<->TX.
  2. if the voltage level is same between STM8 and NodeMCU.

normally even with wrong baud rate, you should receive wrong data instead of nothing.

I'm not receiving any data from NodeMCU, I have ensured that all the hardware connections are correct, the voltage level is same as well, since I'm powering both the boards from the same source. I tried to de-solder the ​shorting jumpers connecting the virtual COM port however I'm still not receiving any data. While using the COM port to send and receive data the device works fine, however I'm unable to transmit data from a different board.

Hi,
Did you solve this problem?
I'm now learn about communicating between stm8 and esp8266 module. Could you please share me this solution?