NEW! RCL-1 RS232 Level Converter in a DB9 backshell
There has been a lot of confusion on how the RX or TX pins should be set with regard to TRIS on the PICs with hardware USARTs, especially with regard to making them work in interrupt mode.
First, keep in mind that MPLAB [may] not (correctly or otherwise) simulate the USART Hardware.
Second, read the datasheets. They are tricky as hell and the details may be buried in there
From DS30292B-page 33 (the '873 datasheet section 3.3 PORTC and TRISC Registers):
When enabling peripheral functions, care should be taken in defining TRIS bits for each PORTC pin. Some peripherals override the TRIS bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input. Since the TRIS bit override is in effect while the peripheral is enabled, read-modify-write instructions (BSF, BCF, XORWF) with TRISC as destination should be avoided. The user should refer to the corresponding peripheral section for the correct TRIS bit settings.
From DS30292B-page 95 (the '873 datasheet section 10.0n on USART):
Bit SPEN (RCSTA<7>) and bits TRISC<7:6> have to be set in order to configure pins RC6/TX/CK and RC7/RX/DT as the Universal Synchronous Asynchro-nous Receiver Transmitter.
In Microchip lingo "set" means make the bit a 1 which would normally set the pin as an input. That isn't confusing with RX, but the requirement that the TRISC bit for the TX pin be set is rather counter-intuative.
Beyond the SPEN and TRIS setup, at least on some PIC's, the ANSEL bits can override the SPEN setting. So, even if SPEN is set, and TRIS is set for both RX and TX, if the associated pins are set as analog inputs, you may not receive any data.
PICUART.ZIP from http://redrival.com/mcgahee/ or http://mcgahee.freeservers.com is known to work and explains most of the common problems. The ZIP file only contains this ASM: picuart.asm which is cached here since the mcgahee pages appear to have been lost.
the PICList.com SPBRG Calc (based on code from Andy Kunz)
Automatic (asm macro) setting of the SPBRG, etc... values based on desired baud rate and processor speed from Olin Lathrop
.sti file generator for RS232 simulation in MPLAB
Detecting rising and falling edge events is a useful tool for "bit bang" or software only implementations of serial receive routines.
From the CHEAPIC tutorial:
Samples:
Olin Lathrop notes:
The only difference [between the 16 and 17 chips with regard to the USART is] that there is no high speed mode. This means you have to carefully choose your crystal frequency if you want to use a fast baud rate. I used a 17 PIC once because these are the only PICs with two UARTS.
Also: RS232@, TTL to/from RS232@, TI Calc@ PIC C IO@ High speed serial IO pin sampleing
Books:
See also:
http://www.drzyzgula.org/bob/electronics/frtom.shtml The links to picuart.zip on this page do not work. I found a page that has this(picuart.zip) and other helpful information. http://www.drzyzgula.org/bob/electronics/frtom.shtml
Books:
Questions:
None of the links to PICUART.zip work. Google turns up nothing, nor any relevant links off usenet. If anyone has a copy, I'd be happy to host it on my server. -Reza
I want to use 4 serial ports with only 1 microcontroller, is it posible ? Somebody knows how use 4 serial ports ( RS 232 ) using a PIC microcontroller ?
James Newton answers:
See Ken Websters PIC16C74 serial port multiplexer.
I'm trying to get Shane Tolmie's pic programmer working for my PIC16F873. My MAX232 is level shifting properly and I'm getting approx 16Mhz out of my oscillator which has its output connected to the CLKIN on the PIC. I have +5V on pin 20, and ground on pins 8,19. I have a 10k pullup resistor between +5V and pin 1. Yet I can't get the PIC downloader by Petr Kolomaznik or any other software to recognize the hardware. I don't know what to check next??
Archive:
Code:
This is the code to actually enter the code into mcu via USART , it will only accept the code unless & until u only press capital 'S'. Without using any Interrupt , its a pooling type code;-------------------------------------------------------------------------------------- USART_REC BANKSEL PIR1 btfss PIR1,RCIF ; Test for received data flag GOTO USART_REC_returns BTFSC RCSTA,OERR goto overerror ; check for over run error BTFSC RCSTA,FERR GOTO frameerror ; CHECK FOR FRAMING ERROR movf RCREG,W ; Store data in W MOVWF HAULT_KEY goto HAULT_DECIDE overerror bcf rcsta,cren ;pulse cren off... movf rcreg,w ;flush fifo movf rcreg,w ; all three elements. movf rcreg,w bsf rcsta,cren ;turn cren back on. ;this pulsing of cren ;will clear the oerr flag. ;enable interrupts. goto USART_REC ;try again... frameerror movf rcreg,w ;reading rcreg clears ferr flag. bsf intcon,gie ;enable interrupts. goto USART_REC ;try again... ;-------------------------------------------------------------------------------------------- HAULT_DECIDE ; CHECK IF THE KEY PRESSED ID 'S' OR RESUME NORMAL SEND DATA FUNCTION MOVLW 0X53 ; capital S SUBWF HAULT_KEY BTFSS STATUS,C goto USART_REC_returns BTFSS STATUS,Z goto USART_REC_returns continue to key enter routine
Comments:
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<bios.h> void main(void) { clrscr(); unsigned com1_status; unsigned com1_send; unsigned com1_rec; unsigned com1_init; int result, mask; com1_init = _bios_serialcom(_COM_INIT, 0, _COM_CHR8 | _COM_NOPARITY | _COM_STOP1 | _COM_1200); printf("Init status: 0x%4.4X\n", com1_init); com1_send = _bios_serialcom(_COM_SEND, 0, '*'); printf("Send status: 0x%4.4X\n", com1_send); mask = 0x6100; printf("%0X\n",42); com1_status = _bios_serialcom(_COM_STATUS, 0, 0); printf("COM1 status: 0x%4.4X\n", com1_status); /* wait until a character is ready */ do { com1_status = _bios_serialcom(_COM_STATUS, 0, 0); com1_status = com1_status & 0xFF00; if( kbhit() ) { if(getch()==26) break; } } while( (mask & com1_status) == 0 ); /* get a character */ com1_rec = _bios_serialcom(_COM_RECEIVE, 0, 0); printf("Read status: 0x%4.4X\n", com1_rec); /* print the character we just received */ result = com1_rec & 0x00FF; printf("Character: 0x%2.2X = %c\n", result, (char)result); getch(); }
there is a lot reference to PICUART.ASM example as most commented and tested... well, it looks to me that the connection/cable diagram inside this file is messed up, signals directions and pin numbers for DTR DST CTS RTS pins are WRONG :-(+
file: /Techref/microchip/rs232.htm, 19KB, , updated: 2016/12/1 16:09, local time: 2024/12/26 16:08,
18.226.248.17:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://sxlist.com/TECHREF/microchip/rs232.htm"> PIC RS232 IO</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.