Please every one am new to code writing. I need your help on a project that am working on. i have a SIM800L gsm module connected to 18f4550 . i will like to read the respone of the gsm module on the LCD when it return "OK" and also turn on an LED connected to PORTA.0. i can make call or send text with the module but i can.t get the LCD to display the respone from the module. Please let someone put me through.
Here is the code.
~~~
'Set pin directions
Dir SerOutPort Out
Dir SerInPort In
Dir PORTB.6 Out 'second USART Tx Pin
Dir PORTB.7 In 'second USART Rx Pin
Dir PORTA.0 Out
Wait 100 Ms
Dim myNum as Word
Dim MyString as String
HSerPrint "AT"
HSerPrintCRLF
'Main routine
Do Forever
HSerGetString MyString
HSerPrint MyString
HSerSend(13)
If MyString = "OK" Then
Set PORTA.0 On
Locate 1,0
Print Mystring
End If
set
Set PORTA.0 Off
Loop
~~~
Last edit: Chris Roper 2019-04-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've noticed an obvious error. You are using portb.6 and portb.7 on both the USART and the LCD.
I normally specify the LCD as write only which saves on a pin (why would you want to read anyway).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks @ David for your observation. it is a mistake on my part when typing. PORTC. 7 and PORTC. 6 were actually used to TX and Rx. why I needed to read the response of the module is because I want to control a load that will be connected to PORTA.0 by send SMS from mobile phone.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Anobium. thank you for your concern. I haven't been able to sort out it out. I am new to coding. I have been going through some examples to see if I can solve it on my own no success yet but I have made up my mind am not going to give up on the project.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
okay I will that the moment am back home. what I plan to achieve through the project is to be able to control some load by sending SMS from a phone. when the GSM module receive the SMS, it will communicate with the microcontroller which willin turn be able to determine whether load A or B should be on or off as the case may be.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the SIM800L is working properly and the power is well taking care of. I have written a small code using the same chip to call another phone number and also text SMS from the chip and it work fine. I strongly believe the problem is with my code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just an observation, and it will probably not impact on your issue, but you don't need to explicitly #include anything from the "lowlevel" folder.
They will be auto included at compile time if needed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I see nothing wrong with your code. Why do I think this. I have you code running on a test bed. I have a terminal representing the GSM module. This code sents the init codes, sends repeated AT to which the terminal can respond 'OK', at this point the LED toggles. I would think the 1s delay would mess things up.
But, I would not use this method of get serial data. I have attached the code I adapted (ignore the LCD stuff as this is for the GCB test bed) but I lifted the Serial Ring Buffer from the Help. And, that works a lot better.
So, if the attached does not work for you to the GSM module... try replacing the GSM module with Terminal to test and diag from the Terminal session.
Last edit: Anobium 2019-04-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thank you for your effort. I really appreciate that. I will try the code and surely give you a feedback the moment power is restored to my community. I've been out of supply for 24hrs now.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@ Evan and everyone thank for your support . After a lot of trying i can now display a full text received by the GSM module on the LCD.
But i still need some help. is tried to used GET(Line,Col) command to extract some part of the text displayed on the LCD , to store it as a string but i got nothing in return. can someone put me through how to do that please.
@ Evan and everyone thank for your support . After a lot of trying i can now display a full text received by the GSM module on the LCD.
But i still need some help. is tried to used GET(Line,Col) command to extract some part of the text displayed on the LCD , to store it as a string but i got nothing in return. can someone put me through how to do that please.
please find attached code.
@Anobium. Ive tried to do that without sucess. what i wanted was to be able to extract some part of the message as it coming in and store it in a string var. for future use.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The sim800 module has a pin (RI) that goes low if you receive a call or an SMS.
If an SMS arrives, the pin goes low for 120 mSec, then returns high.
We must read through an interrupt the passage to 0 of this pin, wait for a time greater than 120 ms and verify that the pin is again at 1.
If so then it means that a text message has arrived.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks, yes i know, i can receive and read the text message successfully on the LCD but what i need to do now is to extract part of the message received and store it as a string. Any idea please.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This routine is used to extract the various parameters received via SMS.
The string must have already been received by another routine and must contain all the characters that were received by the modem.
This is a part from a program written in another language in which the following parameters are extracted from the received string:
1) Telephone number
2) Date and time
3) text of the message
In this example the variables used are not defined, so we need to define them.
The"DatiRicevuti" variable is a string with the characters received from the modem.
MRx_Count = strlen(DatiRicevuti)
`
I look for pointers to the various sections of text to be extracted.
For ii = 0 to MRx_Count ' StrLen (DatiRicevuti) - 1
If DatiRicevuti [ii] = Chr(34) Then ' Character found
Inc (Cnt)
Select Case Cnt
Case 3 ' Inizio del Numero di Telefono
PNum = ii + 1
Case 5
PDat = ii + 1
Case 6
PTxt = ii + 1
Case Else
nop
End Select
End If
Next ii
' -
' Numero di telefono
' Telephone number
If PNum Then
Jj = 0
For ii = PNum to MRx_Count
If DatiRicevuti [ii] <> 34 Then
DatiSMS.Numero [Jj] = DatiRicevuti [ii]
Inc (Jj)
Else
DatiSMS.Numero [Jj] = 0
Break
End If
Next ii
End If
' -
' Data e ora
' Date e Time
If PDat Then
Jj = 0
For ii = PDat to MRx_Count
If DatiRicevuti [ii] <> 34 Then
DatiSMS.OraData [Jj] = DatiRicevuti [ii]
Inc (Jj)
Else
DatiSMS.OraData [Jj] = 0
Break
End If
Next ii
End If
' -
' Testo
' TEXT
If PTxt Then
Jj = 0
For ii = PTxt to MRx_Count
If (DatiRicevuti [ii] <> 10) And (DatiRicevuti [ii] <> 13) Then
DatiSMS.Messaggio [Jj] = DatiRicevuti [ii]
Inc (Jj)
Else
DatiSMS.Messaggio [Jj] = 0
Break
End If
Next ii
End If
`
' -
I hope it can be useful
Last edit: jackjames 2019-05-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please every one am new to code writing. I need your help on a project that am working on. i have a SIM800L gsm module connected to 18f4550 . i will like to read the respone of the gsm module on the LCD when it return "OK" and also turn on an LED connected to PORTA.0. i can make call or send text with the module but i can.t get the LCD to display the respone from the module. Please let someone put me through.
Here is the code.
~~~
chip 18f4550, 4
'LCD settings
#define LCD_IO 4
#define LCD_RS PORTB.7
#define LCD_RW PORTB.6
#define LCD_Enable PORTB.5
#define LCD_DB4 PORTB.4
#define LCD_DB5 PORTB.3
#define LCD_DB6 PORTB.2
#define LCD_DB7 PORTB.1
HSerPrint "AT"
HSerPrintCRLF
Set PORTA.0 Off
Loop
~~~
Last edit: Chris Roper 2019-04-27
I've noticed an obvious error. You are using portb.6 and portb.7 on both the USART and the LCD.
I normally specify the LCD as write only which saves on a pin (why would you want to read anyway).
thanks @ David for your observation. it is a mistake on my part when typing. PORTC. 7 and PORTC. 6 were actually used to TX and Rx. why I needed to read the response of the module is because I want to control a load that will be connected to PORTA.0 by send SMS from mobile phone.
Set PORTA.0 Off
Loop
Thanks for for response. its an error and been taken care of but can't still get the response displayed.
@Oni. How are you getting on? All sorted? If not - let us know.
@Anobium. thank you for your concern. I haven't been able to sort out it out. I am new to coding. I have been going through some examples to see if I can solve it on my own no success yet but I have made up my mind am not going to give up on the project.
Describe what you are trying to achieve. Post yourchallenges again. And, attach your code that you have produced.
There are many that can help.
okay I will that the moment am back home. what I plan to achieve through the project is to be able to control some load by sending SMS from a phone. when the GSM module receive the SMS, it will communicate with the microcontroller which willin turn be able to determine whether load A or B should be on or off as the case may be.
OK. You will need to share what the phone model is, what the phone interface is.
Doesn't the SIM800L gsm need a 2G sim card? It runs at 3.6V and logic is 3V from a quick look.
the SIM800L is working properly and the power is well taking care of. I have written a small code using the same chip to call another phone number and also text SMS from the chip and it work fine. I strongly believe the problem is with my code.
thank you everyone. I have try to reframe the code this is what I now have.
it still not working as expected.
Last edit: Chris Roper 2019-04-27
Just an observation, and it will probably not impact on your issue, but you don't need to explicitly #include anything from the "lowlevel" folder.
They will be auto included at compile time if needed.
@Oni.
I see nothing wrong with your code. Why do I think this. I have you code running on a test bed. I have a terminal representing the GSM module. This code sents the init codes, sends repeated AT to which the terminal can respond 'OK', at this point the LED toggles. I would think the 1s delay would mess things up.
But, I would not use this method of get serial data. I have attached the code I adapted (ignore the LCD stuff as this is for the GCB test bed) but I lifted the Serial Ring Buffer from the Help. And, that works a lot better.
So, if the attached does not work for you to the GSM module... try replacing the GSM module with Terminal to test and diag from the Terminal session.
Last edit: Anobium 2019-04-28
I have replaced the original file I posted with the attached.
You may want to increase the #define BUFFER_SIZE from 8 to 64.
Last edit: Anobium 2019-04-28
thank you for your effort. I really appreciate that. I will try the code and surely give you a feedback the moment power is restored to my community. I've been out of supply for 24hrs now.
I guess you are also in Africa then Oni.
I am South African.
@ Evan and everyone thank for your support . After a lot of trying i can now display a full text received by the GSM module on the LCD.
But i still need some help. is tried to used GET(Line,Col) command to extract some part of the text displayed on the LCD , to store it as a string but i got nothing in return. can someone put me through how to do that please.
@ Evan and everyone thank for your support . After a lot of trying i can now display a full text received by the GSM module on the LCD.
But i still need some help. is tried to used GET(Line,Col) command to extract some part of the text displayed on the LCD , to store it as a string but i got nothing in return. can someone put me through how to do that please.
please find attached code.
Last edit: oni omoniyi 2019-05-30
What are you tryung to do?
Why not inspect the incoming data? rather than extract from the LCD.
@Anobium. Ive tried to do that without sucess. what i wanted was to be able to extract some part of the message as it coming in and store it in a string var. for future use.
The sim800 module has a pin (RI) that goes low if you receive a call or an SMS.
If an SMS arrives, the pin goes low for 120 mSec, then returns high.
We must read through an interrupt the passage to 0 of this pin, wait for a time greater than 120 ms and verify that the pin is again at 1.
If so then it means that a text message has arrived.
thanks, yes i know, i can receive and read the text message successfully on the LCD but what i need to do now is to extract part of the message received and store it as a string. Any idea please.
This routine is used to extract the various parameters received via SMS.
The string must have already been received by another routine and must contain all the characters that were received by the modem.
This is a part from a program written in another language in which the following parameters are extracted from the received string:
1) Telephone number
2) Date and time
3) text of the message
In this example the variables used are not defined, so we need to define them.
The"DatiRicevuti" variable is a string with the characters received from the modem.
MRx_Count = strlen(DatiRicevuti)
`
I look for pointers to the various sections of text to be extracted.
For ii = 0 to MRx_Count ' StrLen (DatiRicevuti) - 1
If DatiRicevuti [ii] = Chr(34) Then ' Character found
Inc (Cnt)
Select Case Cnt
Case 3 ' Inizio del Numero di Telefono
PNum = ii + 1
Case 5
PDat = ii + 1
Case 6
PTxt = ii + 1
Case Else
nop
End Select
End If
Next ii
' -
' Numero di telefono
' Telephone number
If PNum Then
Jj = 0
For ii = PNum to MRx_Count
If DatiRicevuti [ii] <> 34 Then
DatiSMS.Numero [Jj] = DatiRicevuti [ii]
Inc (Jj)
Else
DatiSMS.Numero [Jj] = 0
Break
End If
Next ii
End If
' -
' Data e ora
' Date e Time
If PDat Then
Jj = 0
For ii = PDat to MRx_Count
If DatiRicevuti [ii] <> 34 Then
DatiSMS.OraData [Jj] = DatiRicevuti [ii]
Inc (Jj)
Else
DatiSMS.OraData [Jj] = 0
Break
End If
Next ii
End If
' -
' Testo
' TEXT
If PTxt Then
Jj = 0
For ii = PTxt to MRx_Count
If (DatiRicevuti [ii] <> 10) And (DatiRicevuti [ii] <> 13) Then
DatiSMS.Messaggio [Jj] = DatiRicevuti [ii]
Inc (Jj)
Else
DatiSMS.Messaggio [Jj] = 0
Break
End If
Next ii
End If
`
' -
I hope it can be useful
Last edit: jackjames 2019-05-30