![]() |
Forum Index : Microcontroller and PC projects : MM COM Interrupts
Author | Message | ||||
Hebble Newbie ![]() Joined: 15/11/2014 Location: AustraliaPosts: 4 |
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: AustraliaPosts: 6269 |
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 ZealandPosts: 9588 |
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: AustraliaPosts: 4 |
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 ZealandPosts: 9588 |
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: AustraliaPosts: 982 |
@Grogs 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: AustraliaPosts: 4 |
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: AustraliaPosts: 6269 |
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: AustraliaPosts: 1329 |
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: AustraliaPosts: 4 |
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 ZealandPosts: 9588 |
@ 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! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |