|
|
View previous topic :: View next topic |
Author |
Message |
srtgumbee
Joined: 15 Dec 2018 Posts: 5
|
I/O Port masking while using UART(s)? |
Posted: Wed Jun 10, 2020 5:43 pm |
|
|
Hi there,
Short question:
If I'm using a hardware UART while Reading/Writing to ports using LATx, would the LATx reflect data on a TXD pin and could I corrupt data on that same TXD pin by writing to the entire LATx?
Longer story:
I have 9 Leds that are connected to the pins of a pic through current limiting resistors. Current per Led is less than 3mA and Leds are spread between 4 ports. I'm required to dim them and are doing so through PWM on a timer interrupt.
Pic is a 44pin PIC18F46K40, CCS compiler is 5.083.
After setting the Leds on/off in main I always save LATx values into global temp eg:
Code: |
void save_port_v()
{
TEMP_LATA = LATA; // save original LAT setting
TEMP_LATB = LATB; // save original LAT setting
TEMP_LATC = LATC; // save original LAT setting
TEMP_LATD = LATD; // save original LAT setting
TEMP_LATE = LATE; // save original LAT setting
}
|
Then in a timer interrupt I apply an 'off' mask for a certain amount of time to only those I/O that have Leds.
Code: |
LATA = LATA & PORT_A_OFF_MASK;
LATB = LATB & PORT_B_OFF_MASK;
LATC = LATC & PORT_C_OFF_MASK;
LATD = LATD & PORT_D_OFF_MASK;
LATE = LATE & PORT_E_OFF_MASK;
|
Using the same interrupt timer I then re-apply the original LATx values for the 'on' period of the led.
Code: |
LATA = TEMP_LATA;
LATB = TEMP_LATB;
LATC = TEMP_LATC;
LATD = TEMP_LATD;
LATE = TEMP_LATE;
|
The leds are running at approx 60hz duty.
I'm also running two hardware UARTs @9600baud and these both seem to be working fine.
Are these UART working by good luck? Or is this method fine? Is there a better way of doing this?
Many thanks |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Jun 11, 2020 10:09 am |
|
|
I would have to do a test with your particular part to be sure -- but last I remember, once you set the PPS, the LAT output does not effect the output of your UART TX line.
You could theoretically, still look at the RX line input if you wanted... but the output LAT is blocked.
So you could write to the entire LAT for that port and you wouldn't see the effects on the UART TX line.
Of course - it's always a good idea to try it to confirm.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19590
|
|
Posted: Fri Jun 12, 2020 12:06 am |
|
|
On most newer PIC's, port functions override the use as a normal I/O pin.
So TRIS doesn't matter.
In the data sheet for this PIC:
Quote: |
Most port pins share functions with device peripherals, both analog and
digital. In general, when a peripheral is enabled on a port pin, that pin
cannot be used as a general purpose output; however, the pin
can still be read.
|
So once the peripheral is enabled on a port pin the TRIS no longer
matters.
In the pin diagram, it shows the peripheral select feeding into the
TRIS control for the pin.
This differs for older chips where the setup for using (say) the UART,
tells you to set the TRIS to output for the TX pin and input for the RX
pin.
So if we look at the PIC18F452, the data sheet says:
Quote: |
In order to configure pins RC6/TX/CK and RC7/RX/DT
as the Universal Synchronous Asynchronous Receiver
Transmitter:
• bit SPEN (RCSTA<7>) must be set (= 1), and
• bits TRISC<7:6> must be cleared (= 0).
|
While on the chip involved here, it instead says:
Quote: |
The EUSART control logic will control the
data direction drivers automatically.
|
|
|
|
|
|
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
|