PDA

View Full Version : Hserout/Hserin max.speed



Mugelpower
- 17th February 2008, 16:56
Hello insider world!

my attempt to send a word and display it on a LCD works with serin and debug, now I try with

HSEROUT/HSERIN and of course it fails.

using two 16F628A with a single canned 20Mhz oscillator.

'************************************************* *******************************************
' HSEROUTFAST1
'16F628A canned 20MHz osc extern
' should count pulses on porta.0 and send by USART to PIC # 2
'************************************************* *******************************************

'
' DEFINITIONS

@__config _EXTCLK_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF

Include "modedefs.bas"
CMCON=%00000111
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 129 '25 for 4MHz
DEFINE HSER_CLROERR 1



Cnt VAR Word ' Cnt is a word variable

' START OF MAIN PROGRAM
' ' Cnt is a word variable
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = %11111110 ' PORT A1 is input
TRISB = %11111111 ' RB output
cnt = 0


main:


COUNT PORTA.0,100,cnt ' Count for 1 second
RCSTA.7 = 1 'usart enabled
HSEROUT [0,cnt ,10,13]
PAUSE 10
RCSTA.7 = 0 'usart disabled

goto main


END ' End of program


and here the recieving program :same setup as above + an lcd in standard configuration.

'************************************************* *******************************************
' PIC#2 : 16F628A 20 Mhz extern canned oscillator same as PIC#1
' should recieve the variable cnt and show it on LCD
'
'************************************************* *******************************************

'
' DEFINITIONS

@__config _EXTCLK_OSC & _WDT_ON & _PWRTE_ON & _MCLRE_ON & _LVP_OFF & _CP_OFF

Include "modedefs.bas"
CMCON=%00000111
DEFINE OSC 20

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 129 '25 for 4MHz
DEFINE HSER_CLROERR 1



Cnt VAR word ' Cnt is a word variable
inputData var word ' variable to receive data into


' START OF MAIN PROGRAM
'
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = 0 ' PORT A is output
TRISB = %11111101 ' RB1 is Input others output
cnt = 0
main:

Hserin [inputData]

cnt = inputData

LCDOUT $FE,2
LCDOUT "cnt=", DEC4 cnt
goto main


END ' End of program

I know HSerin needs some registers to enable and disable but thats too far for me now.

Experience: you can force a 4Mhz PIC16F628A to run on 20MhZ with an extern osc..hehe, everything works..tried some ..hihi

duncan303
- 17th February 2008, 20:56
Hi

I had just a quick glance through to check your Tris settings and came across this

TRISB = %11111101 ' RB1 is Input others output ???

Maybe have a look at the direction of TX/RX both should be set as inputs on both PICs

Therefore on the 16F628A TX/RX are on portB1 and PortB2 respectively.

there may be other issues, I have not studied further,

HTH a little bit

Duncan

Archangel
- 17th February 2008, 21:54
TRISB = %11111101 ' <font color=red>RB1 is Input others output</font color

1 is input, 0 is output, easy to remember 1 looks like I and 0 looks like O :)

Mugelpower
- 18th February 2008, 15:51
do I need to connect both TX RX Lines on both pics crosswise because of some handshake signals or only one wire for sending from one pic to another? I didnīt find a picture of a master/slave configuration, exept Mister_eīs master/slave example wich is great but for serin/serout.
Hey, how about something alike for Hserin/Hserout Mister_e?




Pic 16f628a to pic 16F628a......

skimask
- 19th February 2008, 04:24
do I need to connect both TX RX Lines on both pics crosswise because of some handshake signals or only one wire for sending from one pic to another? I didnīt find a picture of a master/slave configuration, exept Mister_eīs master/slave example wich is great but for serin/serout.
Hey, how about something alike for Hserin/Hserout Mister_e?

Pic 16f628a to pic 16F628a......

You do realize that the only major difference between SERIN/SEROUT and HSERIN/HSEROUT is that SERIN/SEROUT is bit-banged and HSERIN/HSEROUT uses the hardware USART module (if available) in the PIC...right?
Therefore, any example that works with SERIN/SEROUT, should work with HSERIN/HSEROUT, if properly configured...and it follows that you would then have to...Read the datasheets/manuals for the particular device that you are using.

Mugelpower
- 19th February 2008, 08:13
Hi Skimask,

hmm...I can tell you the only thing I knew was that Hserin/Hserout uses the Usart and I hoped that because of this it could run the data transwer partially in the background .that means that the data-bits-pushing is performed with the minimum of software used to speed things up.

because Iīm now thanks to your gurus of piclands help up to 20MHz I may use serin/serout with success....

But: serin/serout and Debugin/Debug worked only with 4 MHz and 4800 baud . any change to that and my recieving PICs LCD showed rubbish. We had that before.

I read cool examples with 112000 baud or so using debug, but that was on "strange" 18F Pics I canīt handle by now.

Maybe I have to switch to a "modern" usart-preferred-PIC with goes along with lots of tutorials or examples or so. The only thing about the usart in the 16F628A I found in the data sheet was "Usart:Y" and the codes for the TX and RX registers.

Tell you what: the learning curve is way steep for an oldschool mechanical engineer of 44 years in foreign language...