Skip to main content
VR_it
Associate II
May 9, 2019
Solved

How to verify whether Quectel M66 recognize my command sent via UART from STM32?

  • May 9, 2019
  • 6 replies
  • 3752 views

0690X000008BSx6QAG.pngI am using STM32F103C8 board and CubeMX to create the code. I have connected the M66 to STM32 to UART2 port. I try to send some commands to Quectel M66 via STM32's UART port. It receives the command but throws some junk characters. I have set the baud rate as 9600 for all UART ports. This is my code

void M66_Check()
{
 char *buffer = "ATI\r\n";
 char *rec_buffer = NULL;
 rec_buffer = (char*)malloc(200 * sizeof(char));
 if(HAL_UART_Transmit(&huart2,buffer,strlen(buffer),200) == HAL_OK)
 {
 printf("AT Command sent successfully\r\n");
 HAL_Delay(1000);
 }
 else
 {
 printf("Not Sent\r\n");
 }
 HAL_UART_Receive(&huart2,rec_buffer,50,200);
 
 printf("About to print Response from M66 \r\n");
 HAL_Delay(2000);
 
 printf(rec_buffer);
}

This topic has been closed for replies.
Best answer by VR_it

I have found out the problem... I needed to transmit and receive in these formats....

I missed those (uint8_t *).

To Transmit - HAL_UART_Transmit(&huart2, (uint8_t *)buffer, strlen(buffer), 100);

To Receive - HAL_UART_Receive(&huart2, (uint8_t *)rec_buffer,50,2000);

Now there is no problem and I am getting the response correctly.

Thanks for your help...

6 replies

Mon2
Senior III
May 9, 2019

Suggestions:

1) review 3.7.4 of the datasheet for your module:

https://www.quectel.com/UploadImage/Downlad/Quectel_M66_Hardware_Design_V1.2.pdf

Are you applying the suggested resistor dividers for the safe voltage shifting to this module?

2) Do the same but source a FTDI to UART cable (3v3 output - NOT RS232) and apply the above resistor dividers and test using any terminal program. The commands are HAYES modem style so:

AT<ENTER>

ATZ<ENTER>

and so on should return valid responses.

VR_it
VR_itAuthor
Associate II
May 9, 2019

Actually this M66 is embedded to the board and all the resisters are embedded internally.

And only way to send those commands is UART port only..

Tesla DeLorean
Guru
May 9, 2019

You delay 1s, while not ready to receive any data, the chip doesn't buffer.

Is 200ms long enough to receive 50 chars?

The receive blocks.

You delay another 2s.

Don't handle NUL termination of the string properly.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
VR_it
VR_itAuthor
Associate II
May 9, 2019

does Delay matters for receiving data from particular UART port? I did to see visually my code flow.. otherwise it would be fast and i could not see the flow..that's why i put it.

Tesla DeLorean
Guru
May 9, 2019

Well doing blocking IO to the UART and waiting 1s afterward, in a sequential fashion seems to be problematic in that the RX/TX on the port can occur simultaneously, and the modem is going to respond in a fraction of a second, while your code isn't paying attention, and the STM32 isn't magically buffering the data.

Waiting for 50 characters, is likely another issue, this will likely timeout in 200ms as the modem's response is probably less than a dozen characters. I you have not code to scope the content of the buffer, or deal with the NUL that all the string handling code requires, ie printf()

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
VR_it
VR_itAuthorBest answer
Associate II
May 10, 2019

I have found out the problem... I needed to transmit and receive in these formats....

I missed those (uint8_t *).

To Transmit - HAL_UART_Transmit(&huart2, (uint8_t *)buffer, strlen(buffer), 100);

To Receive - HAL_UART_Receive(&huart2, (uint8_t *)rec_buffer,50,2000);

Now there is no problem and I am getting the response correctly.

Thanks for your help...