I'm sorry guys. I was very very tired. I have a crazy learning curve, and sometimes when I push wide-open-throttle for too long cuz I've really bitten off too much, I burn out and crash. I've been asleep since Saturday... five weeks was just too long. I really do appreciate all the help! You all are great!
Can I use EUSART over BT HC-05? I would assume not since one is UART and one is EUSART...
If that's the case my problem is then:
1. I cant use DT's interrupts without corrupting my serin/serout. And I have to assume it'll corrupt hserin/hserout as well.
2. I can't use ON INTERRUPT cuz it'll miss pulses during even the shortest waits. This is even worse than #1 since the machine will be lost.
If I use serial interrupts and program loops, which from how arduino is structured, I assume that's what happens on that platform, wouldn't that solve my problem once and for all?
I may be wrong, but the only difference between SERIN and HSERIN is one is handled by software, the other by hardware. But the actual signal is identical, bluetooth shouldn't be able to know or care how it was generated.
Multicalc, you need a DLL possibly. It's in that thread. It works on my XP and WIN7 machines. You REALLY want to get this tool working, it does other things as well as the USART settings.
If an Arduino can do something, I don't see a reason why a PIC couldn't do it.
Robert
One difference is that Hardware USART requires an RS-232 driver but software does not. Also with software the pins are not fixed. Just need to take this into account when deciding which to use. Obviously if there is no RS-232 driver available then Hardware USART can not be used. I wonder if this is why he could not get HSERIN to work, could explain the gibberish he got.
Steve Earl www.datageo.co.uk
Might be on to something. I forgot I use a MAX232 in my setup.
PC side uses more than 5V (12V I think), good thing a PIC can take a beating.
Robert
Look what I found.
http://www.picbasic.co.uk/forum/show...2591#post82591
Robert
Jury's still out on the beating... I toast them at regular intervals doing far less nefarious acts to them.... However, they are, on whole, much cheaper to replace than arduino boards.
As far as the 12v tho, this 16f1829 chip I'm using now has been a hoss so far. And it started life as a PICAXE20M2. So when I first flashed it, it was with a home-made serial cable with no MAX232 or anything. Just straight out the serial port to the chip, so I think some chips will handle it better than most think...
Steve Earl www.datageo.co.uk
Hi,
If SEROUT works with the HC-05 then HSEROUT will - as long as you get the polarity and baudrate correct. USART vs EUSART is just a matter of the features available they both do asyncronous serial and they both work with HSERIN/HSEROUT.Can I use EUSART over BT HC-05? I would assume not since one is UART and one is EUSART...
That's correct and it's just the nature of the beast basically. It's not a problem, issue or bug, it's just the way the microcontroller works. If it's sitting in a tight software timed loop (which SERIN is) and an interrupt forces it to go and do something else the timing of that tight software loop is thrown off - nothing you can do about that.1. I cant use DT's interrupts without corrupting my serin/serout. And I have to assume it'll corrupt hserin/hserout as well.
That's also correct due to the reasons described earlier.2. I can't use ON INTERRUPT cuz it'll miss pulses during even the shortest waits. This is even worse than #1 since the machine will be lost.
Well, that depends..... For cabled connection to a PC it's a good idea to use a RS232 tranceiver for several reasons. Normally, the polarity of the USART output on the PIC is inverted in respect to what the PC expects. A typical RS232 tranceivers does two things. It "boosts" the signal voltage leverl so it falls within the specs for a proper RS232 connection and it inverts the signal so the PC can read it correctly.One difference is that Hardware USART requires an RS-232 driver...
Now, since we're talking about a Bluetooth connection here and it does work with SEROUT I probably wouldn't want to put a MAX232 between the PIC and the bluetooth module since it's most likely designed to operate at TTL levels. However, and as has been pointed out before, you need to watch the polarity and make it match whatever you're using with SEROUT. Either invert in in the PIC (if it's got that option) or use an external inverter between the PIC and the Bluetooth module.
Take a step back, write a small test program just for the HSEROUT/HSERIN part and get that working.
/Henrik.
OK. I got multicalc working.
I got hserout working.
hserin - notsomuch.
My menu looks fine in the terminal. (although I can't test it with interrupts firing since I can't respond and mover the dish) But it just sits there and looks at me stupid when I give a command.
Code:'**************************************************************** '* Name : UNTITLED.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 6/7/2014 * '* Version : 1.0 * '* Notes : * '* : * '**************************************************************** INCLUDE "DT_INTS-14.bas" INCLUDE "ReEnterPBP.bas" DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1 DEFINE HSER_SPBRG 129 ' 9600 Baud @ 20MHz, 0.16% DEFINE HSER_CLROERR 1 ' Clear overflow automatically APFCON0.2 = 1 APFCON0.7 = 1 #CONFIG __config _CONFIG1, _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF __config _CONFIG2, _PLLEN_OFF & _LVP_OFF #ENDCONFIG DEFINE OSC 20 ANSELA = 0 ANSELB = 0 ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT_INT, _doEncoder, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM @ INT_ENABLE INT_INT LED var PORTC.7 TRISC.7 = 0 LED = 0 DOWN var PORTB.4 TRISB.4 = 0 DOWN = 0 EAST var PORTB.5 TRISB.5 = 0 EAST = 0 WEST var PORTB.6 TRISB.6 = 0 WEST = 0 TRISC.5 = 1 UP var PORTB.7 TRISB.7 = 0 UP = 0 a0 var byte a1 var byte e0 var byte e1 var byte i var byte VerboseMode var byte cereal var byte Aencoder0Pos var word Eencoder0Pos var word VerboseMode = 1 goto MainMenu doEncoder: if UP = 1 then 'if e0 = 5 then Eencoder0Pos = Eencoder0Pos + 1 ' e0 = 0 if VerboseMode = 1 then Hserout ["Eencoder0Pos = ", #Eencoder0Pos, 13, 10] 'endif 'e0 = e0 + 1 endif if DOWN = 1 then 'if e1 = 5 then Eencoder0Pos = Eencoder0Pos - 1 ' e1 = 0 if VerboseMode = 1 then Hserout ["Eencoder0Pos = ", #Eencoder0Pos, 13, 10] 'endif 'e1 = e1 + 1 endif if EAST = 1 then if a0 = 5 then Aencoder0Pos = Aencoder0Pos + 1 A0 = 0 if VerboseMode = 1 then Hserout ["Aencoder0Pos = ", #Aencoder0Pos, 13, 10] endif a0 = a0 + 1 endif if WEST = 1 then if a1 = 5 then Aencoder0Pos = Aencoder0Pos - 1 a1 = 0 if VerboseMode = 1 then Hserout ["Aencoder0Pos = ", #Aencoder0Pos, 13, 10] endif a1 = a1 + 1 endif @ INT_RETURN MainMenu: gosub CLR HSEROUT ["******** MAIN MENU ********", 13, 10, 10] HSEROUT [" 1. Start Homing Sequence", 13, 10] HSEROUT [" 2. Manual JOG Mode", 13, 10] HSEROUT [" 3. Auto-Acquire Satellite", 13, 10] HSEROUT [" 4. Stow Dish for Travel", 13, 10, 10] HSEROUT ["Enter Your Selection:"] hSERIN [cereal] if VerboseMode = 1 then HSEROUT [#cereal,13,10] ' If cereal = "1" then goto HomeDish If cereal = "2" then goto JogMenu ' If cereal = "3" then goto TEST1 ' If cereal = "4" then goto Startup goto MainMenu JogMenu: gosub CLR pause 250 HSEROUT ["***** JOG MENU *****", 13, 10, 10] HSEROUT ["U - UP", 13, 10] HSEROUT ["D - DOWN", 13, 10] HSEROUT ["E - EAST", 13, 10] HSEROUT ["W - WEST", 13, 10] HSEROUT ["S - ALL STOP", 13, 10] HSEROUT ["X - MAIN MENU", 13, 10, 10] hSERIN [cereal] if cereal = "U" Then gosub allSTOP HIGH UP endif if cereal = "D" then gosub allSTOP HIGH DOWN endif if cereal = "E" then gosub allSTOP high EAST endif if cereal = "W" then gosub allSTOP HIGH WEST endif if cereal = "S" then gosub allSTOP if cereal = "X" then gosub allSTOP goto MainMenu endif goto JOGMenu allSTOP: EAST = 0 UP = 0 DOWN = 0 WEST = 0 if VerboseMode = 1 then GOSUB POS return CLR: if VerboseMode = 0 then For i = 0 to 30 HSEROUT [10] next i endif return abort: gosub allSTOP gosub clr HSEROUT ["USER STOP! -- MOVE ABORTED!", 13, 10] PAUSE(5000) goto MainMenu moveerror: gosub allSTOP gosub clr HSEROUT ["SYSTEM ERROR! -- MOVE ABORTED!", 13, 10] PAUSE(5000) goto MainMenu POS: pause 100 HSEROUT [" EL -- ", #Eencoder0Pos, " AZ -- ", #Aencoder0Pos, 13, 10] pause 2000 return
Are you saying these lines do not execute?
hSERIN [cereal]
if VerboseMode = 1 then HSEROUT [#cereal,13,10]
Steve Earl www.datageo.co.uk
Are you saying these lines do not execute?
hSERIN [cereal]
if VerboseMode = 1 then HSEROUT [#cereal,13,10]
correct
Steve Earl www.datageo.co.uk
The issue has nothing to do with HSERIN or the program. As you have a MAX232 could you connect direct to your PC and use HyperTerminal to test the functioning?
Steve Earl www.datageo.co.uk
have a look at this thread for some ideas on serial transmission with interrupts
http://support.melabs.com/threads/28...terrupt-Serial
The BT modules could be the issue have they got Flow Control on the RS232. A data sheet would help.
Steve Earl www.datageo.co.uk
Hi,
If SERIN/SEROUT without flow control works across the BT-link (which it apparently is) then HSEROUT/HSERIN will work too. It's just a matter of getting it setup correctly.
Having an oscilliscope or logic analyzer and probing the signals as it enters/exits the PIC would help. Doing so with the "working" version using SEROUT/SERIN and the with the HSEROUT/HSERIN comparing what you get would most likely reveal the issue.
/Henrik.
My understanding is that serin never worked but serout did, post #44, which is why I suspect flow control, we were given the wrong impression when we were told using hardware usart had solved the problem. Do we need more information? or will this lead to more misinformation depending on how I read it.If SERIN/SEROUT without flow control works across the BT-link (which it apparently is) then HSEROUT/HSERIN will work too.
Steve Earl www.datageo.co.uk
Flow control.... hmmmm. Makes me think I may have somethiny else amiss... could it be terminal settings? Serin/serout works fine. I have hooked up an LED to the rx on the pic and I see it flicker on data send. I havent tried to cross the tx/rx to look for echo but I suspect ill get it. Was there something I needed to change in the terminal program to make the data "legit" ? I seem to remember a flow control dropdown box......
I suppose I can also scope the data coming out of the bt and into the pic, but I dont think itll yield much more than seeing the led flicker... unless you want me to somehow capture and post the raw scope results to actually interpret them
I'll be back home in about an hour if you would like me to do that...
The flow control I was thinking of was between the 16f1829 and the BT connected to it.
Steve Earl www.datageo.co.uk
OK! I think I have my permanent solution. Since I had no problems with the first setup I did with this project where I was using physically attached buttons instead of serial commands to control the unit, I am adding a second PIC, whose only job in life is to sit at a serin command pause and await commands. Upon receiving a command, it will simply set a pin high for about 100ms, simulating a button press. Proof of concept already works... Just have two small snags... (and a large one too, but one step at a time lol)
1. I am trying to send via serial just one character. Capital A-F, depending on what combo of buttons is pressed by the user. It's not going thru. The BT is linked. The link seems good. When I hold a button down, it causes the serin pause to release, causing my debugging LED to flash. However, no command is processed. I'm sure it's a format problem or something, but I have tried 9 ways to sunday and I just can't seem to spot what I'm doing wrong. Also, if I shut down the master BT and log my laptop terminal into the dish PIC, sending A-F from the terminal works perfectly and it responds as expected.
2. Only buttons 3 and 4 work. Buttons 1 and 2 do not cause the LED to flash on the receiving end. I assume I'm missing something again about analog/digital, but this pic is very basic and has no ADC, and for the life of me I cannot figure out what I am missing. I have read thru every register in the datasheet, and I'm just not snapping to what it is...
Here is the code for the handheld device:
Here is the code for the PIC16F628A that is receiving the commands and "pressing buttons":Code:'**************************************************************** '* Name : Wireless Handheld Device '* Author : John Moore '* CHIP : PIC16F628A '* Date : May 28, 2014 '* Version : 1.0 '* Notes : This pic will eventually have 4 physical buttons and an LCD '* : as well as a BT device. Right now I just need it to send the '* ; serial commands, as I am monitoring the feedback with a terminal. '**************************************************************** #CONFIG __config 10000111110000 #ENDCONFIG button1 var PORTA.2 button2 var PORTA.3 button3 var PORTA.4 button4 var PORTB.3 TRISA.2 = 1 TRISA.3 = 1 TRISA.4 = 1 TRISB.3 = 1 cereal var byte TX var PORTB.2 TRISB.2 = 0 START: if button1 = 1 then cereal = "A" if button2 = 1 then cereal = "B" if button3 = 1 then cereal = "C" if button4 = 1 then cereal = "D" if (button2 = 1) and (button3 = 1) then cereal = "E" if (button1 = 1) and (button4 = 1) then cereal = "F" if cereal <> "X" then serout TX, 2, [cereal] pause 100 cereal = "X" GOTO START
Code:'**************************************************************** '* Name : On-Board Communication PIC '* Author : John Moore '* CHIP : PIC16F628A '* Date : May 28, 2014 '* Version : 1.0 '* Notes : This pic will never be more complicated than this. It's only '* : purpose in life is to get characters and push buttons. '**************************************************************** #CONFIG __config 10000111110000 #ENDCONFIG button1 var PORTB.7 button2 var PORTB.6 button3 var PORTB.5 button4 var PORTB.4 TRISB.7 = 0 TRISB.6 = 0 TRISB.5 = 0 TRISB.4 = 0 button1 = 0 button2 = 0 button3 = 0 button4 = 0 RX var PORTB.3 TRISB.3 = 1 LED var PORTA.1 TRISA.1 = 0 cereal var byte START: serin RX, 2, cereal if cereal = "A" then high button1 pause 140 low button1 endif if cereal = "B" then high button2 pause 140 low button2 endif if cereal = "C" then high button3 pause 140 low button3 endif if cereal = "D" then high button4 pause 140 low button4 endif if cereal = "E" then button2 = 1 button3 = 1 pause 140 button2 = 0 button3 = 0 endif if cereal = "F" then button1 = 1 button4 = 1 pause 140 button1 = 0 button4 = 0 endif LED = 1 pause 250 LED = 0 pause 250 GOTO START
bit 7 of your config word should be 0 , having lvp enabled can lead to tears .
the comparator needs to be disabled to use your porta pins as digital
Last edited by richard; - 29th June 2014 at 05:44. Reason: typo
So you have your BT sorted out?
I use a BT chip on my boards with no converter. I have the BT chip running at 3.3v just like the PIC.
I am not sure what you are meaning by handheld device but if you are using a BT chip, look into making the app work on your Android phone.
Look into Basic4Android. Its a piece of cake to use. The wireless side is a bit cumbersome but once you get it going, its pretty slick. I use it to make an app to control up to 48 electrical motors sending data back and forth from the motor control boards to a tablet all wirelessly.
http://www.basic4ppc.com/index.html
If you get try it and need some help, email me at [email protected]
Bookmarks