2019-05-09 04:19 AM
I 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);
}
Solved! Go to Solution.
2019-05-09 11:40 PM
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...
2019-05-09 04:54 AM
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.
2019-05-09 06:11 AM
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.
2019-05-09 06:20 AM
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.
2019-05-09 06:23 AM
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..
2019-05-09 06:34 AM
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()
2019-05-09 11:40 PM
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...