|
|
View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 363
|
uart 12F1840 |
Posted: Thu Jan 10, 2019 5:48 am |
|
|
Hello,
I want to know can i set uart tx line to be "float_high"? I have another hardware that "tx line" blocking it?
Example Code:
Code: |
#include <12F1840.h>
#device *=16
#device WRITE_EEPROM = NOINT
#fuses INTRC_IO,PROTECT,MCLR,PUT,BROWNOUT,NOWDT,CPD
#use delay(clock=32MHz)
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5, errors) |
Thanks for Attention! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Thu Jan 10, 2019 6:42 am |
|
|
Just disable the UART.
FLOAT_HIGH, is really only available for a software UART. A few of the
DsPIC's also support open collector drive to give this, but the standard
UART does not.
So just use:
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5, errors, NOINIT)
Then when you want to use the uart, use:
setup_UART(TRUE);
which will turn the UART on.
Then send your data, and disable after transmission with
setup_UART(FALSE);
However the lines will still 'clash' if the other UART is actually driving the
line at the same time.
You can get open collector drive by 'cheating' a little. Setup two streams:
Code: |
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5, errors, STREAM=RX)
#use rs232(baud=9600, xmit=PIN_A4, errors, STREAM=TX, FLOAT_HIGH)
//Then disable the hardware UART transmit with
#BIT (TXEN=GETENV("BIT:TXEN")
TXEN=FALSE;
//Now the hardware RX will be still running, but the transmit stream will
//be using a software UART and support 'FLOAT_HIGH'.
//transmit with:
fputc(TX,char_to_send);
//receive with
receive_char=fgetc(RX);
|
This will then give proper 'open collector' drive on the TX line. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 363
|
|
Posted: Thu Jan 10, 2019 9:02 am |
|
|
Hi mr."Ttelmah",
Because I have to use "#int_rda" second option will do my job, but for SW_UART may have to add oprion "FORCE_SW" because compiler gave me error *** Error 100 "Main.c" Line 15(5,67): USE parameter value is out of range H/W USART can not float?
Also this is not valid:
//Then disable the hardware UART transmit with
#BIT TXEN=GETENV("BIT:TXEN")
TXEN=FALSE; |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Thu Jan 10, 2019 9:10 am |
|
|
As I said the hardware UART cannot float except on a few DsPIC's.
Er. The bit should be called TXEN.
You do understand that the TXEN=FALSE; needs to actually be in the code,
not in the stuff outside the actual code. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 363
|
|
Posted: Thu Jan 10, 2019 9:29 am |
|
|
Compiler Ver. 5.075
Test Example:
Code: |
#include <12F1840.h>
#device *=16
#fuses INTRC_IO,NOPROTECT,MCLR,PUT,BROWNOUT,NOWDT,CPD
#use delay(clock=32MHz)
#use rs232(baud=9600, xmit=PIN_A4, rcv=PIN_A5, errors, STREAM=RX)
#use rs232(baud=9600, xmit=PIN_A4, errors, STREAM=TX, FLOAT_HIGH)
//Then disable the hardware UART transmit with
#BIT (TXEN=GETENV("BIT:TXEN")
TXEN=FALSE;
void main(void){
char c;
while(1){
c = fgetc(RX);
fputc(c, TX);
}
} |
Errors:
Compiling .......
*** Error 100 "main.c" Line 9(5,66): USE parameter value is out of range H/W USART can not float
*** Error 28 "main.c" Line 12(6,7): Expecting an identifier
*** Error 43 "main.c" Line 12(11,12): Expecting a declaration
*** Error 43 "main.c" Line 12(29,30): Expecting a declaration
*** Error 43 "main.c" Line 12(0,1): Expecting a declaration
*** Error 48 "main.c" Line 14(5,9): Expecting a (
*** Error 43 "main.c" Line 14(10,16): Expecting a declaration
*** Error 43 "main.c" Line 14(15,16): Expecting a declaration
8 Errors, 0 Warnings.
Build Failed. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Thu Jan 10, 2019 9:54 am |
|
|
According to the datasheet, that PIC has pin selectable feature. I'd guess you NEED to do the 'pin selecting' first, before trying to use the HWUART ??
It probably defaults to RA0/1 NOT RA4/5.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Thu Jan 10, 2019 11:12 am |
|
|
Key is though that the TXEN=FALSE; is a code line. Not something that
can be stuck outside the code. It needs to be in the actual program.
Code doesn't get executed unless it is in the actual program.... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Thu Jan 10, 2019 1:31 pm |
|
|
The 12F1840, does not have PPS on the UART. Just has relocation on a
couple of the other peripherals. Some comments inline:
Code: |
#include <12F1840.h>
#device *=16
#fuses INTRC_IO,NOPROTECT,MCLR,PUT,BROWNOUT,NOWDT
//don't use protection fuses when developing code. Doing so wastes
//lives on the flash memory
#use delay(INTERNAL=32MHz)
#use rs232(baud=9600, UART1, errors, STREAM=RX)
//ensures hardware is selected
#use rs232(baud=9600, xmit=PIN_A4, errors, FORCE_SW, STREAM=TX, FLOAT_HIGH)
//Hardware should not be selected with only TX selected, but make sure
//Then disable the hardware UART transmit with
#BIT (TXEN=GETENV("BIT:TXEN")
void main(void){
char c;
TXEN=FALSE; //Instruction to disable UART TX
while(1){
c = fgetc(RX);
fputc(c, TX);
}
}
|
|
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Thu Jan 10, 2019 1:42 pm |
|
|
kmp84 wrote: |
Code: | #BIT (TXEN=GETENV("BIT:TXEN")
|
|
You're missing one closing parenthesis: ) |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Thu Jan 10, 2019 1:43 pm |
|
|
well OK... it's controlled by the APFCON register, but to me it's still a 'pin selectable' option... YOU have to tell the PIC what pin does which function.
I'm pretty sure the defaults are RA0/1, though I can't seem to find that in the datasheet easily ! time passs, I'm back... chapter 12 Alternate pin functions...register 12-1, whew..man some things are a struggle at my age...
It is there though.
What I can't know is IF the compiler will edit the APFCON register based on the #USR RS232(...options...)
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Thu Jan 10, 2019 2:10 pm |
|
|
I didn't have the opening bracket in my original post. Seems to have
been added.
APFCON, doesn't use PPS. It defaults to one pin set, and you can change
what pin is used by directly accessing this register. Unlike PPS, CCS just
assumes the default pins unless you change this.
You use APFCON, as shown here:
<https://www.ccsinfo.com/forum/viewtopic.php?p=149502>
The pins being used here are the default ones for the UART. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 363
|
|
Posted: Fri Jan 11, 2019 1:30 am |
|
|
Hi All,
This is simple test program which also does not work. (;
Code: |
#include <12F1840.h>
#device *=16
#fuses INTRC_IO,NOPROTECT,MCLR,PUT,BROWNOUT,NOWDT
//don't use protection fuses when developing code. Doing so wastes
//lives on the flash memory
#use delay(INTERNAL=32MHz)
#use rs232(baud=9600, UART1, errors, STREAM=RX)
//ensures hardware is selected
#use rs232(baud=9600, xmit=PIN_A4, FORCE_SW, STREAM=TX, FLOAT_HIGH)
//Hardware should not be selected with only TX selected, but make sure
//Then disable the hardware UART transmit with
#BIT TXEN=GETENV("BIT:TXEN")
int1 FL = FALSE;
char c;
#int_rda
void Serial_ISR(void){
c = fgetc(RX);
FL = TRUE;
}
void main(void){
delay_ms(100);
TXEN=FALSE; //Instruction to disable UART TX
fprintf(TX,"\r\n SW-UART Test.");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE){
if(FL){
fputc(c, TX);
FL = FALSE;
}
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Fri Jan 11, 2019 2:17 am |
|
|
You do realise that driving it 'open collector', requires there the be a pull-up
resistor on the TX line, or nothing will be generated?.
It is possible that the FLOAT_HIGH code is faulty. It's a feature that I doubt
if anyone has actually used on the 12F1840 before, so it could easily have
a bug. Make sure you have a pull-up, simplify to just the FLOAT_HIGH test:
Code: |
#include <12F1840.h>
#device *=16
#fuses INTRC_IO,NOPROTECT,MCLR,PUT,BROWNOUT,NOWDT
#use delay(INTERNAL=32MHz)
#use rs232(baud=9600, xmit=PIN_A4, FORCE_SW, STREAM=TX, FLOAT_HIGH)
void main(void){
delay_ms(100);
fprintf(TX,"\r\n SW-UART Test.");
while(TRUE)
;
}
|
If this doesn't work, you need to speak to CCS. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9269 Location: Greensville,Ontario
|
|
Posted: Fri Jan 11, 2019 7:22 am |
|
|
I've gone back to the original post as I thought he wanted to disable the TX pin as it was used for some other purpose..IE a status LED ?
" I have another hardware that "tx line" blocking it"
so now I'm confused, as whatever the 'hardware' is on the TX line WILL receive whatever data he transmits to the PC. If it's an LED , it'll flash.
Or am I reading this all wrong ?
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19587
|
|
Posted: Fri Jan 11, 2019 8:13 am |
|
|
I'm assuming they are both TX outputs.
Obviously the receiving device will see the data from both units.
However the obvious 'caveat', if if the other device is driving the line
high (is not itself an 'open collector' drive device), then this device
can't operate the line.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|