PDA

View Full Version : Hserin Syntax



xapmanis
- 8th April 2013, 21:04
Hello there :) Im working with a project and using the Hserin command is my final Step to finish it ( i need PC-MCU communication on background ).
Im using PIC18F26K22 it's kind new controller but so easy to work with and so good.
I have made C7 input and C6 output from TRISC register (C6/C7 = TX1/RX1)

Communication Configs on laptop are

Baud = 9600
Parity = No Parity
ByteSize = 8
StopBits = 1



DEFINE OSC 32
DEFINE HSER_BAUD 9600 'Hser baud rate
DEFINE HSER_CLROERR 1 'Hser clear overflow automatically
DEFINE HSER_SPBRG 25 'Hser spbrg init
DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_BITS 9 'Hser Use 9th bit for parity

Main:
hserin [str rec\10]
for i=0 to 10
hserout [rec[i],13,10]
next i
pause 1000

goto main


This is the part of the code that i use Hserin and Hserout (to see if what's pic is taking are correct )

Can you help me ?? Do i have wrong syntax ?? or Wrong Defines ?? I just got tired today for searching ways to make EUSART work :frown: :frown:

HenrikOlsson
- 8th April 2013, 21:23
Hi,
One thing is that you claim to have the laptop set to no parity but the code is setup for 9 bits. I'd remove the DEFINE HSER_BITS 9.
Also, you're receiving a string of 10 bytes but you're sending 11 bytes (+13,10). Shouldn't prevent it from running though.
Then I'd do a simple HSEROUT["Program Start",10,13] before entering the Main loop - just to see if the USART is alive and the connection is OK.

/Henrik.

xapmanis
- 9th April 2013, 07:44
Thank you a lot Henrik for the advises ill work on it when i get back from college.

xapmanis
- 9th April 2013, 21:05
Hello Henrik, I got back home and did run some tests. I found what i did wrong !! I did put wrong defines.
The only defines a simple HSEROUT/HSERIN needs are:

DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 20h 'Hser transmit status init
DEFINE HSER_BAUD 9600 'Hser baud rate
DEFINE HSER_CLROERR 1 'Hser clear overflow automatically

The thing that put me through trouble was that
DEFINE HSER_BAUD 9600 and DEFINE HSER_SPBRG 25 does the same thing, they set the BaudRate and u can't use them both (what i did !!) :P

Mistakes on pics can sometimes drive me crazy !! Thank you for your reply :) :)

Regards, Kostas

xapmanis
- 9th April 2013, 21:09
Hello Henrik, I got back home and did run some tests. I found what i did wrong !! I did put wrong defines.
The only defines a simple HSEROUT/HSERIN needs are:

DEFINE HSER_RCSTA 90h 'Hser receive status init
DEFINE HSER_TXSTA 20h 'Hser transmit status init
DEFINE HSER_BAUD 9600 'Hser baud rate
DEFINE HSER_CLROERR 1 'Hser clear overflow automatically

The thing that put me through trouble was that
DEFINE HSER_BAUD 9600 and DEFINE HSER_SPBRG 25 does the same thing, they set the BaudRate and u can't use them both (what i did !!) :P

Mistakes on pics can sometimes drive me crazy !! Thank you for your reply :) :)

Regards, Kostas

Sherbrook
- 9th April 2013, 23:13
Hi
When using the PIC USART the Tx pin should be set to INPUT, not output as you would expect.
See PIC 18F2x/4xK22 datasheet page 270 section 16.1.1.7
Phil

xapmanis
- 10th April 2013, 09:11
Hey phil, i just read page 270. It's true what you said but it seems to work both ways. I think Hserout/Hserin sets TRIS register automatically.
Regards Kostas.