Esempio n. 1
0
void config_uart2(void){
	CloseUART2();
	unsigned int UMODEvalue, U2STAvalue, config;
	
	UMODEvalue = UART_EN &
		UART_DIS_WAKE &
		UART_DIS_LOOPBACK &
		UART_DIS_ABAUD &
		UART_IDLE_CON &
		UART_NO_PAR_8BIT &
		UART_1STOPBIT;

	U2STAvalue = UART_INT_TX &
		UART_TX_PIN_NORMAL &
		UART_TX_ENABLE &
		UART_INT_RX_BUF_FUL &
		UART_RX_OVERRUN_CLEAR &
		UART_ADR_DETECT_DIS;

	config = UART_TX_INT_DIS &
		UART_RX_INT_EN &
		UART_INT_RX_BUF_FUL &
		UART_RX_INT_PR4;

	__C30_UART = 2;

	ConfigIntUART2(config);
	OpenUART2(UMODEvalue, U2STAvalue, (int) ((double) ((FCY/16.)*1000/BAUD_RATE-1) + 0.5));

	Serial.receiveddata = Serial.rbuf;
}
Esempio n. 2
0
void serio_init(uckernel_task handler)
{
	serio_set_rx_handler(handler);

	new_queue(&tx_queue, tx_queue_data, QUEUE_SIZE, sizeof(uint8_t));
	new_queue(&rx_queue, rx_queue_data, QUEUE_SIZE, sizeof(uint8_t));

	iPPSInput(IN_FN_PPS_U2RX, IN_PIN_PPS_RP10);
	iPPSInput(IN_FN_PPS_U2CTS, IN_PIN_PPS_RPI32);
	iPPSOutput(OUT_PIN_PPS_RP17, OUT_FN_PPS_U2TX);
	iPPSOutput(OUT_PIN_PPS_RP31, OUT_FN_PPS_U2RTS);
	CloseUART2();

	/*Enable UART intruupts*/
	ConfigIntUART2(UART_RX_INT_EN | UART_RX_INT_PR6 | UART_TX_INT_EN | UART_TX_INT_PR6 | UART_INT_TX_BUF_EMPTY);
	/*UART initialized to 9600 baudrate @BRGH=0, 8bit,no parity and 1 stopbit*/
	OpenUART2(UART_EN | UART_BRGH_FOUR, UART_TX_ENABLE, 34);
	serio_initialized = true;
}
Esempio n. 3
0
/**
 * Initialization function for the UART2 peripheral. Should be called in initialization code for the
 * model. This function configures the UART for whatever baud rate is specified. It also configures
 * two circular buffers for transmission and reception.
 *
 * This function can be called again to re-initialize the UART. This clears all relevant registers
 * and reinitializes values to 0.
 */
void Uart2Init(uint16_t brgRegister)
{
	// First initialize the necessary circular buffers.
	CB_Init(&uart2RxBuffer, u2RxBuf, sizeof(u2RxBuf));
	CB_Init(&uart2TxBuffer, u2TxBuf, sizeof(u2TxBuf));

	// If the UART was already opened, close it first. This should also clear the transmit/receive
	// buffers so we won't have left-over data around when we re-initialize, if we are.
	CloseUART2();

	// Configure and open the port.
	OpenUART2(UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & UART_MODE_FLOW & UART_UEN_00 &
		UART_EN_WAKE & UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT & UART_UXRX_IDLE_ONE &
		UART_BRGH_SIXTEEN & UART_1STOPBIT,
		UART_INT_TX_LAST_CH & UART_IrDA_POL_INV_ZERO & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE &
		UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR,
		brgRegister
		);

	// Setup interrupts for proper UART communication. Enable both TX and RX interrupts at
	// priority level 6 (arbitrary).
	ConfigIntUART2(UART_RX_INT_EN & UART_RX_INT_PR6 & UART_TX_INT_EN & UART_TX_INT_PR6);
}
Esempio n. 4
0
void gpsSetup(void)
{
    /* Configure Port Direction */
    TRISBbits.TRISB8 = 0;   //  Turn RB8 into output for GPS EN
    TRISBbits.TRISB9 = 1;   //  Turn RB9 into input for GPS FIX
    TRISBbits.TRISB14 = 1;  //  Turn RB14 into input for GPS RX
    TRISBbits.TRISB15 = 0;  //  Turn RB15 into output for GPS TX
    TRISFbits.TRISF4 = 1;   //  Turn RF4 into input for GPS PPS

    /* Configure PPS pins for GPS */
    iPPSInput(IN_FN_PPS_U2RX,IN_PIN_PPS_RP14);      // Assign U2RX to pin RP14
    iPPSOutput(OUT_PIN_PPS_RP29,OUT_FN_PPS_U2TX);   // Assign U2TX to pin RP29

    /* Enable the GPS module */
    PORTB |= 0x0100;

    /* Close UART in case it's already open */
    CloseUART2();

    /*Enable UART Interface */

    ConfigIntUART2(UART_RX_INT_DIS | UART_RX_INT_PR6 | UART_TX_INT_DIS | UART_TX_INT_PR6);
    // Receive interrupt disabled
    // Priority RX interrupt 6
    // Transmit interrupt disabled
    // Priority TX interrupt 6

    OpenUART2(UART_EN, UART_TX_ENABLE, 25);
    // Module enable
    // Transmit enable
    // 9600 baud rate (@ 4 MHz internal clock)

    /* Initalize the Adafruit GPS libraries */
    common_init();

}
Esempio n. 5
0
int main(void)
{	
    // Bring all Outputs Low
    LATB = 0x0000;
    LATD = 0x0000;
    LATF = 0x0000;
    LATG = 0x0000;

    // Disable analog I/O on PORT B and G
    ANSB = 0x0000;
    ANSG = 0x0000;

    // Setup the GPS and USB UART
    usbSetup();
    gpsSetup();
    gsmSetup();
    sdSetup();

    // Clear and enable GSM and USB interrupts
    U1RX_Clear_Intr_Status_Bit;
    U3RX_Clear_Intr_Status_Bit;
    EnableIntU1RX;
    EnableIntU3RX;
    
    // Clear and enable GPS interrupt
//    U2RX_Clear_Intr_Status_Bit;
//    EnableIntU2RX;

    // Set up to echo GPS data
//    sendCommand(PMTK_SET_BAUD_9600);
//    DELAY_MS(100);
//    sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
//    sendCommand(PMTK_SET_NMEA_OUTPUT_OFF);    // Enable for log dump
//    DELAY_MS(100);
//    sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);      // Disable for log dump
//    DELAY_MS(100);

    // Start GPS data logger
//    startLOCUS();

    strToUSB("Starting SM5100B Communication...\n");

    // Loop Forever
    while(1)
    {
        blink(LED_GRN_P42);
        DELAY_MS(1000);

        // Print out logger info
//        displayLOCUSInfo();

    }

    // Disable Interrupts and close UART
    DisableIntU1RX;
    DisableIntU2RX;
    DisableIntU3RX;
    CloseUART1();
    CloseUART2();
    CloseUART3();
    
}