Second Program Port

How to use the Second Programming Port on a PIC.

As I was working on my XLP project with the PIC24F16KA102 I thought it would be nice to be able to set an ID and a few other parameters after programming the code in it.  I needed to access one of the serial ports.  I looked at the datasheet and found the pins for the second UART.  The first UART is being used to run the radio so, I thought I couldn’t use that.  The problem with the second UART is it shares pins with the programming/debug port (PGD1 is U2TX and PGC1 is U2RX).  This is good news bad news.  I thought maybe I can use the same header to both program the part and enter the parameters.

I wrote some routines to drive the second UART port but as you would guess they didn’t work.  I wanted to debug them but with the pins conflicting on the first programming/debug port I couldn’t do that or could I.  The PIC24F16KA102 has a second programming/debug port.  I wondered how to activate that.  I wired up the second programming/debug port and thought maybe the part would look at the programming ports as it booted up to see which one was active.  That didn’t work.  I did some googling and found that you have to configure the part to use the second programming/debug port using the configuration bits.  In the FICD configuration register are two bits (bits 1-0) which define which programming/debug port to use.  The default for these bits is the first programming/debug port which makes sense.  I used the first programming/debug port to change these bits to the second programming/debug port.  Once I did that I was able to go to the second programming/debug port and it actually worked.

I made my changes to the second UART routines using the debugger to get it to work.  The problem was the baud rate.  It was hard coded and wasn’t using the calculations.  Once I put in the calculated baud rate everything started to work.  Boy, how simple can it get.  I’m glad it was that easy.  Now with the second port working I wanted to test my theory about using the same connector to program the firmware in the chip then put the parameters in the chip using the second UART port.

I have pictures of the Pogo Pin connector I made to program the temperature sensor here.  I decided I needed another Pogo Pin connector for the second UART.  Here it is.

Serial Programmer Top

Here is the UART Adapter from the top

 

You can see the Pogo pins and the connector for the USB to serial cable I used.

Serial Programmer Side

UART Adapter Side View

 

This is a little better view of the Pogo Pins.

Serial Programmer Wiring

UART Adapter Bottom View

 

Here you can see the wiring.  I needed three wires to interface to the second UART.  I needed GND, U2TX, and U2RX.  This allows me to send commands to the microcontroller and receive responses from the microcontroller.  This did work.  The only problem is holding it on the board with one hand and typing the commands with the other.  It became a little difficult.  I have thought about this problem and have come to the conclusion that I need an edge connector to make this connection rather than the Pogo pins as cool as the Pogo pins are.

Hope this helps.