View previous topic :: View next topic |
Author |
Message |
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Mon Oct 24, 2016 12:33 am Post subject: Help for initialize hm-10 module |
|
|
Hello friends
I have spend 2 days in order to make hm-10 module work and I didnt make it.
For the beginig the only thing who I would like to do is to take a simple answer " ok " from hm 10.
I have connect lcd 2x16 so i would like to see on the lcd the answer.I didnt use com emulator.
I try everything but i didnt take answer .I have buy from ebay the module with 5v to 3.3v shifter.
Here is the code so far I know is mess but i have change it hunder time.
$Regfile="m168def.dat"
$Crystal=8000000
$hwstack=40
$swstack=16
$framesize=32
$baud=9600
Wait 1
'***************lcd config + power on lcd**********
$lib "lcd4busy_anypin.lbx"
'lcd config
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portb.2 , Rs = Portb.0 , Wr = Portb.1
Config Lcd = 16 * 2
Initlcd
Display On
'***************************************************************************************************************************************************
'uart config
Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'****************************************************************************************************************************************************
waitms 2000
Config Serialin = Buffered , Size = 20
Dim A As STRING * 16 'Here we declare a byte variable
DIM KEY AS BYTE
KEY = Ischarwaiting()
begin:
CLS
WAIT 1
'WAKE UP MODULE
PRINT "QWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXY"
PRINT "AT"
Do
IF KEY = 1 THEN 'we got something
INPUT A 'get it
lcd A
ELSE
LOOP
END IF
End
I have try and wake upcommand and many many others
The only thing i can see is the red led blinking on the module.
I thing that didnt receive any command.
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Mon Oct 24, 2016 5:56 am Post subject: |
|
|
Hi,
Your using buffered Serial Input (Config Serialin = Buffered , Size = 20) but you don't actualy enable Interrupts. That could be your Problem.
Try without Config Serialin = Buffered or add enable Interrupts to your code
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Mon Oct 24, 2016 3:02 pm Post subject: |
|
|
some update
I download to my iphone serial bt app and the app recognize hm-10 and pair with iphone.
And in my iphone I see everything I write with print command for example if i print "AT+PETROS" i see in my iphone AT+PETROS.
That mean that rs232 communication work.
The question is why didnt respond to AT commands and also if I send data from iphone i didnt see them on lcd. |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Mon Oct 24, 2016 3:27 pm Post subject: |
|
|
Hello,
Read my post again, more closely this time.
You are using buffered serial input, which uses interrupts, but as you don't enable the interrupts the serial buffering code will never be called so even if the hm-10 module responds to the AVR, the AVR will ignore the serial data.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Mon Oct 24, 2016 3:40 pm Post subject: |
|
|
petros047 wrote: | The question is why didnt respond to AT commands and also if I send data from iphone i didnt see them on lcd. |
I'd say the question is why you don't respond to posters taking the effort to give you an answer.
For the topic: using buffered input without enabling interrupts is for sure one of the errors.
Also the code looks not very well developed, Ischarwaiting() outside of the loop is no clever logic.
And then make sure, that the message terminate sign(s) need to match the module you use, otherwise input won't work.
See Config Input for that matter, about CR, LF, or its combination. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Mon Oct 24, 2016 9:30 pm Post subject: |
|
|
You are right I return to home after job I add interupt also change a little the code and now is working
Now if I connect my iphone I can see on my iphone what I write in print" " and also if i send something from iphone I can read it on lcd.
The problem is why the bluettoth didnt go to programming mode and listen at commands.
For example if i send print "AT+NAME?" I have to see hmsoft but I see AT+NAME?
$Regfile="m168def.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32
$baud=9600
Wait 1
'***************lcd config + power on lcd**********
$lib "lcd4busy_anypin.lbx"
'lcd config
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portb.2 , Rs = Portb.0 , Wr = Portb.1
Config Lcd = 16 * 2
Initlcd
Display On
'***************************************************************************************************************************************************
'uart config
Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'****************************************************************************************************************************************************
waitms 2000
Enable Interrupts
Config Serialin = Buffered , Size = 20
Config Input1 = CR , Echo = CRLF
Dim A As STRING * 16 'Here we declare a byte variable
begin:
CLS
WAIT 1
'WAKE UP MODULE
PRINT "QWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXYQWERTYUIOPLKJHGFDSAZXY"
PRINT "AT";
Do
If Ischarwaiting() = 1 Then
INPUT A
LCD A
ELSE
LOOP
END IF
End |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Tue Oct 25, 2016 5:54 am Post subject: |
|
|
Hi,
Try this
Code: | $Regfile="m168def.dat"
$Crystal=16000000
$hwstack=40
$swstack=16
$framesize=32
$baud=9600
Wait 1
'***************lcd config + power on lcd**********
$lib "lcd4busy_anypin.lbx"
'lcd config
Config Lcdpin = Pin , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 , E = Portb.2 , Rs = Portb.0 , Wr = Portb.1
Config Lcd = 16 * 2
Initlcd
Display On
'***************************************************************************************************************************************************
'uart config
Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'****************************************************************************************************************************************************
waitms 2000
Enable Interrupts
Config Serialin = Buffered , Size = 20
Config Input1 = CR , Echo = CRLF
Dim A As STRING * 16 'Here we declare a byte variable
begin:
CLS
WAIT 1
'WAKE UP MODULE
PRINT ""
wait 1
Do
PRINT "AT+NAME"
waitms 500
If Ischarwaiting() = 1 Then
INPUT A
LCD A
endif
wait 5
LOOP
End |
Note the small but very important changes.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Oct 25, 2016 7:02 pm Post subject: |
|
|
After digging through some publicly available information (originally the TOs duty), it is clear why this won't work.
The hm-10 neither accepts CR or LF, nor does it reply with either.
If sending commands to the module, a delay after the command tells the module the command is ready, if receiving no CR/LF's are included.
This explains, why Input() won't work, as it waits for terminating bytes like CR/LF.
Simple solution is to use $TIMEOUT for receiving.
A more complicated solution is a custom receive routine, which is required as soon as lots of data streams in without delay, as then buffered input would fill up and finally stop receiving.
Adapt sending it's even easier, adding a semicolon like Print <command string>; will suppress any trailing CRLF's.
After the Print, adding a short delay terminates the command. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Tue Oct 25, 2016 7:51 pm Post subject: |
|
|
Thank you guys
I try this and it work at least I receive ok for answer to my lcd bad I dont receive the value OK+"NAME"
Do
PRINT "AT+NAME?";
waitms 500
If Ischarwaiting() = 1 Then
$timeout = 2000000
INPUT A
wait 1
LCD A
END IF
LOOP
End
According to bascom help I have to disable serialin when i use $timeout |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Oct 25, 2016 8:38 pm Post subject: |
|
|
You may have accidently deleted, i.e. set empty the value Name in the module's memory.
How does the response look like on the iPhone?
If I were you, I'd write now my own simple input routine now to have full control, it's done in a few lines. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Tue Oct 25, 2016 8:59 pm Post subject: |
|
|
in my iphone still appear AT+NAME?
to create my own input routine i dont have a clue but i will try if finally understand what exactly this module need |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Oct 25, 2016 9:37 pm Post subject: |
|
|
You can use ischarwaiting() in combination with waitkey(), use it in a loop.
In front of the loop clear a string and set a word or dword counter variable to a value which you can find out experimentally.
Within the loop check ischarwaiting(), if there's a char, get it with waitkey, add it to a string or put it into an array, then reset the counter to its initial value.
If there's no char, decrease the counter, as soon it reaches zero, exit the loop.
The execution time of the loop in combination with the counter is your timeout.
This kind of code gives you more control, especially if you store data into a byte array, instead of a string.
You need to know, that Bascom strings are zero-terminated, if there's for example a zero after "ok" coming from the module, with any print or lcd command you will only see "ok", even if data comes in after. With waitkey() you can filter out zero, before you add to the string, or in case you store into a byte array, you can debug print the complete array. |
|
Back to top |
|
|
petros047
Joined: 14 Mar 2012 Posts: 84
|
Posted: Tue Oct 25, 2016 10:57 pm Post subject: |
|
|
Finally it works I take complete respond.
'uart config
Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'****************************************************************************************************************************************************
waitms 2000
ENABLE INTERRUPTS
Config Serialin = Buffered , Size = 32
Config Input = CR , Echo = CRLF
Dim A As STRING * 32 'Here we declare a byte variable
begin:
Do
cls
PRINT "AT+NAMEPETROS?";
waitms 1000
If Ischarwaiting() = 1 Then
$timeout = 2000000
INPUT A
wait 1
LCD A
wait 5
END IF
LOOP
End
ofcourse accordind to bascom I can not use serialin with timeout so I will try and your way and make it all in a subroutine so it will be easy to use it in my finally program. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|