Unable to establish UART communication between ESP8266 and STM8 Nucleo 32 board. However successful UART communication over COM Port.
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