Haz una pregunta
  Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos
Foros Registrarse ¿Olvidaste tu contraseña?

Temas similares

25/08/2011 #1


2 Stop-Bits en RS232 con CCS
Estimados!!
Una pregunta pequeña. Estoy usando el CCS para programar el 16F877, y necesito implementarle un puerto RS232 con 2 bits de stop. La versión de CCS que uso es 4.068.

El problemilla que tengo, es que no sé cómo configurarle que tenga 2 bits de stop. Si se tratase del protocolo RS485, vería que el CCS viene con un Header File que trae el código del RS485 y podría manipularlo. No es así el caso del RS232.

La línea de código para inicializar el puerto es la de siempre:

Código:
#use rs232(baud=38400,parity=N,xmit=PIN_A1,rcv=PIN_A2,bits=8,enable=PIN_A0)
Bien... y dónde o cómo le configuro que quiero 2 Stop Bits?
Se puede?

Agradezco mucho sus respuestas!!
Saludos!
26/08/2011 #2


Hola, prueba esto
#use rs232(baud=38400,parity=N,xmit=PIN_A1,rcv=PIN_A2,b its=8,enable=PIN_A0,STOP=2)
27/08/2011 #3


Ooook!! Muchas gracias. Lo probaré. Solo que como no sé cómo está armada esa librería, ya que parece que está embebida en el CCS, no sé cuáles son los parámetros, y el manual tampoco lo indica.

Avisaré cuando funcione.
Gracias!
Saludos!
29/08/2011 #4


Hola, los parametros se pueden cambiar todos sin problemas te dejo una parte del archivo de ayuda del CCS

#USE RS232

--------------------------------------------------------------------------------
Syntax:
#use rs232 (options)

Elements:
Options are separated by commas and may be:

STREAM=id
Associates a stream identifier with this RS232 port. The identifier may then be used in functions like fputc.

BAUD=x
Set baud rate to x

NOINIT option:

Use baud=0 to not init the UART and pins C6 and C7 can still be used for input-output functions.

#use rs232(baud=0,options)

To make printf work with NOINIT option, use:

setup_uart(9600);

XMIT=pin
Set transmit pin

RCV=pin
Set receive pin

FORCE_SW
Will generate software serial I/O routines even when the UART pins are specified.

BRGH1OK
Allow bad baud rates on chips that have baud rate problems.

ENABLE=pin
The specified pin will be high during transmit. This may be used to enable 485 transmit.

DEBUGGER
Indicates this stream is used to send/receive data though a CCS ICD unit. The default pin used in B3, use XMIT= and RCV= to change the pin used. Both should be the same pin.

RESTART_WDT
Will cause GETC() to clear the WDT as it waits for a character.

INVERT
Invert the polarity of the serial pins (normally not needed when level converter, such as the MAX232). May not be used with the internal UART.

PARITY=X
Where x is N, E, or O.

BITS =X
Where x is 5-9 (5-7 may not be used with the SCI).

FLOAT_HIGH
The line is not driven high. This is used for open collector outputs. Bit 6 in RS232_ERRORS is set if the pin is not high at the end of the bit time.

ERRORS
Used to cause the compiler to keep receive errors in the variable RS232_ERRORS and to reset errors when they occur.

SAMPLE_EARLY
A getc() normally samples data in the middle of a bit time. This option causes the sample to be at the start of a bit time. May not be used with the UART.

RETURN=pin
For FLOAT_HIGH and MULTI_MASTER this is the pin used to read the signal back. The default for FLOAT_HIGH is the XMIT pin and for MULTI_MASTER the RCV pin.

MULTI_MASTER
Uses the RETURN pin to determine if another master on the bus is transmitting at the same time. If a collision is detected bit 6 is set in RS232_ERRORS and all future PUTC's are ignored until bit 6 is cleared. The signal is checked at the start and end of a bit time. May not be used with the UART.

LONG_DATA
Makes getc() return an int16 and putc accept an int16. This is for 9 bit data formats.

DISABLE_INTS

Will cause interrupts to be disabled when the routines get or put a character. This prevents character distortion for software implemented I/O and prevents interaction between I/O in interrupt handlers and the main program when using the UART.

STOP=X

To set the number of stop bits (default is 1). This works for both UART and

non-UART ports.

TIMEOUT=X

To set the time getc() waits for a byte in milliseconds. If no character comes in within this time the RS232_ERRORS is set to 0 as well as the return value form getc(). This works for both UART and non-UART ports.

SYNC_SLAVE
Makes the RS232 line a synchronous slave, making the receive pin a clock in, and the data pin the data in/out.

SYNC_MASTER
Makes the RS232 line a synchronous master, making the receive pin a clock out, and the data pin the data in/out.

SYNC_MATER_CONT
Makes the RS232 line a synchronous master mode in continuous receive mode. The receive pin is set as a clock out, and the data pin is set as the data in/out.

UART1
Sets the XMIT= and RCV= to the chips first hardware UART.

UART2

Sets the XMIT= and RCV= to the chips second hardware UART.

Purpose:
This directive tells the compiler the baud rate and pins used for serial I/O. This directive takes effect until another RS232 directive is encountered. The #USE DELAY directive must appear before this directive can be used. This directive enables use of built-in functions such as GETC, PUTC, and PRINTF. The functions created with this directive are exported when using multiple compilation units. To access the correct function use the stream identifier.

When using parts with built-in SCI and the SCI pins are specified, the SCI will be used. If a baud rate cannot be achieved within 3% of the desired value using the current clock rate, an error will be generated. The definition of the RS232_ERRORS is as follows:

No UART:

· Bit 7 is 9th bit for 9 bit data mode (get and put).
· Bit 6 set to one indicates a put failed in float high mode.

With a UART:

· Used only by get:

· Copy of RCSTA register except:

· Bit 0 is used to indicate a parity error.
29/08/2011 #5


Mil gracias!! Muchísimas gracias!!! Esto realmente me sirvió mucho!

Saludoooooooos!
Respuesta
¿Tienes una mejor respuesta a este tema? ¿Quieres hacerle una pregunta a nuestra comunidad y sus expertos? Registrate

Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2011, Crawlability, Inc.