Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 3 months ago.
Reallocating the UART pins
Hello
I have a situation where i need 4 UARTs wtih LPC824. However two of them are mutually exclusive. So I am was hoping there was a way to change pin allocations to use 1 or the other based on time . To Try i did the following program. However it fails with "No UART Available"
<code> RawSerial serialPorts[3] = {RawSerial(USBTX,USBRX),RawSerial(P0_4,P0_0), RawSerial(P0_19,P0_18)};
DigitalOut dummy1(P0_6,1);
DigitalOut dummy2(P0_7,1);
while(1) {
First set of allocation
dummy1 = DigitalOut(P0_6,1);
dummy2 = DigitalOut(P0_7,1);
serialPorts[2] = RawSerial(P0_19,P0_18);
serialPorts[2].putc('1');
wait(7);
Second set of allocation
dummy1 = DigitalOut(P0_19,1);
dummy1 = DigitalOut(P0_18,1);
serialPorts[2] = RawSerial(P0_6,P0_7);
serialPorts[2].putc('2');
wait(7); }
</code>
2 Answers
8 years, 3 months ago.
Did you try deleting and creating the serial port object when you need to switch?
RawSerial *sharedPort = null; void switchToPortOne() { if (sharedPort) delete sharedPort; sharedPort = new RawSerial(P0_19,P0_18); } void switchToPortTwo() { if (sharedPort) delete sharedPort; sharedPort = new RawSerial(P0_6,P0_7); sharedPort->baud(9600); // etc for any non-default setup required. } main() { switchToPortOne(); sharedPort->putc('1'); switchToPortTwo(); sharedPort->putc('2'); }
I have no idea if this will work, it will be slow when switching but id does avoid two serial objects trying to use the same uart at the same time.
Oh and << >> rather than < > around to code tags to make them work ;-)
Andy Awesome. Looks like it worked
Pardon the basic question. I have an array. How will the syntax be? ex:
RawSerial serialPorts[3] = {RawSerial(P0_25,P0_26),RawSerial(USBTX,USBRX), RawSerial(P0_21,P0_22)}
Thanks for <<code>>
pointer. Have always wondered why it didnt work
When I tried to SWM pin allocation ,Strangely, the first sharedPort worked only once (in a loop) and then it would throw out garbage, The second shared port worked well.. Heres my code
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); LPC_SWM->PINASSIGN0 = 0xffffffffUL; LPC_SWM->PINASSIGN0 = 0xffff1213UL; LPC_SYSCON->SYSAHBCLKCTRL |= (0<<7);
8 years, 3 months ago.
Varying with your UART needs (speed; handshake lines, etc.), perhaps you could bit-bang out the UART model(s) that are required ? There are also SPI based UARTs from assorted silicon vendors but often these SPI UARTs cost more than the CPU with the requested resources of multiple UARTs.
Reference reading: https://developer.mbed.org/forum/mbed/topic/2092/