Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:33 05 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM COM Interrupts

Author Message
Hebble
Newbie

Joined: 15/11/2014
Location: Australia
Posts: 4
Posted: 08:37pm 14 Nov 2014
Copy link to clipboard 
Print this post

Hi - I'm hoping that someone can help me with a serial interrupt problem that I am trying to understand. The setup is a Maximite connected to an RN-42 Bluetooth module acting as master and a Micromite connected to an HC-06 Bluetooth module acting as slave - both communicating using serial communications. The intention is to have the master request a temperature from the slave at a preset time and for the slave to repond with a temperature from a connected DS18B20. I am trying to initiate the request by sending an "*" from the master and using the Interrupt parameter of the OPEN comspec$ command on the slave to return the DS18B20 value. I have set the slave up to flash an LED when the interrupt is invoked but I am not getting any response.

I am using MMBasic 4.5 on both micros and I am fairly sure that the Bluetooth pairing is occurring - the LED on the HC-06 becomes steady after both micros are switched on and resumes flashing when the master is turned off. I have established that the master is sending the "*" at 5 second intervals using TeraTerm. The code I am using is listed below - I have stripped out all the temperature stuff.

I would appreciate any advice on what might be going on or if there is a better way of doing this!


'TEMP MASTER
'===========

10 LCD INIT 3,4,5,6,1,2
15 SETTICK 5000,SendReq
20 OPEN "COM1:9600" AS #1
25 DO:LOOP

80 SendReq:
85 PRINT #1,"GetTemp"
90 LCD 1,1,TIME$
95 IRETURN




'TEMP SLAVE
'==========

10 SetPin 2,DOUT
15 Pin(2) = 0
20 Open "COM1:9600,256,SendTemp,1" As #1
25 Do:Loop

50 SendTemp:
55 Pin(2) = 1
60 Pause 100
65 Pin(2) = 0
70 IReturn
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 08:57pm 14 Nov 2014
Copy link to clipboard 
Print this post

The HC-06 usually works reliably once it has been paired.

Start by putting a LED and resistor on the Tx line from the HC-06 Micromite Rx - Pin 12
That will tell you if anything is happening. (a CRO would be better)
It will also tell you if the Tx/Rx are swapped.

You can also use a USB-TTL converter and monitor the HC-06 from the comfort of TeraTerm on the PC. That will confirm that the baud rate is set to 9600 on the HC-06.

Your code looks OK.
You can test your code by replacing the Bluetooth with wires temporally.

Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9588
Posted: 09:00pm 14 Nov 2014
Copy link to clipboard 
Print this post

Hi and welcome to the forums.

At first glance, I can't see anything OBVIOUSLY wrong, but my only thought at this point would be to increase the time delay in your slave code to at least 500mS.

A 100mS LED flash is going to be VERY quick, and if you are not looking at it at EXACTLY the right time, the Human eye may well miss it.

So, I would change that to 500mS - perhaps even 1000mS for the purposes of testing, then you can work backwards once you are seeing acknowledge pulses.

I would also be inclined to change your serial buffer interrupt to MORE then just one character to ensure that all of the command bytes arrive BEFORE checking to see what the message is. Based on your "GetTemp" message, I would make the buffer 6 bytes long before any interrupt is called.
Smoke makes things work. When the smoke gets out, it stops!
 
Hebble
Newbie

Joined: 15/11/2014
Location: Australia
Posts: 4
Posted: 01:04am 15 Nov 2014
Copy link to clipboard 
Print this post

Guys - thanks for the prompt replies.

Grogster - I have increased the LED on-time and the interrupt bytes to 6 but still no success. TassyJim - I have confirmed that the HC-06 is operating at 9600 baud and I'll try connecting the diode to Pin 12 tomorrow.

I'll let you know what happens.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9588
Posted: 01:57am 15 Nov 2014
Copy link to clipboard 
Print this post

Please keep us posted on your progress.

Time to follow Jim's suggestion(if you have not already), and replace the wireless link with plain old wires and test that you do indeed get the expected result from the other end. If that is the case, then the problem is in the wireless link. If the hard-wired arrangement does not work, then there is some kind of bug in your program.
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 982
Posted: 02:01pm 15 Nov 2014
Copy link to clipboard 
Print this post

@Grogs

  Quote  A 100mS LED flash is going to be VERY quick, and if you are not looking at it at EXACTLY the right time, the Human eye may well miss it.


On experimentation to minimise power consumption and to have a visual indication of program happiness, I was surprised to find flashing an LED for 1mS every second very successful and noticeable.

GM
 
Hebble
Newbie

Joined: 15/11/2014
Location: Australia
Posts: 4
Posted: 06:50pm 15 Nov 2014
Copy link to clipboard 
Print this post

Ok - I've got it working. The Micromite 'slave' circuit is built on a piece of Veroboard. After trying the suggestions above I thought there might be a hardware problem so I cleaned up the circuit board a bit and with the following bits of code I was able to get the COM Interrupt working as I expected it to.

Maximite (Master)
=================

LCD INIT 3,4,5,6,1,2
SETTICK 5000,SendReq
OPEN "COM1:9600" AS #1
DO:LOOP

SendReq:
PRINT #1,"**"
LCD 1,1,TIME$
IRETURN


Micromite (Slave)
=================

SetPin 2,DOUT
Pin(2) = 1
Pause 200
Pin(2) = 0
Open "COM1:9600,3,GetTemp,2" As #1
Do:Loop

GetTemp:
Input #1,t$
Pin(2) = 1
Pause 200
Pin(2) = 0
IReturn


Without the Input command in the GetTemp interrupt the LED will light up on the initial interrupt and stay lit during successive interrupts. The initial LED flash on the slave startup was just to convince me that the program was running Ok. I can now get on with having the slave read a DS18B20 and send the value back to the master. I can't say I totally understand serial comms with interrupts but I think I know a bit more about it now.

Thanks all for your time and comments - I will be more careful with the construction side next time.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 08:50pm 15 Nov 2014
Copy link to clipboard 
Print this post

Glad to see it working.

The maximite sends **<CR>

The micromite has to process that data.
Your INPUT is reading the port upto the first <CR> or comma.
If you used LINE INPUT, it would read upto the first <CR> including any comma's

As far as I know, you have to clear the receive buffer before the next interrupt can occur. Otherwise, the incoming data is added onto the end of any existing data but no interrupt.

I am in the process of setting up a data acquisition system with 4 'remote' Micromites controlled by a Maximite. I will use a multidrop serial arrangement, very similar to what you are doing but with hard wiring.
In my setup, the first character will be the 'address' byte so the individual Micromites know who's turn it is to report (or do some other function such as turn the bore pump on/off.

Jim


VK7JH
MMedit
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 09:46pm 15 Nov 2014
Copy link to clipboard 
Print this post

  Grogster said  A 100mS LED flash is going to be VERY quick, and if you are not looking at it at EXACTLY the right time, the Human eye may well miss it.
So, I would change that to 500mS - perhaps even 1000mS for the purposes of testing, then you can work backwards once you are seeing acknowledge pulses.


Hi Grogs,
I'm using 100mS each second on a box mounted against a window in a reasonably bright daylight area and it's still quite noticeable. There's a 3mm red and a green with their usual current limiting. The red is more obvious of course but both are fine.

Greg
 
Hebble
Newbie

Joined: 15/11/2014
Location: Australia
Posts: 4
Posted: 09:48pm 15 Nov 2014
Copy link to clipboard 
Print this post

Jim - thanks for the info on the receive buffer - it has helped my understanding a lot. The data acquisition system I am aiming to setup includes a number of Bluetooth Micromite slaves each controlled by a Bluetooth Micromite master with each master hardwired to a Maximite which would control the time of data acquisition and recording. As far as I can see the Maximite can only control one Bluetooth device hence the Bluetooth Micromite masters.

David
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9588
Posted: 12:58pm 16 Nov 2014
Copy link to clipboard 
Print this post

@ Graeme Meager and paceman Re: 100mS LED flashing - So noted, and thanks for putting me right on that. The Human eye must be faster then I thought.

Oh, and Hebble - well done on getting it working.
Smoke makes things work. When the smoke gets out, it stops!
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025