2016-12-07 03:59 AM
Hi all,
I am working for a project which is having 5 interfacing modules out of this one module needs to interface quectel M95 GSM modem to stm32f030C8. From PCB side and Hardware all was done working fine modem Responding to AT Commands.USART1 is used for interfacing M95 module. STM32 cube MX tool is used for generate code for TrueStudio.
Here is my problem,when i sent AT command modem responding with OK and reading messages also.For that i am using USART2 to display received message on PC terminal using MAX3232 converter.
If i want read the message which is received , in that received message some part of message is missing.i tried to increase the buffer size & receive length in the HAL_UART_Receive_IT function but not worked out.
I am using usart1 receive interrupt .Receiving uart message are not exact what we need to receive some of sending characters also received.
uint8_t uart1_aRxBuffer[150],
send_Buf[100];
HAL_UART_Transmit(&huart1,(uint8_t *)send_Buf,len,1000);
HAL_UART_Receive_IT(&huart1,(uint8_t *)uart1_aRxBuffer,len1);
please help on this it is need to submit to the client ASAP.
#no-hablo-halSolved! Go to Solution.
2016-12-16 04:50 AM
The RAM size is the limit. In the interrupt for UART RX, fill up a buffer (as big as you need) from receive data string. Once you get the end of string (line feed/return detect) , set a RAM flag which will be polled by the main loop to grab the message and analyse it.
2016-12-16 08:23 AM
Here is some code that should at least follow a logical process where you can get responses from the M It uses the Interrupt version of the UART receive HAL call, however it limits the size to 1 character. This way you get an interrupt on every character and you can manage the receive buffer yourself.
The callback that is called on each character is near the bottom, and that builds the receive buffer. the routine above it can be used to remove one character from the buffer at a time, and the get_response routine keeps filling the buffer until an 'OK' is received and then returns the length of the message to the calling program. If it does not get this response within the time specified in the 'WaitResponse' value, it returns a -1 as the length as an error indication. You may need to enhance this function if you would like to handle non-'OK' responses from the chip. Also, it does not handle or pass characters received after the 'OK' sequence like line termination characters ' ' or ' '.
Good luck
#define WaitResponse 1000
#define BufferSize 256;
//globals to manage receive buffers
int RxIndex = 0;
char InBuffer[BufferSize];
void send_cmnd(char *AT_cmd_string){
int err;
response_string[0] = 0; // set up condition for 'response_format() function'
HAL_UART_Receive_IT(&huart1, (uint8_t*)InBuffer, 1 );// Start RxInt with first char
printf('
GSM Tx: %s
',(int8_t*)AT_cmd_string); // your debug message
HAL_UART_Transmit_IT(&huart1, AT_cmd_string, strlen(AT_cmd_string));//Send command to M95
err = get_response();
if(err > 0)
printf('
UART1 Rx:%s
',response_string);
}
int get_response(void){
int i=0, len=0, done = 0, ticktime;
ticktime = HAL_GetTick();// get start tick time
ticktime += WaitResponse; // set time when we give up
ticktime %= 0x1000000; //timer is only 24 bits, so wrap if timer would wrap
// Check for 'OK' to terminate response
while((done==0) && (Hal_GetTick() != ticktime)){
UART1_getchar(); // wait for the next character
len++;
if((InBuffer[len-1] == 'K') && (len>1)){
if(returnBuffer[len-2] == 'O') // got 'OK'
done == 1;
}
}
if(done == 0) // timeout occurred
return -1; //return error value
else {
returnBuffer[len++] = 0;//NULL terminate string
return len;
}
/*
*This routine returns a 1 when a new character has been returned by the
* UART. If no new chars,
* returns 0
*/
int UART1_kbhit(UART_HandleTypeDef *huart){
//if (huart->RxXferCount == indx)
if(RxIndex == 0)
return 0;
else return 1;
}
/*
* This routine stalls until a character has been recieved by the UART
* and then returns it
*/
char UART1_getchar(void){
__HAL_UART1_EXTI_DISABLE_IT()// hold off interrupt until index updated
while(!UART1_kbhit());
if(RxIndex > 0)
RxIndex --;
__HAL_UART1_EXTI_ENABLE_IT()
return RxBuffer[RxIndex];
}
/*
*This routine is a callback defined by the HAL which is called when the receive
*operation has completed. Since we are setting the receive interrupt function to
*only get once character, this is called when each character comes in so that
*the user program can manage the input buffer. All it does in increment the index
*pointer for the buffer and re-start the interrupt-based receive function.
*/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef * huart){
RxIndex++;
if(RxIndex == BufferSize) // if overrun buffer, wrap
RxIndex = 0;
HAL_UART_Receive_IT(&huart1, RxBuffer[RxIndex],1);
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
2016-12-19 12:19 AM
Thanks for quick reply,
The Above code has errors if we paste same in Debugger,
Any how some what i managed to compile but the code was stopped working on this function
UART1_kbhit
();
My old code was some what improved it working fine with modem replies .
but how to read modem SIM Messages those are very lengthy. For reading one message it is working fine but at the same time second message is not reading simply executing SIM read command.This is done by
HAL_UART_Receive_IT(&huart1,(uint8_t *)uart1_aRxBuffer,120);
can i do like this?
AT+CMGR=1;
** some text Message Reply**
AT+CMGR=2;
Simply OK
But when i delete first message second one is reading.help me on this issue.
2016-12-19 12:49 AM
For the while(!UART1_kbhit()); in function
char UART1_getchar(void) is not getting exit from loop.
2016-12-19 04:54 AM
Yes, that is what would happen. When you call HAL_UART_Receive_IT() with a buffer length of N, it will not cause a transfer complete interrupt until the buffer is completely filled. By sending it a buffer length of 120 , kbhit() is waiting for the interrupt service routine to increment the receive index counter, which will not occur until 120 characters are received since that will trigger the first interrupt, where the ISR will only get one character anyway.
With an interrupt every character, it should continue receiving until the buffer overflows (it is set to 256 characters in the above example, you can make that bigger if you have RAM available). I don't know how long the 'long' message is that you are talking about but if it is less than 256 characters you should not have an issue. It sounds like you should finish processing one received message before you send out another AT command that generates the next message. Otherwise I have no idea what you are doing wrong. Perhaps you should find a software engineer to work on this with you. Or ask you professor for help.