Hi, I am use the UART1_Read_Text to Reads characters received via UART until the delimiter sequence is detected in this case "OK" , when I reset the pic it working properly but after several readings the pic is frozen and justamnete is this function and there is no way to exit this loop until that I reset the pic again
I am use the mikroc Pro V1.65 and the Pic18f452 a 20Mhz.
Can anyone explain this or is it just a bug
Possible UART1_Read_Text Bug ??
I have not used that function yet but I believe it is a blocking call. What value did you set ATTEMPTS to?
Are you checking the overrun and framming bits to see if there is a problem with reception?
I am a fan of using interrupts for reception and that may be helpful (sorry, no code available for this specific post but I have other entries on the forum).
Also, try to post some code.
Are you checking the overrun and framming bits to see if there is a problem with reception?
I am a fan of using interrupts for reception and that may be helpful (sorry, no code available for this specific post but I have other entries on the forum).
Also, try to post some code.
Hi, it is my code:
I have put in an LED indicator (PORTD.f0 ) to see where stops the program and just in this function:
UART1_Read_Text(Buffer, "OK", 16);
I have to reset the pic to run again...
Code: Select all
int i, j, k = 0;
int Test_AT_CSQ = 0;
int received = 0;
char Buffer[16] ;
char receive;
void Modo_RX(){
UART1_Init(19200);
Delay_ms(100);
Test_AT_CSQ = 0;
do {
UART1_Write_Text ("AT\r\n");
Delay_ms(1000);
UART1_Write_Text ("AT+CSQ\r\n");
Delay_ms(5000);
if (UART1_Data_Ready() == 1) {
receive = UART1_Read();
if (receive == '\r') {
received = 0;
do{
if (UART1_Data_Ready() == 1) {
PORTD.f0 = 1;
UART1_Read_Text(Buffer, "OK", 16);
received = 1;
PORTD.f0 = 0;
}
} while(received == 0);
// Verifica si es la trama +CSQ = 5 ?
if ((Buffer[3] == '+') && (Buffer[4] == 'C') && (Buffer[5] == 'S')&& (Buffer[6] == 'Q')) {
if ( Buffer[8] == '5'){
Test_AT_CSQ = 1;
}
else Test_AT_CSQ = 0;
}
}
}
} while (Test_AT_CSQ == 0);
}
void main(){
TRISD = 0;
while (1){
Modo_RX();
}
}
UART1_Read_Text(Buffer, "OK", 16);
I have to reset the pic to run again...
- slavisa.zlatanovic
- mikroElektronika team
- Posts: 1321
- Joined: 07 Apr 2009 09:39
Hi!
This is not the library bug.
We recommend using the interrupts and state machine when working with the GSM modules.
i.e.
Visit the link below to see complete GSM code example:
http://www.mikroe.com/zip/gsm-gprs/gm86 ... s_v100.zip
Best regards
Slavisa
This is not the library bug.
We recommend using the interrupts and state machine when working with the GSM modules.
i.e.
Code: Select all
// uart rx interrupt handler
void interrupt(){
char tmp;
if (PIR1.RCIF == 1) { // do we have uart rx interrupt request?
tmp = UART1_Read(); // get received byte
// process reception through state machine
// we are parsing only "OK" and "RING" responses
switch (gsm_state) {
case 0: {
response = -1; // clear response
if (tmp == 'O') // we have 'O', it could be "OK"
gsm_state = 1; // expecting 'K'
if (tmp == 'R') // we have 'R', it could be "RING"
gsm_state = 10; // expecting 'I'
break;
}
case 1: {
if (tmp == 'K') { // we have 'K' ->
response = GSM_OK; // we have "OK" response
gsm_state = 50; // expecting CR+LF
}
else
gsm_state = 0; // reset state machine
break;
}
case 10: {
if (tmp == 'I') // we have 'I', it could be "RING"
gsm_state = 11; // expecting 'N'
else
gsm_state = 0; // reset state machine
break;
}
case 11: {
if (tmp == 'N') // we have 'N', it could be "RING"
gsm_state = 12; // expecting 'G'
else
gsm_state = 0; // reset state machine
break;
}
case 12: {
if (tmp == 'G') { // we have 'G' ->
response = GSM_RING; // we have "RING" response
gsm_state = 50; // expecting CR+LF
}
else
gsm_state = 0; // reset state machine
break;
}
case 50: {
if (tmp == 13) // we have 13, it could be CR+LF
gsm_state = 51; // expecting LF
else
gsm_state = 0; // reset state machine
break;
}
case 51: {
if (tmp == 10) { // we have LF, response is complete
response_rcvd = 1; // set reception flag
responseID = response; // set response ID
}
gsm_state = 0; // reset state machine
break;
}
default: { // unwanted character
gsm_state = 0; // reset state machine
break;
}
}
}
}
http://www.mikroe.com/zip/gsm-gprs/gm86 ... s_v100.zip
Best regards
Slavisa
Re: Possible UART1_Read_Text Bug ??
I have exactly the same problem but I need a different solution... This is my code:
When connected to my BlueTooth module in AT command mode (38400 baud) if I issue a command like "AT+UART?" then the response form the BT module is:
"+UART=38400,0,0\r\nOK\r\n" and everything works fine and bt_uart_response string is "+UART=38400,0,0" and bt_uart_status string is "OK". But when I issue a command like "AT+NAME=MyBTModule" then the response is just "OK\r\n" and my MCU hangs there, of course on the second UART1_Read_Text function. Can you help me please how to change the second function, expected strings is just "OK" or nothing. Oh and I forgot, the MCU is PIC18F4520.
Greetings, Goran.
Code: Select all
UART1_Read_Text(bt_uart_response,"\r\n",30);
UART1_Read_Text(bt_uart_status,"\r\n",10);
"+UART=38400,0,0\r\nOK\r\n" and everything works fine and bt_uart_response string is "+UART=38400,0,0" and bt_uart_status string is "OK". But when I issue a command like "AT+NAME=MyBTModule" then the response is just "OK\r\n" and my MCU hangs there, of course on the second UART1_Read_Text function. Can you help me please how to change the second function, expected strings is just "OK" or nothing. Oh and I forgot, the MCU is PIC18F4520.
Greetings, Goran.