Serial on pins p26 and p25 possible?

12 May 2010 . Edited: 12 May 2010

Hey guys im running short on serial pins, and wondering if p26(tx),p25(rx) can be used as well.

 

P26 -> P2.0/PWM1.1/TXD1/TRACECLK

P25 -> P2.1/PWM1.2/RXD1


As I am using p13 -> P0.15/TXD1/SCK0/SCK with SPI

 

Cheers Jase

12 May 2010

Hi Jason,

Yes, as well as being able to declare interfaces using the DIP pin numbers which are marked on the pinout card the the purpose you are using, e.g.

Serial uart(p13,p14);

Or you can do as you say and use DIP pins that are not marked for the purpose, e.g.

Serial uart(p26,p25);

In this case, note that you are actually using UART1 of the LPC1768, which is already on p13,p14. Using p26,p25 is just an alternate mapping, rather than an extra UART.

This is the same with LED1-4, which can also be used as PwmOut (oh yeah, dim those LED's Knight Rider Style :-)

The last thing to note is that you can also construct objects using the LPC port/pin numbers, so for the example you gave you could equally do this :

Serial uart (P2_0,P2_1);

This isnt that much use when you can already just use the DIP pin numbers, but if you were to move your design to a bare LPC1768 on your own PCB, it means that you can still use the library objects on pins that are not supported by the DIP form factor of the mbed.

Hope that helps,

Chris

12 May 2010

Thanks Chris, great answer. That is just what I was hoping to hear!

 

13 May 2010

Along the same lines can I configure another SPI port?  I am currently running a parallel LCD display on P21-26 and P30.   My SPI ports are used for an SD card and accelerometer.  I would like to swtich from the parallel LCD to the mobile LCD (SPI).

Is it really so simple as reprogramming a pin even though they indicated output has a different default function?

 

13 May 2010 . Edited: 13 May 2010

Hi James,

I think the answer to your question is yes, but not quite sure exactly if I read it correctly. But what you may be after is this...

SPI is naturally meant to be a shard bus, so the mbed libraries actually allow you to have multiple SPI interfaces using the same physical interface; you then use a chip select to control which device you talk to. For example:

SPI dev1(p5, p6, p7);
DigitalOut cs1(p8);

SPI dev2(p5, p6, p7);
DigitalOut cs2(p9);

// disable both devices
cs1 = 1;
cs2 = 1;

// write to device 1
cs1 = 0;
dev1.write(0xFF);
cs1 = 1;

// write to dev 2
cs2 = 0;
dev2.write(0xFF)
cs2 = 1;

If you are using a library that uses a SPI and CS, assuming it correctly enables and disables them then it'll work fine. e.g you could connect multiple MobileLCDs as long as each has a seperate CS pin assigned.

You can do the same with I2C too, and no ned for a seperate CS as they use address to identify the different slaves.

Hope this gives you what you need.

Simon

14 May 2010

James Novak wrote:

Along the same lines can I configure another SPI port?  I am currently running a parallel LCD display on P21-26 and P30.   My SPI ports are used for an SD card and accelerometer.  I would like to swtich from the parallel LCD to the mobile LCD (SPI).

Is it really so simple as reprogramming a pin even though they indicated output has a different default function?

 

Simon, don't devices on the same SPI bus. Need to be running at the same frequency?

14 May 2010 . Edited: 14 May 2010

Hi Jason,

Jason Engelman wrote:
don't devices on the same SPI bus. Need to be running at the same frequency?

As only one device is selected at a time, I made it so they can run at different frequencies. So in the above example, you could do the following setup:

dev1.mode(8, 0);  // 8-bit word
dev1.frequency(200000); // 200kHz
dev2.mode(9, 2);  // 9-bit word
dev2.frequency(4000000); // 4MHz

then whenever you use whichever device, the appropriate frequency and mode would be used. My initial use case that highlighted this was an LCD and touchscreen on the same bus; they used different bit format, and I wanted to drive the LCD very fast but the touchscreen controller had a speed limit.

Simon

09 Jun 2010 . Edited: 09 Jun 2010

Chris/Simon,

Small problem, I am trying to use CAN on P0_21 and P0_22 or P2_7 and P2_8. When I use the following code, it seems to get stuck when initializing i.e

 

 

CAN can1(P0_21,P0_22); // CAN can1(P2_7,P2_8); doesnt work either

 


Is there some setup code I am missing?

10 Jun 2010 . Edited: 10 Jun 2010

Does CAN require the 32mhz RTC xtal to be connected?

10 Jun 2010

I can confirm that the P0_21,P0_22 and P2_7,P2_8 problem is a bug. I'm working on CAN currently, so this should be fixed in the next release.

The CAN should not require the RTC crystal, it comes off of the system clock.

10 Jun 2010

great thanks jon!