Skip to content

benwong01f611/stm32f103vet6-esp8266

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ESP8266 WiFi module for STM32F103VET6

This is the API for utilizing the ESP8266 WiFi module on STM32F103VET6. Referenced from this CSDN article, modified for using it on STM32F103VET6.

The folder original stores the original version of the code.

Why I need this

I am from Hong Kong University of Science and Technology and Iam currently working on a group project in the course "Introduction to Embedded Systems" (course code: ELEC3300) that requires using STM32F103VET6, and my group would like to utilize the ESP8266 on it. However it is so hard to find how to start the module.

Requirements

  • USART
  • DMA
  • Timer

Steps

  1. Connect B8 to 3.3V, and the USART pin to RX and TX (depends on which USART you are using, for example USART2 is using A2 as TX and A3 as RX, then connect A2 to RX and A3 to TX)
  2. Create a new project with CubeIDE (or other)
  3. Set High Speed Clock to "Crystal/Ceramic Resonator"
  4. Set the USART mode to "Asynchronous"
  5. Enable NVIC global interrupt for USART
  6. Enable DMA for USART RX
  7. Enable a timer
  8. Set the timer's clock source to "Internal Clock", prescalar to "72-1", counter period to "10000-1" (depends on your clock configuration, the formula is 1ms = ((1+PRESCALER)/72M)*(1+PERIOD))
  9. Under "Project Manager", enable "Generate peripheral initialization as a pair of '.c/.h' files per peripheral"
  10. Copy wifi.h and wifi.c to folder Inc and Src respectively
  11. Add the following code to USARTx_IRHandler, where x is your USART number
void USART2_IRQHandler(void)
{
  /* USER CODE BEGIN USART2_IRQn 0 */
  USER_UART_Handler();
  /* USER CODE END USART2_IRQn 0 */
  HAL_UART_IRQHandler(&huart2);
  /* USER CODE BEGIN USART2_IRQn 1 */
  HAL_UART_Receive_DMA(&huart2, Espdatatype.DMARecBuffer, DMA_REC_SIZE);
  /* USER CODE END USART2_IRQn 1 */
}
  1. Include wifi.h to stm32f1xx.h and main.h
  2. Add the following function (you can place it in main.c):
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
	static uint8_t count = 0;
	if(htim == (&htim3)){
		count++;
		if(count >= 10){
			recDataHandle();
			count = 0;
		}
	}
}
  1. Add wifiInit(CLIENT) or wifiInit(SERVER) to main.cpp, CLIENT means starting ESP8266 as client (station mode) and SERVER means starting ESP8266 as server (AP)
  2. Modify wifi.c, change the UART/USART/timer to your configuration
  3. Modify wifi.h according to your preferences
  4. Done!

Usage

void sendData(char *userdata, uint16_t userLength);

sendData() will send the data out after connecting to a server, userLength is equivilent to strlen(userdata).

void onReceiveData();

onReceiveData() will be called when data is received, the data is stored in Espdatatype.UserBuffer, and the length of the data is stored in Espdatatype.UserRecLen

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages