Jump to content
Sign in to follow this  
zzjoki

Rs232 Docs

Recommended Posts

I'm trying to set up a quick rs232 connection and am frustrated trying to understand the rs232_driver.h.

 

On first glance the header file is confusing. Templates? Emulated USART?

 

Anyway, I'm sure you're aware of the need. I'm just sending a "vote" for more docs as time allows.

Share this post


Link to post
Share on other sites

YES!!!! I'm having the same problem for a PIC18F4520 on picdem2plus. Just one small working file as an example would be SO helpful....

Share this post


Link to post
Share on other sites
I'm trying to set up a quick rs232 connection and am frustrated trying to understand the rs232_driver.h.

 

On first glance the header file is confusing. Templates? Emulated USART?

 

Anyway, I'm sure you're aware of the need. I'm just sending a "vote" for more docs as time allows.

 

Me to. However keep in mind that in some ways a good demo program ( not overly complex ) can be as good or better than documentation.

That is how i got it working.

 

Here is my contribution http://home.comcast.net/~russ_hensel/RClub...tepperTest.html

 

Note that there are many ways to do rs232, with or without hardware support, interrupt driven or polling. It is hard for one example problem to show more than one way, and documentation of all can be very complex.

Share this post


Link to post
Share on other sites

I am curious why you need more documents...

 

Serial/RS232 libraries are arguably to help new users only, you will find far more useful information in the datasheet.

 

I suppose I should qualify that, to initialize serial you set a handfull of flags and that is the hardest part of setting up serial.

Most serial libraries(not all) utilize functions that result in extra processing time for something that takes one cycle. The classic example of this is checking the transmit flag.

 

Anyway here is a simple init and remap you can drop in a header and use:

#ifndef	_SERIAL_H
#define	_SERIAL_H

#include <system.h>

volatile bit _SER_TRISIN		@TRISC.7;	
volatile bit _SER_TRISOUT	@TRISC.6;	

volatile bit _SER_SPBRG		@SPBRG;	
volatile unsigned char _SER_TXREG		@TXREG;	
volatile unsigned char _SER_RXREG		@RCREG;
#define 	_SER_RCREG	_SER_RXREG	/* Naming Convention Macro */

volatile bit _SER_TX9D		@TXSTA.0;	/* Transmit 9 Bit */
volatile bit _SER_TRMT		@TXSTA.1;	/*  */
volatile bit _SER_BRGH		@TXSTA.2;	/*  */
volatile bit _SER_SYNC		@TXSTA.4;	/*  */
volatile bit _SER_TXEN		@TXSTA.5;	/*  */
volatile bit _SER_TX9		@TXSTA.6;	/*  */
volatile bit _SER_CSRC		@TXSTA.7;	/*  */

volatile bit _SER_RX9D		@RCSTA.0;	/*  */
volatile bit _SER_OERR		@RCSTA.1;	/*  */
volatile bit _SER_FERR		@RCSTA.2;	/*  */
volatile bit _SER_ADDEN		@RCSTA.3;	/*  */
volatile bit _SER_CREN		@RCSTA.4;	/*  */
volatile bit _SER_SREN		@RCSTA.5;	/*  */
volatile bit _SER_RX9		@RCSTA.6;	/*  */
volatile bit _SER_SPEN		@RCSTA.7;	/*  */


volatile bit _SER_TXIF		@PIR1.4;	/*  */
volatile bit _SER_RXIF		@PIR1.5;	/*  */
#define _SER_RCIF	_SER_RXIF	/* Naming Convention Macro */

void _initSerial(void)
{
/* Specific pin setup */
_SER_TRISOUT = 0;	/* Output */
_SER_TRISIN = 1;	/* Input */
/* TX setup */
_SER_TX9D = 0;		/* 8bit mode */
_SER_TXEN = 1;		/* Enable Transmit */
_SER_SYNC = 0;		/* Asynchronous */
_SER_TRMT = 0;		/* Clear TSR */
_SER_BRGH = 1;		/* High Speed */
/* RX setup */
_SER_SPEN = 1;		/* Enable Serial */
_SER_RX9D = 0;		/* 8bit mode */
_SER_CREN = 1;		/* Cont. Receive */
/* 115.2 baud @ 20Mhz
* BaudRate = Fosc div (16(x+1))
* 113636.3636 = 20Mhz div (16(9+1))
*/
_SER_SPBRG = 10;	
_SER_RXIF = 0;		/* Clear RX Interrupt */
}

#endif /* EOF */

 

Hope that helps.

Share this post


Link to post
Share on other sites
I am curious why you need more documents...

 

Serial/RS232 libraries are arguably to help new users only, you will find far more useful information in the datasheet

 

I believe it's the mixing of the ideas of emulated rs232, templates, along with plain old rs232 use. It's a bigger bite for a newbie to chew on.

 

Why or when would you use emulated rs232 for devices which have hardware rs232, like the 16f877. Why are there two timing parameters that look different?

 

A little study on my part would probably solve these puzzles.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...