Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Wifi_RxCallBack function in the ESP8266.c file is not working as expected #1

Open
LucaLush opened this issue Oct 6, 2024 · 1 comment

Comments

@LucaLush
Copy link

LucaLush commented Oct 6, 2024

The MCU I use is STM32F103ZET6. The original Wifi_RxCallBack function is as follows.This function cannot read characters normally through uart interrupt. It's like uart interrupt data cannot be written to the Wifi.usartBuff as expected.

void Wifi_RxCallBack(void)
{
	Wifi.RxBuffer[Wifi.RxIndex] = Wifi.usartBuff;
	if(Wifi.RxIndex < _WIFI_RX_SIZE)
	  Wifi.RxIndex++;
	HAL_UART_Receive_IT(&_WIFI_USART,&Wifi.usartBuff,1);
}

When I change Wifi_RxCallBack to the following form, all function in ESP8266.c work fine. Why is this happening? Have you ever encountered similar problems?

void Wifi_RxCallBack(void)
{
	Wifi.RxBuffer[Wifi.RxIndex] = (uint8_t)(_WIFI_USART.Instance->DR & (uint8_t)0x00FF);
	if(Wifi.RxIndex < _WIFI_RX_SIZE)
	  Wifi.RxIndex++;
	HAL_UART_Receive_IT(&_WIFI_USART,&Wifi.usartBuff,1);
}
@jrmejiaa
Copy link
Owner

jrmejiaa commented Oct 7, 2024

Hi,

Thanks to to reach out, I have worked a long time ago with this library, it was one of my first projects. Therefore, it is quite old and I am almost certain that the problem is that STM32 updated the HAL drivers and therefore is not longer 100% compatible.

The HAL_UART_Receive_IT seems now to have new header, which looks something like this, according to this manual:

HAL_StatusTypeDef HAL_UART_Receive_IT (UART_HandleTypeDef * huart, uint8_t * pData, uint16_t
Size)

My gut feeling is that you are sending a uint8_t pointer aka Wifi.usartBuff, but you are telling with the variable Size that you are waiting for a uint16_t. Maybe the compiler and the function would understand that you need is a uint8_t buffer is you explicit say it, instead of putting the 1 alone. You could try:

void Wifi_RxCallBack(void)
{
	Wifi.RxBuffer[Wifi.RxIndex] = Wifi.usartBuff;
	if(Wifi.RxIndex < _WIFI_RX_SIZE)
	  Wifi.RxIndex++;
	HAL_UART_Receive_IT(&_WIFI_USART,&Wifi.usartBuff,(uint8_t) 1);
}

Another solution is to change the usartBuff to a uint16_t type and take only the first bits, similar as you already to with the change that you made.

/* After changing the Wifi.usartBuff to uint16_t */
void Wifi_RxCallBack(void)
{
	Wifi.RxBuffer[Wifi.RxIndex] = (uint8_t) (Wifi.usartBuff & 0x00FF);
	if(Wifi.RxIndex < _WIFI_RX_SIZE)
	  Wifi.RxIndex++;
	HAL_UART_Receive_IT(&_WIFI_USART,&Wifi.usartBuff,1);
}

According to the documentation the HAL interruption must put the information in the pData pointer, it has to be there, and you should reach it with any of those changes. If not, something is not working properly with the UART IRQ Handler.

Let me know if that helps, I would like to know if it works.

Happy Coding :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants