|
|
View previous topic :: View next topic |
Author |
Message |
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
can h/w uart be configured to only use tx? |
Posted: Tue Jun 11, 2019 5:15 am |
|
|
Hi Folks,
I've got a product I designed a couple of years ago, that I now need to design an expansion board for. I've only got a limited number of pins on the expansion port.
I'm using a PIC24FJ256GA106-I/PT, on compiler 5.085.
On this expansion board - I have some SPI peripherals which are read only (ie I don't require MOSI / SDO).
At the moment, I have had to assign the complete SPI port as so:
Code: |
/* SECOND SPI BUS TO COMMUNICATE WITH THE TEMPERATURE SENSORS V0.22 */
#pin_select SCK2OUT=PIN_B14
#pin_select SDI2=PIN_F6 /* INPUT ONLY */
#pin_select SDO2=PIN_B15
#use spi(MASTER, SPI2, MODE=0, BITS=8, stream=SPI_PORT2, BAUD=100000)
|
However doing this means that I have one pin on my expansion port that I don't actually need (SDO).
In an ideal world - I could use PIN_B15 as a transmit pin for another UART which would then allow me to get a bit more debug out of the unit. At the moment I am having to use a serial port that would be better served doing something else.
So... the fundamental question is:
Can I allocate a hardware SPI port using PPS that doesn't have an SDO pin assigned?
Likewise - can I allocate a hardware UART, that only has a transmit pin and not a receive?
If the worse comes to the worse, I can move the two unwanted pins onto a second expansion port that I'm not yet using - but this still means I have two pins on my processor that I don't physically need for my design.
Any thoughts?
Thanks in advance
James |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Jun 11, 2019 6:25 am |
|
|
On a PIC18, no. However on a PIC24, potentially yes.
On the PIC18 SPI, the data being clocked 'in', is performed _when_ the data
is clocked 'out'. So what you are wanting (RX only) can't be done without
an output pin. However on the PIC24, it can potentially exist.
The key is the bit DISSDO, in SPIxCON1, which says to disable the
SDO bit. You have to 'cheat' and enable this after booting, which means the
pin will 'momentarily' be used by the SPI, but you can then get it back. So:
Code: |
#PIN_SELECT SDI1=PIN_B0
#PIN_SELECT SDO1=PIN_B2 //Only temporarily used
#pin_SELECT SCK1OUT=PIN_B1
#USE SPI(SPI1, MASTER, MODE=0)
#WORD SPI1CON1=GETENV("SFR:SPI1CON1")
#BIT DISSDO=SPI1CON1.11
void main()
{
//Now need to enable DISSDO, and remap SDO1 for normal use
DISSDO=TRUE;
PIN_SELECT("NULL",PIN_B2);
//PIN B2, should now be available for normal use...
while(TRUE)
{
//User Code
}
}
|
With this done the pin becomes available for normal use again (I hope...).
Not sure if this will work, but potentially it should....
Your thread name is 'wrong', since you refer to the hardware UART, but are
using the SPI. |
|
|
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Tue Jun 11, 2019 6:31 am |
|
|
Thanks - I will try it.
However I need to do the same for the UART as well, as I want TX only. Can this be achieved using something similar
James |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Jun 11, 2019 6:41 am |
|
|
Yes. On the UART, the bit is UTXEN. On a non PPS UART, simply disabling
this is all that is needed (has been covered here before). However on the
PPS UART, you will have to cheat the pin in the same way, since otherwise
once PPS is enabled, it locks the pin from being used for normal port I/O. |
|
|
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Tue Jun 11, 2019 7:13 am |
|
|
Thanks - I will give it a go once my board is built, and report back.
Cheers
James |
|
|
JamesW
Joined: 23 Apr 2007 Posts: 91 Location: Rochester, England
|
|
Posted: Tue Jun 11, 2019 7:17 am |
|
|
In fact I have a couple more questions, firstly it's the receive pin of the UART that I want to disable not the transmit - is there a bit to disable the UART RX PIN.
The pin I want to un-select, is the SDO which I then want to re-assign to the TX of the UART. However if I define the PIN_SELECT for both TX and SDO - the compiler complains.
Is there a way to re-define pin select, once it's been "un-selected" in main?
Cheers
James |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Tue Jun 11, 2019 7:34 am |
|
|
As I show, you can remap select settings 'in code'. The key thing is to set them
up once before the peripheral is configured, and after this you are free to
remap the peripherals at run time (remember though you must have the
fuse to allow PPS to be remapped).
If you look at the thread at the top of the forum, I show remapping
being done, and the best was to sequence the unlock/lock controls for this.
No there is no option to enable the UART, and disable the receiver. There
is a UART enable, and a TXEN, but no RXEN. It is not something the PIC
supports. It is unusual to want this, since RX is the harder one to do
in software, while TX works well using a software UART.
I don't know what would happen if you mapped the input to null with the
receive still enabled. It might well lead to data being continuously received. |
|
|
|
|
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
|