Skip to main content
Sesf.1
Visitor II
January 6, 2023
Question

B-L475E-IOT01A's wifi module does not send packet after a while

  • January 6, 2023
  • 0 replies
  • 2793 views

Hello everyone,

I am using B-L475E-IOT01A's wifi to send data to a server using UDP protocol. I am not using anything other than the wifi right now and my main loop looks like this:

while(1)
{
	 if(wifiReady==1 && wifiState==2)
	 {
		 wifiReady=0;
		 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_RESET);
		 HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)dummyCommand, (uint8_t *)payloadBuffers[2], (DUMMY_LENGTH)/2, 2000);
		 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_SET);
		 wifiState=1;
		 if(memcmp(payloadBuffers[2],"\r\n1400\r\nOK\r\n> ",14)==0){
				printf("good\r\n");
				badcounter=0;
		 }
		 else{
			 printf("bad\r\n");
			 badcounter++;
			 printf("all=%d, bad=%d\r\n", sendcounter, badcounter);
			 if(badcounter>8)
			 {
				 wifiReady=0;
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_RESET);
				 HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)CLOSEClientcommand, (uint8_t *)payloadBuffers[2], (strlen(CLOSEClientcommand))/2, 2000);
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_SET);
				 while(wifiReady==0) loopCounter++;
				 loopCounter=0;
				 wifiReady=0;
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_RESET);
				 HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)dummyCommand, (uint8_t *)payloadBuffers[2], (DUMMY_LENGTH)/2, 2000);
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_SET);
				 while(wifiReady==0) loopCounter++;
				 loopCounter=0;
				 wifiReady=0;
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_RESET);
				 HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)STARTClientcommand, (uint8_t *)payloadBuffers[2], (strlen(STARTClientcommand))/2, 2000);
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_SET);
				 while(wifiReady==0) loopCounter++;
				 loopCounter=0;
				 wifiReady=0;
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_RESET);
				 HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)dummyCommand, (uint8_t *)payloadBuffers[2], (DUMMY_LENGTH)/2, 2000);
				 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_SET);
				 while(wifiReady==0) loopCounter++;
				 loopCounter=0;
			 }
		 }
	 }
	 else if( wifiReady==1 && wifiState==1 )
	 {
		 lastWifiEventTimeStamp=htim2.Instance->CNT;
		 sprintf(payloadBuffers[0],"S3=%d\r", PAYLOAD_LEN);
		 wifiReady=0;
		 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_RESET);
		 HAL_SPI_TransmitReceive(&hspi3, (uint8_t *)payloadBuffers[0], (uint8_t *)payloadBuffers[1], (PAYLOAD_LEN+len)/2, 2000);
		 HAL_GPIO_WritePin(WIFI_CS_GPIO_Port,WIFI_CS_Pin,GPIO_PIN_SET);
		 wifiState=2;
		 sendcounter++;
	 }
 
}

and this is the wifi initialization squence:

	sendCommand(SSIDcommand,strlen(SSIDcommand));
	sendCommand(PSWcommand,strlen(PSWcommand));
	sendCommand(SECcommad,strlen(SECcommad));
	sendCommand(JoinRetryCountcommad,strlen(JoinRetryCountcommad));
	sendCommand(AutoConnectcommad,strlen(AutoConnectcommad));
	sendCommand(CONNECTcommand,strlen(CONNECTcommand));
	sendCommand(SocketCommand,strlen(SocketCommand));
	sendCommand(UDPCommand,strlen(UDPCommand));
	sendCommand(IPcommand, strlen(IPcommand));
	sendCommand(PORTcommand, strlen(PORTcommand));
	sendCommand(STARTClientcommand, strlen(STARTClientcommand));
	sendCommand(STIMOEOUTcommand, strlen(STIMOEOUTcommand));
	sendCommand(SENDPacketSize, strlen(SENDPacketSize));

and here is the interrupt handler for DATAReady pin:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
 if(GPIO_Pin == GPIO_PIN_1)
 {
	 if(HAL_GPIO_ReadPin(WIFI_INT_GPIO_Port,WIFI_INT_Pin)==1)
	 {
		 wifiReady=1;
	 }
	 else if(HAL_GPIO_ReadPin(WIFI_INT_GPIO_Port,WIFI_INT_Pin)==0)
	 {
		 DMAReceiveCompleted=1;
	 }
 }
}

this code works fine for a while but suddenly stops sending data to the server and AT command returns following error which doesn't make sense given the code i posted above:

[UDP RC] rv= -1\r\n-1\r\nERROR: Unknown Error\r\nUsage: S3 <0001 - 1460>

and this is SPI setting of the microcontroller:

0693W00000Y7ZHMQA3.pngHere is the sample output of a udp server i wrote in python:

953 counter=187121 average RTT=0s average bps=0.0mbps
954 counter=187124 average RTT=0.333s average bps=0.032mbps
955 counter=187560 average RTT=0.002s average bps=4.657mbps
956 counter=188038 average RTT=0.002s average bps=5.106mbps
957 counter=188421 average RTT=0.003s average bps=4.091mbps
958 counter=188872 average RTT=0.002s average bps=4.817mbps
959 counter=189336 average RTT=0.002s average bps=4.956mbps
960 counter=189792 average RTT=0.002s average bps=4.871mbps
961 counter=190244 average RTT=0.002s average bps=4.828mbps
962 counter=190700 average RTT=0.002s average bps=4.871mbps
963 counter=191145 average RTT=0.002s average bps=4.753mbps
964 counter=191589 average RTT=0.002s average bps=4.742mbps
965 counter=191981 average RTT=0.003s average bps=4.187mbps
966 counter=192550 average RTT=0.002s average bps=6.078mbps
967 counter=192903 average RTT=0.003s average bps=3.77mbps
968 counter=193413 average RTT=0.002s average bps=5.447mbps
969 counter=193837 average RTT=0.002s average bps=4.529mbps
970 counter=194258 average RTT=0.002s average bps=4.497mbps
971 counter=194712 average RTT=0.002s average bps=4.849mbps
972 counter=195172 average RTT=0.002s average bps=4.913mbps
973 counter=195625 average RTT=0.002s average bps=4.839mbps
974 counter=196052 average RTT=0.002s average bps=4.561mbps
975 counter=196509 average RTT=0.002s average bps=4.881mbps
976 counter=196956 average RTT=0.002s average bps=4.774mbps
977 counter=197296 average RTT=0.003s average bps=3.632mbps
978 counter=197735 average RTT=0.002s average bps=4.689mbps
979 counter=198183 average RTT=0.002s average bps=4.785mbps
980 counter=198333 average RTT=0.007s average bps=1.602mbps
981 counter=198639 average RTT=0.003s average bps=3.268mbps
982 counter=198722 average RTT=0.012s average bps=0.887mbps
983 counter=198722 average RTT=0s average bps=0.0mbps
984 counter=198722 average RTT=0s average bps=0.0mbps
985 counter=198722 average RTT=0s average bps=0.0mbps
986 counter=198722 average RTT=0s average bps=0.0mbps
987 counter=198722 average RTT=0s average bps=0.0mbps
988 counter=198722 average RTT=0s average bps=0.0mbps
989 counter=198722 average RTT=0s average bps=0.0mbps
990 counter=198722 average RTT=0s average bps=0.0mbps
991 counter=198722 average RTT=0s average bps=0.0mbps
992 counter=198722 average RTT=0s average bps=0.0mbps
993 counter=198722 average RTT=0s average bps=0.0mbps
994 counter=198722 average RTT=0s average bps=0.0mbps
995 counter=198722 average RTT=0s average bps=0.0mbps
996 counter=198722 average RTT=0s average bps=0.0mbps
997 counter=198722 average RTT=0s average bps=0.0mbps
998 counter=198722 average RTT=0s average bps=0.0mbps
999 counter=198722 average RTT=0s average bps=0.0mbps
1000 counter=198722 average RTT=0s average bps=0.0mbps
1001 counter=198722 average RTT=0s average bps=0.0mbps
1002 counter=198722 average RTT=0s average bps=0.0mbps
1003 counter=198722 average RTT=0s average bps=0.0mbps
1004 counter=198722 average RTT=0s average bps=0.0mbps
1005 counter=198722 average RTT=0s average bps=0.0mbps
1006 counter=198722 average RTT=0s average bps=0.0mbps
1007 counter=198722 average RTT=0s average bps=0.0mbps
1008 counter=198722 average RTT=0s average bps=0.0mbps
1009 counter=198722 average RTT=0s average bps=0.0mbps
1010 counter=198722 average RTT=0s average bps=0.0mbps
1011 counter=198722 average RTT=0s average bps=0.0mbps
1012 counter=198884 average RTT=0.006s average bps=1.73mbps
1013 counter=199377 average RTT=0.002s average bps=5.266mbps
1014 counter=199789 average RTT=0.002s average bps=4.401mbps
1015 counter=200238 average RTT=0.002s average bps=4.796mbps

as you can see connection starts and stops working intermittently and apparently there is no pattern for this events.

I've tried every trick that i could come up with, like closing and opening the connection and putting delay between sending consecutive packets, but none of them solved the problem for me.

I really appreciate any help for solving this problem.

thanks.

This topic has been closed for replies.