Giter Site home page Giter Site logo

selcukaltinay / test-driven_developed_esp8266_driver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mehmettopuz/test-driven_developed_esp8266_driver

1.0 0.0 0.0 49.94 MB

Makefile 0.17% C++ 0.56% C 3.42% Assembly 0.01% HTML 92.18% JavaScript 3.62% CSS 0.03%

test-driven_developed_esp8266_driver's Introduction

Test-Driven Developed ESP8266 Driver

In this project, I implemented a demo driver to communicate between ESP-01 and STM32G474(NUCLEO) following the principles of Test-Driven Development. I have used CppUTest that is an unit testing framework to test the codes.

How to Use

First of all, you have to implement your own UART receive, UART transmit and getTick functions because this driver needs these functions to communicate with ESP-01.

void UART_SendMessage(uint8_t* messageArray)
{

	while(*messageArray)
	{
		USART1->TDR = *messageArray++;
		while(!(USART1->ISR & (1<<6)));		// wait for transmit register(TC) to set.
	}
/* with HAL drivers-----------------------*/
//	HAL_UART_Transmit(&huart1, messageArray, strlen((char*)messageArray), HAL_MAX_DELAY);
}
uint8_t UART_ReceiveByte(void)
{

	return USART1->RDR;
/* with HAL drivers-----------------------*/
//	uint8_t buffer[10];
//
//	HAL_UART_Receive(&huart1, &buffer, 1, HAL_MAX_DELAY);
//
//	return buffer[0];
}

Pass the functions to the ESP_Init() function as a function pointer. I have used HAL_GetTick() instead of implementing my own getTick function.

  ESP_Init(UART_SendMessage,	// UART transmit function
		  UART_ReceiveByte,		// UART receive function
		  HAL_GetTick,			// get tick function
		  255					// UART ring buffer size
		  );

Add ESP_UART_ReceiveHandler() function to ISR.

void USART1_IRQHandler(void)
{
	  if(!(USART2->ISR & (1<<5)))			// rx interrupt
	  {
		 ESP_UART_ReceiveHandler(); 		// ESP receive handler function.
	  }
}

It is ready to use. You can use this driver to connect TCP/IP server and send/read messages for now. I will continue to improve the driver as soon as possible. Here is an example how to connect TCP/IP server.

  while(!HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin));		// Start button

  USART1->CR1 |= (1<<5); // rx interrupt enable

  ESP_Init(UART_SendMessage,	// UART transmit function
		  UART_ReceiveByte,		// UART receive function
		  HAL_GetTick,			// get tick function
		  255					// UART ring buffer size
		  );

  while(1)
  {
	  Status connectionStatus = Connect_Wifi("SSID", "Password");

	  if(connectionStatus == STATUS_OK)
		  break;
	  else if(connectionStatus == STATUS_ERROR || connectionStatus == TIMEOUT_ERROR)
	  {
		  Error_Handler();
	  }
  }

  while(Connect_TCP_Server("192.168.88.183", "255") == IDLE);

  while(Send_TCP_Message("Test message") == IDLE);

  char receivedCommand[50];
  while (1)
  {
	  if(Read_TCP_Message(receivedCommand) == STATUS_OK)
	  {

		  if(strcmp(receivedCommand,"MOTOR_ON") == 0)
		  {
			  while(Send_TCP_Message("MOTOR_ON command has been detected.\n") == IDLE);

			  	  	  	  	  	  // do something else
		  }
		  else if(strcmp(receivedCommand,"MOTOR_OFF") == 0)
		  {
			  while(Send_TCP_Message("MOTOR_OFF command has been detected.\n") == IDLE);
			  	  	  	  	  	  	  	  // do something else
		  }
		  else if(strcmp(receivedCommand,"LED_ON") == 0)
		  {
			  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, 1);
		  }
		  else if(strcmp(receivedCommand,"LED_OFF") == 0)
		  {
			  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, 0);
		  }
		  else
		  {
			  while(Send_TCP_Message("Invalid command!\n") == IDLE);
		  }
		  memset(receivedCommand,0,50);		// clear the received command buffer
	  }

	  HAL_Delay(100);

    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.