News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Possible to use UART tx pin only?

Started by david, Oct 26, 2023, 10:51 AM

Previous topic - Next topic

david

Hi All,
I'm a bit confused about the wording regarding the use of the rx and tx UART pins.   
RCSTA.7 implies the rx and tx ports are enabled as a pair (I think) whereas the blurb in the introduction appears to say that tx or rx functions can be individually excluded and the unused UART pin can become a GPIO. 
I only need the tx function and would rather have the rx pin assigned as a GPIO but I'm not sure that is possible.  If I had the chip I would try it out but I think this is common to anything with a UART module so I may have something that could confirm things.

Cheers,
David

trastikata

Hi David,

Clear the  SREN and CREN and you should be good to go.

david

Many thanks.
I should have seen CREN - it's quite specific.  SREN I don't follow - it says "Don't care" for asynch mode.
I have a couple of chips on order and mean time I will try it on a similar device.

I should perhaps mention that this is perhaps a misguided approach to try to send a 5 digit number from one PIC to another during variable speed stepper motor pulses.  The fastest speed is 800uS between pulses so I don't have a lot of time to transfer the data but 115200 baud should squeak in. 
I appreciate your kind assistance.

Cheers,
David 

trastikata

Quote from: david on Oct 26, 2023, 12:07 PMI should have seen CREN - it's quite specific.  SREN I don't follow - it says "Don't care" for asynch mode.

I spoke by memory, didn't check the datasheet.

Are both PICs on the same board?

david

Ha!  I used to have a memory once....
Yes both PICs will be close to each other but not necessarily on the same board - effectively an optional extra to cater for "feature creep".
The first PIC is quite busy and is generating the stepper pulses in real time with a lot of housekeeping going on in between pulses.  I now need to get a count out for display purposes without upsetting the stepper pulses.  That's about when I realised there wasn't a lot of time to spare and that any count process needed to be constant in timing regardless of the count value.  So the grand plan was to send the fixed value count (always 5 digits) between stepper pulses to the 2nd PIC which would do the required maths and update a display say at 2Hz.  I had wondered about an interrupt but I think missing a couple of stepper pulses every half second would be quite audible.

David

trastikata

Quote from: david on Oct 26, 2023, 10:17 PMYes both PICs will be close to each other but not necessarily on the same board

Then if not at the same board, at 115200 baud, capacitance in lines and noise might play a role in the wave forms.

But I've never tried 115200 UART over a cable, so more experienced people could give a better advise if possible or not.

david

Actually I'm not too worried about the baud rate and have never run in to problems during my working days or now for hobby work.  We used to flash SiRF GPS chips at 256000 baud off a PC using ribbon cable but the key is a lowish source resistance. 
The 2nd PIC in my breadboard lash-up is running at 115200 and talking to a Bluetooth module (at 115200) via a ribbon cable without issue.
Please correct me if I'm wrong but 115200 baud is about equivalent to (worst case) a square wave of 57600Hz.  If the PIC source resistance is say 150R then you will only get slight rounding with a 1nF of stray capacitance.  Almost too good to be true.

David

trastikata

Hi David,

I thought there might be some over or undershoot from the pin drivers, but as I said  my speculations in this case are not based on past experience.

david

That's certainly possible if there's inductance involved.   Adding 200nH (~200mm wire) in series with the 150R in the previous model with a 10pF output load did show damped ringing and overshoot.  Increasing output load capacitance to 100pF cleaned up the output (with slower rise/fall times) and the ringing at the resistor increased. i.e. reflected back to the signal source.
I will certainly keep an eye on this.  I'm in awe at how this mess on my bench has performed so well.

Cheers,
David 

tumbleweed

As long as the ringing/overshoot is < 1/2 of the bit time then the uart should have no issues (other than the receiver not liking the signal exceeding the input pin voltage specs).

That's one of the advantages of an async interface vs a sync interface like SPI where you have to worry about the ringing generating extra clock pulses.


top204

#10
With a device that has PPS (Peripheral Pin Select), also make sure you set the pin not being used for the USART to digital mode, because the compiler automatically sets up the PPS for both RX and TX pins used when the hardware USART serial commands are used in a program.

I've never tried just using a single pin when the USART is enabled, and on the older devices, it was not possible, but looking at the datasheets for the more recent devices, it does have enable and disable for both the RX and TX of the USART peripheral, so it "should" be possible. However, with microchip, one can never be sure. :-)

david

Hello Les,
Many thanks for that extra information.
The device I'm hoping to use is a 16F1824 but I'm not using any of the compiler's "Declares" and instead just defining the UART registers as follows.

APFCON0=%00000000     'UART tx on RC4
SPBRGL=34             '115200=34     
SPBRGH=0              '115200=0     
RCSTA=%10000000       'bit 4 disables receive
TXSTA=%00100100       'BRGH=1
BAUDCON=%01001000     'output inverted -use FTDI dongle

This is as yet untested but as trastikata indicated, bit 4 of the RCSTA register should toggle the rx function on and off and hopefully allow its use as a GPIO if unused.

Cheers,
David

david

I just checked and a 12F1840 has exactly the same UART registers so I modified some existing code and I can now get 115200 baud data on pin 7 (UART tx)and a digital timing flag output on pin 6 which is usually the UART rx.  Nice to know.

David