Hi all,
Could anyone guide me about setting up the serial communication to 115200 baudrate?
Thanks
kblim
Hi all,
Could anyone guide me about setting up the serial communication to 115200 baudrate?
Thanks
kblim
I use DEBUG & DEBUGIN. These commands produce much smaller code, and
you can get higher data-rates like 19200 with a 4MHz osc.
This example works with a max232 PIC-PC interface. If you need direct, thenCode:DEFINE OSC 20 DEFINE DEBUG_REG PORTC DEFINE DEBUGIN_REG PORTC DEFINE DEBUGIN_BIT 7 DEFINE DEBUG_BIT 6 DEFINE DEBUG_MODE 0 '1 = Inverted, 0 = true DEFINE DEBUGIN_MODE 0 DEFINE DEBUG_BAUD 19200 X VAR BYTE[3] MAIN: DEBUGIN 6000,NoData,[WAIT("A"),str X\3] DEBUG "Received: ",str X\3,13,10 GOTO MAIN NoData: DEBUG "Nada",13,10 GOTO Main END
just change mode to inverted.
Last edited by Bruce; - 25th July 2010 at 22:39. Reason: baud rate change to 19200 max
Hi Bruce,
Just wonder how to use Serout2, Serin2 with 115200 baudrate.
From the formula :int(1000000/baudrate)-20,
if use 115200 i will have int(1000000/115200)-20 = -12
Please help.
kblim
If the baud rate calc doesn't work out to a positive number, then I'm pretty
sure the data rate you need isn't supported by the command.
Use this:
DEFINE HSER_SPBRG 21 'Configuración de velocidad de USART
DEFINE HSER_TXSTA 36 'a 115200 baudios.
Now you can use hserin and hserout at 115200 bauds
Yeah but in synchronous mode... and all that imply too
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
First of all thank you for all the kindness reply. However I still couldn't solve the problem. I think I must clearify something.
Actually I would like to use the Serin2 and Serout2 command to do the asynchronising on any of the hardware pin.
As I know the Hserout and Hserin only implemented on the certain hardware pins.
The command of the SerOut2:
SerOut2 ModemOut, ModemSpeed, ["ate0",13]
Where the
1. ModemOut = Pin to be used
2. ModemSpeed = A number from the calculation Of
[int(1000000/baudrate)-20]
3. ["ate0",13] = any string to send out to the pin
So I do not know the HSER setting will effect the SerOut2 and SerIn2 command or not.
Please help.
I know the hserout instruction is for the hardware USART, but how about the SerIn2 and Serout2 command.
Do you guys use Serin2 and Serout2 command instead of hserout?
What is the main difference between Serin2/Serout2 and hserout?
How to set the 115200 baud rate for serin2/serout2 bcoz previously i was using these command to connect to a gsm module with 19200 baud rate?
Thanks
Hi kblim,
As far as I know, you can't use baud rates higher than 38400 baud (I think) with the ser-type commands.
I'm sure you can't do 115200.
This is because the ser-type commands use a "bit-banging" approach as opposed to the hser-type commands which use the built-in usart and generate less code.
This was the first time that I heard that you can communicate at 115200 using debug though.
What are the pros and cons of that anyhow, Bruce?
Regards.
---> picnaut
The serin, serout type commands were originally designed to offer BASIC Stamp users similar commands. They all produce huge code when used because the command libraries have to cover so many various options to maintain Stamp compatibility.
Debug/Debugin produce much smaller code, and offer the higher data-rates because the library routines are much smaller.
Serin, serout commands can be used on any I/O-pins that support digital I/O. Data-rates & pins used can be changed on the fly. Debug/Debugin pins & data-rates are fixed with the DEFINE used to set them up, but offer much higher data-rates since the library routines are much smaller.
If you need higher baud rates with slower osc speeds, then use Debug and Debugin if you can live with fixed rates & pins you can use.
Of course you can use them all if needed, but I'll normally opt for the hardware USART or Debug/Debugin.
Hi all,
Just wonder how to define the debug to communicate with the open mode when receiving serial data from other device. Using the open mode because need to share the data line with few PICs.
It is possible to do Open mode for DebugIn, Non Open Mode for Debug?
Kindly share your expectise.
Thanks alot.
Regards
There is one other possible unconventional solution... Set SERIN2/SEROUT2 to run at 11500 baud at 4MHz and then switch to 40MHz Oscillator (approipriate 18F PIC Series) WITHOUT telling PICBasic you've done so... everything works at x10 speed... so PAUSE 1000 will only give you 100mS instead of a Second. In theory it should work (I'd use 67 rather than 66 as the calculated Speed figure)...
Hi all,
I was previously using the SerOut2 to send data, but the data line was sharing by few PICs and I have used Open Mode.
Recently porting my code by replacing SerOut2 with the Debug command to save same space. But later found out that there are no way to setup the Debug in the open mode.
Please help! Is there neccessary to use Open mode to share the data? or the Debug doesn't need the Open mode even sharing the data line.
Regards
I have an application where a PIC12F683 has to communicate with an external peripheral. I need SerIn/SerOut because the external device may be 4800 or 9600 bps.
The PIC12F683 also needs to communicate with a PIC16F876A.
Is there any advantage to using Debug/DebugIn for the PIC2PIC comms given that the PIC12F683 already uses SerIn/SerOut?
dhouston, Serin/out provide software type communications and can have the baudrate's and port's changed on the fly during program execution. Therefore the compiled code overhead is quite large, whereas Debigin/out commands after the compile are the smallest for software type usart emulation. The port and baudrate used for Debugin/out can not be changed during program execution therefor they must be DEFINE'd at the start of the source program. There are some other functions that are lost in the use of Debugin/out but for the most part it was designed for program debugging with a terminal. I have used Debugout for PIC micros that have no internal usart and still use it today for programming debug functions. The limitations of Debugin/out are covered in the manual. LOL
Dave Purola,
N8NTA
Dave,
I understand all of that.
My question is, given that I have to use SerIn/SerOut for the external link, will I take another overhead hit if I also use it for the internal link or can I gain by using Debug for the internal link?
dhouston , If you are already using Serin/out on your program there is no need to add the extra code overhead in using Debugin/out unless you need the serial speed.
Dave Purola,
N8NTA
I'm having difficulties making my PIC's HSEROUT working at all. I need to get 115200bps.
I can reach 38400bps with the SEROUT2 command without any trouble.
For 115200bps, I go with HSEROUT. I use the MCS Serial Communicator and the PIC has a 20MHz crystal.
SEROUT2 is okay, HSEROUT is not working at all (not even @1200bps).
I've been trying to make it work for hours and hours, redoing the cabling (see picture) different ways as suggested in other threads, modifying the code also many times but no success until now. I just always get garbage on the serial terminal's screen.
Code:' SEROUT2 ' PIC 16F690 Fuses @ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC OPTION_REG = 000000 'PORT A&B Pull-Ups (look WPUA & WPUB) ADCON0 = 000000 'A/D Module ANSEL = 000000 'Select analog inputs Channels 0 to 7 ANSELH = 000000 'Select analog inputs Channels 8 to 11 INTCON = 000000 'INTERRUPT Control 'WPUA = 000000 'Select PORTA weak pull-ups 'IOCA = 000000 'Interrupt On Change selection CM1CON0 = 000000 'Comparator1 Module CM2CON0 = 000000 'Comparator2 Module TRISA = 000000 'Set Input/Output (0 to 5) PORTA = 000000 'Ports High/Low (0 to 5) TRISB = 000000 'Set Input/Output (4 to 7) PORTB = 000000 'Ports High/Low (4 to 7) TRISC = 000000 'Set Input/Output (0 to 7) PORTC = 000000 'Ports High/Low (0 to 7) '------------------------------------------------------------------------------- ' DEFINEs DEFINE OSC 20 DEFINE LCD_COMMANDUS 2000 DEFINE LCD_DATAUS 50 '------------------------------------------------------------------------------- LED1 VAR PORTA.2 Counter VAR WORD Counter = 0 TEST: TOGGLE LED1 'serout2 PORTB.7,16416,[dec counter,13,10]'19200 DIN with MAX232 SEROUT2 PORTB.7,16390,[DEC Counter,13,10]'38400 DIN with MAX232 PAUSE 500 Counter = Counter + 1 GOTO TEST ENDCode:' HSEROUT ' PIC 16F690 Fuses @ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC OPTION_REG = 000000 'PORT A&B Pull-Ups (look WPUA & WPUB) ADCON0 = 000000 'A/D Module ANSEL = 000000 'Select analog inputs Channels 0 to 7 ANSELH = 000000 'Select analog inputs Channels 8 to 11 INTCON = 000000 'INTERRUPT Control 'WPUA = 000000 'Select PORTA weak pull-ups 'IOCA = 000000 'Interrupt On Change selection CM1CON0 = 000000 'Comparator1 Module CM2CON0 = 000000 'Comparator2 Module TRISA = 000000 'Set Input/Output (0 to 5) PORTA = 000000 'Ports High/Low (0 to 5) TRISB = 000000 'Set Input/Output (4 to 7) PORTB = 000000 'Ports High/Low (4 to 7) TRISC = 000000 'Set Input/Output (0 to 7) PORTC = 000000 'Ports High/Low (0 to 7) '------------------------------------------------------------------------------- ' DEFINEs DEFINE OSC 20 DEFINE HSER_RCSTA 90h DEFINE HSER_TXSTA 24h DEFINE HSER_BAUD 19200 'DEFINE HSER_SPBRG 64 DEFINE HSER_CLOERR 1 '------------------------------------------------------------------------------- LED1 VAR PORTA.2 Counter VAR WORD Counter = 0 TEST: TOGGLE LED1 HSEROUT [DEC Counter,13,10] PAUSE 500 Counter = Counter + 1 GOTO TEST END
There's a MAX232 close to the PIC making me think the lines are as short as possible. But is it enough on the hw side?
Last edited by flotulopex; - 16th October 2011 at 14:56.
Roger
Try changing
DEFINE HSER_TXSTA 24h to
DEFINE HSER_TXSTA 20h
Charles Linquist
I tried this already: no success.
Still looks like this:
Roger
I was referring to you trying to run 19200. That was what your code above referenced.
If you want to run 115K baud -
From Mr. E's Multi-Calc:
RCSTA1 = $90 ' Enable serial port & continuous receive
TXSTA1 = $24 ' Enable transmit, BRGH = 1
SPBRG1 = 42 ' 115200 Baud @ 20MHz, 0.94%
SPBRGH1 = 0
BAUDCON1.3 = 1 ' Enable 16 bit baudrate generator
Some of these might change if you are using a 16F part.
You may have to remove the "1" after the register names if you are not using PBP 3
Charles Linquist
if serout2 was inverted, HSER is not inverted. 16416 in table shows inverted.
Last edited by amgen; - 16th October 2011 at 19:40.
Is there any way to set the DEBUG baud rate at runtime?
Sorry, I don't understand what you want me to do?! I don't have any problems with SEROUT2 at this time.Originally Posted by amgen
I did try this at all available baudrates; never worked. Before you ask, yes, I tried with another PICOriginally Posted by Charles Linquis
I do use a PIC16F690 and modified the code with your suggestion as it is herunder:As said, I tried also the lowest selectable baudrate 300bps; even so, I can't see any "good" data in the terminal.Code:' HSEROUT ' PIC 16F690 Fuses @ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC OPTION_REG = %10000000 'PORT A&B Pull-Ups (look WPUA & WPUB) ADCON0 = %00000000 'A/D Module ANSEL = %00000000 'Select analog inputs Channels 0 to 7 ANSELH = %00000000 'Select analog inputs Channels 8 to 11 INTCON = %00000000 'INTERRUPT Control 'WPUA = %00000000 'Select PORTA weak pull-ups 'IOCA = %00000000 'Interrupt On Change selection CM1CON0 = %00000000 'Comparator1 Module CM2CON0 = %00000000 'Comparator2 Module TRISA = %00000000 'Set Input/Output (0 to 5) PORTA = %00000000 'Ports High/Low (0 to 5) TRISB = %00000000 'Set Input/Output (4 to 7) PORTB = %00000000 'Ports High/Low (4 to 7) TRISC = %00000000 'Set Input/Output (0 to 7) PORTC = %00000000 'Ports High/Low (0 to 7) '------------------------------------------------------------------------------- ' DEFINEs DEFINE OSC 20 RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $24 ' Enable transmit, BRGH = 1 SPBRG = 42 ' 115200 Baud @ 20MHz, 0.94% BAUDCTL.3 = 1 'for PIC16F690 - BAUDCON1.3 = 1 ' Enable 16 bit baudrate generator '------------------------------------------------------------------------------- LED1 var PORTA.2 Counter var word Counter = 0 TEST: Toggle led1 HSEROUT [dec counter,13,10] pause 500 Counter = counter + 1 goto test end
Roger
back to basic Roger... check your ANSEL(h) settings.. you're sending something on a analog configured pin.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
are you using a USB to serial converter ?
Why didn't you SHOUT IT OUT LOUD!!??
You're absolutely right: the signal has to be inverted in the way I'm using it. I added a transistor to invert the signal going to the MAX232 chip and guess what: IT WORKS!!!!
The HSEROUT code example in one of my previous post is working fine, also with 115200bps.
I still have some transmission errors but I think this can be due to the small error rate - I'll try with a 18,432MHz crystal.
Thanks a lot and have a nice day.
Roger
Hi there,
I need to use a 18,432MHz crystal with this PIC16F690 project to achieve a clean 115200bps serial comm.
Looking at the OSC values in the DEFINEs list, I can't find the value "18".
Shall I simply define the OSC as, i.e., "20" while connecting a 18MHZ crystal?
The only drawback I can see is about timing in PAUSE commands or similar. I assume the HUSART will still run from the 18MHz osc; right?
Any other problems I wouldn't see?
Roger
I don't like to yell because I'm usually wrong.Why didn't you SHOUT IT OUT LOUD!!??
Just a few thoughts, the Max232 chip inverts signal, if your using USB to serial adapter, that takes a non-inverted signal, so you may be inverting redundently. Also, have you tried OSC-Tune to adjust clock to good 115Kb, then you can use standard Xtal ?
Don
Yes, I do use a USB-to-serial interface (FTDI).
I now corrected the BAUDCTL register so as it sends data inverted (no need for a hw inverter anymore).
As far as I understand this register's function, OSCTUNE calibrates the internal oscillator so I don't think it will affect the baud rate generator (I don't know).
BTW, how do I measure a "good" 115200bps signal?
Code:' HSEROUT ' PIC 16F690 Fuses @ __Config _FCMEN_OFF &_IESO_OFF &_BOR_OFF &_CPD_OFF &_CP_OFF &_MCLRE_OFF &_PWRTE_OFF &_WDT_OFF &_HS_OSC OPTION_REG = %10000000 'PORT A&B Pull-Ups (look WPUA & WPUB) ADCON0 = %00000000 'A/D Module ANSEL = %00000000 'Select analog inputs Channels 0 to 7 ANSELH = %00000000 'Select analog inputs Channels 8 to 11 INTCON = %00000000 'INTERRUPT Control 'WPUA = %00000000 'Select PORTA weak pull-ups 'IOCA = %00000000 'Interrupt On Change selection CM1CON0 = %00000000 'Comparator1 Module CM2CON0 = %00000000 'Comparator2 Module TRISA = %00000000 'Set Input/Output (0 to 5) PORTA = %00000000 'Ports High/Low (0 to 5) TRISB = %00000000 'Set Input/Output (4 to 7) PORTB = %00000000 'Ports High/Low (4 to 7) TRISC = %00000000 'Set Input/Output (0 to 7) PORTC = %00000000 'Ports High/Low (0 to 7) '------------------------------------------------------------------------------- ' DEFINEs DEFINE OSC 20 RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $24 ' Enable transmit, BRGH = 1 SPBRG = 42 ' 115200 Baud @ 20MHz, 0.94% BAUDCTL = 24 'Transmit INVERTED data to RB7, Enable 16 bit baudrate generator '------------------------------------------------------------------------------- LED1 var PORTA.2 Counter var word Counter = 0 TEST: Toggle led1 HSEROUT [dec counter,13,10] pause 500 Counter = counter + 1 goto test end
Roger
The baud rate generator will be accurate. If the formula says you will get 115KBaud with a 20Mhz oscillator, you will.
If you don't get 115K baud, then you aren't really running at 20Mhz, or the receiving device has an issue.
I mentioned in another post how to measure just how fast your chip is running - without an oscilloscope.
(Turn LED ON)
For X = 1 to 60
Pause 60000
Next X
(Turn LED OFF)
Wait one hour. If your LED goes off in exactly 60 minutes, your chip is running the speed you think it is. Using a
calculator, you can measure the actual frequency to about 0.1%
A useful tool is BRAY's TERMINAL program (Google it). Free, and it lets you set odd baud rates, like 113Kbaud.
or 120Kbaud.
Charles Linquist
Can anyone give some info about this please?I need to use a 18,432MHz crystal...
Looking at the OSC values in the DEFINEs list, I can't find the value "18".
Shall I simply define the OSC as, i.e., "20" while connecting a 18MHZ crystal?
Roger
Does really nobody know something about that?I need to use a 18,432MHz crystal...
Looking at the OSC values in the DEFINEs list, I can't find the value "18".
Shall I simply define the OSC as, i.e., "20" while connecting a 18MHZ crystal?
Roger
You are going to have to unless you change the libraries. Just remember that any PAUSE commands will be 8.5% longer than you think.
You can get around that by creating some variables.
For example: If your program needed 3 different delays 20ms, 50ms, 190ms
You would create 3 vars
delay20 con 18
delay50 con 46
delay190 con 175
Now, if you need a 20mSec delay, you can use the command
PAUSE delay20
It is not exact, but it is close.
Charles Linquist
Thanks Charles,
I thought this would happen. No problem then, for me ;-)
Roger
Bookmarks