Permalink
Browse files

Found a bug in PPS support for input pins, fixed it. We now have prop…

…erly working UARTS (both 1 and 2) on PPS (tested).

Also added new #define macros for assigning peripherals to outputs and inputs.
  • Loading branch information...
EmbeddedMan committed Sep 15, 2012
1 parent 3fe7fcd commit 365d8766b1a1dbd1e61234bfa7970e83ab83ebd2
@@ -185,14 +185,11 @@ void HardwareSerial::begin(unsigned long baudRate)
/* Map the UART TX to the appropriate pin.
*/
- pps = ppsOutputRegister(pinTx);
- *pps = ppsOutputSelect(ppsTx);
+ ppsSwitchOutputPin(pinTx, ppsTx);
/* Map the UART RX to the appropriate pin.
*/
- pps = ppsInputRegister(ppsRx);
- *pps = ppsInputSelect(pinRx);
-
+ ppsSwitchInputPin(pinRx, ppsRx);
#endif
/* Compute the address of the interrupt priority control
@@ -324,26 +324,26 @@ typedef uint32_t p32_ppsin;
#define PPS_IN_INT2 (1 + _PPS_SET_C)
#define PPS_IN_INT3 (2 + _PPS_SET_B)
#define PPS_IN_INT4 (3 + _PPS_SET_A)
-#define PPS_IN_T2CK (4 + _PPS_SET_A)
-#define PPS_IN_T3CK (5 + _PPS_SET_B)
-#define PPS_IN_T4CK (6 + _PPS_SET_C)
-#define PPS_IN_T5CK (7 + _PPS_SET_D)
-#define PPS_IN_IC1 (8 + _PPS_SET_C)
-#define PPS_IN_IC2 (9 + _PPS_SET_D)
-#define PPS_IN_IC3 (10 + _PPS_SET_B)
-#define PPS_IN_IC4 (11 + _PPS_SET_A)
-#define PPS_IN_IC5 (12 + _PPS_SET_C)
-#define PPS_IN_OCFA (13 + _PPS_SET_D)
-#define PPS_IN_OCFB (14 + _PPS_SET_C)
-#define PPS_IN_U1RX (15 + _PPS_SET_C)
-#define PPS_IN_U1CTS (16 + _PPS_SET_B)
-#define PPS_IN_U2RX (17 + _PPS_SET_B)
-#define PPS_IN_U2CTS (18 + _PPS_SET_C)
-#define PPS_IN_SDI1 (19 + _PPS_SET_B)
-#define PPS_IN_SS1 (20 + _PPS_SET_A)
-#define PPS_IN_SDI2 (21 + _PPS_SET_C)
-#define PPS_IN_SS2 (22 + _PPS_SET_D)
-#define PPS_IN_REFCLKI (23 + _PPS_SET_A)
+#define PPS_IN_T2CK (5 + _PPS_SET_A)
+#define PPS_IN_T3CK (6 + _PPS_SET_B)
+#define PPS_IN_T4CK (7 + _PPS_SET_C)
+#define PPS_IN_T5CK (8 + _PPS_SET_D)
+#define PPS_IN_IC1 (9 + _PPS_SET_C)
+#define PPS_IN_IC2 (10 + _PPS_SET_D)
+#define PPS_IN_IC3 (11 + _PPS_SET_B)
+#define PPS_IN_IC4 (12 + _PPS_SET_A)
+#define PPS_IN_IC5 (13 + _PPS_SET_C)
+#define PPS_IN_OCFA (17 + _PPS_SET_D)
+#define PPS_IN_OCFB (18 + _PPS_SET_C)
+#define PPS_IN_U1RX (19 + _PPS_SET_C)
+#define PPS_IN_U1CTS (20 + _PPS_SET_B)
+#define PPS_IN_U2RX (21 + _PPS_SET_B)
+#define PPS_IN_U2CTS (22 + _PPS_SET_C)
+#define PPS_IN_SDI1 (31 + _PPS_SET_B)
+#define PPS_IN_SS1 (32 + _PPS_SET_A)
+#define PPS_IN_SDI2 (34 + _PPS_SET_C)
+#define PPS_IN_SS2 (35 + _PPS_SET_D)
+#define PPS_IN_REFCLKI (44 + _PPS_SET_A)
#define NUM_PPS_IN 24
@@ -172,6 +172,9 @@
#define ppsSetFromPin(P) ((digital_pin_to_pps_in_PGM[P] >> 4) & 0x000F)
#define ppsSetFromFunc(F) (((F) >> 8) & 0x000F)
#define ppsInputFromFunc(F) ((F) & 0x00FF)
+#define ppsSwitchOutputPin(Pin, Peripheral) *(ppsOutputRegister(Pin)) = ppsOutputSelect(Peripheral)
+#define ppsSwitchInputPin(Pin, Peripheral) *(ppsInputRegister(Peripheral)) = ppsInputSelect(Pin)
+
#define timerOCtoDigitalPin(P) (uint8_t)(output_compare_to_digital_pin_PGM[P])
#define timerOCtoOutputSelect(P) (uint8_t)(output_compare_to_pps_sel_PGM[P])
@@ -293,9 +293,9 @@ extern const uint8_t external_int_to_digital_pin_PGM[];
#define _SER0_IPL _UART1_IPL_IPC
#define _SER0_SPL _UART1_SPL_IPC
#define _SER0_TX_OUT PPS_OUT_U1TX
-#define _SER0_TX_PIN 5
+#define _SER0_TX_PIN 17
#define _SER0_RX_IN PPS_IN_U1RX
-#define _SER0_RX_PIN 6
+#define _SER0_RX_PIN 18
/* Serial port 1 uses UART2
*/

0 comments on commit 365d876

Please sign in to comment.