Exemplo 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;
}
Exemplo n.º 2
0
void UART2_Config(void){

    OpenUART2((
            UART_EN &                   //Enable UART Module
            UART_IDLE_CON &             //Work while idle
            UART_IrDA_DISABLE &         //Disable Infared decoder
            UART_MODE_SIMPLEX &         //UART Simplex mode (RTS pin)
            UART_UEN_00 &               //TX/RX pins configured all other latched
            UART_DIS_WAKE &             //Disable wake on Start bit
            UART_DIS_LOOPBACK &         //Disable loopback
            UART_DIS_ABAUD &            //Disable Auto Baud
            UART_UXRX_IDLE_ONE &        //Receive idle is 1
            UART_BRGH_SIXTEEN &         //16 clocks per bit period
            UART_NO_PAR_8BIT &          //No parity bit
            UART_1STOPBIT               //One stop bit
            ),
            (
            UART_INT_TX_LAST_CH &       //Interrupt when last character shifted out
            UART_IrDA_POL_INV_ZERO &    //IrDA encoded, UxTX Idel state is '0'
            UART_SYNC_BREAK_DISABLED &  //Sync break transmission disabled or completed
            UART_TX_ENABLE &            //Transmit enable
            UART_TX_BUF_NOT_FUL &       //Transmit buffer is not full
            UART_INT_RX_CHAR &          //Interrupt on every char received
            UART_ADR_DETECT_DIS &       //address detect disable
            UART_RX_OVERRUN_CLEAR       //Rx buffer Over run status bit clear
            ),
            (
            __BAUDUART2_ //Baud rate
            ));
    ConfigIntUART2(
                UART_RX_INT_EN &        //Receive interrupt enabled
                UART_RX_INT_PR2 &       //Priority RX interrupt 1
                UART_TX_INT_DIS &       //transmit interrupt disabled
                UART_TX_INT_PR1         //Priority TX interrupt 1
            );



#ifdef InvertU2RxTxBits
    U2STAbits.UTXINV = 0;
    U2MODEbits.URXINV = 0;
#endif

    //Set the tristate and map pins for Uart
    TRIS_U2TX;
    TRIS_U2RX;
    MAP_U2TX;
    MAP_U2RX;
}
Exemplo n.º 3
0
xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength )
{
unsigned short usBRG;

	/* Create the queues used by the com test task. */
	xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );
	xCharsForTx = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) );

	/* Configure the UART and interrupts. */
	usBRG = (unsigned short)(( (float)configPERIPHERAL_CLOCK_HZ / ( (float)16 * (float)ulWantedBaud ) ) - (float)0.5);
	OpenUART2( UART_EN, UART_RX_ENABLE | UART_TX_ENABLE | UART_INT_TX | UART_INT_RX_CHAR, usBRG );
	ConfigIntUART2( ( configKERNEL_INTERRUPT_PRIORITY + 1 ) | UART_INT_SUB_PR0 | UART_TX_INT_EN | UART_RX_INT_EN );

	xTxHasEnded = pdTRUE;

	/* Only a single port is implemented so we don't need to return anything. */
	return NULL;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
void uartInit() {
    /// UART2 for RS-232 w/PC @ 230400, 8bit, No parity, 1 stop bit
    unsigned int U2MODEvalue, U2STAvalue, U2BRGvalue;
    U2MODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE &
                  UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE &
                  UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE &
                  UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_2STOPBITS;
    U2STAvalue  = UART_INT_RX_CHAR & UART_SYNC_BREAK_DISABLED &
                  UART_TX_ENABLE & UART_ADR_DETECT_DIS &
                  UART_IrDA_POL_INV_ZERO; // If not, whole output inverted.
    U2BRGvalue  = 10; // Approximately 830kBaud

    OpenUART2(U2MODEvalue, U2STAvalue, U2BRGvalue);

    in_pkt_ = &(pkt_buf_0_);
    last_bldc_packet = &(pkt_buf_1_);
    last_bldc_packet_is_new = 0;

    ConfigIntUART2(UART_RX_INT_EN & UART_RX_INT_PR6);
}
//Initialize UART module and query skinproc tactile grid size
void tactileInit() {
    //unsigned char data[2] = {0};
    //radioSendData(0x3001, 0, CMD_TACTILE, 2, data, 0);
    if (TACTILEUART){
        /// UART2 for SkinProc, 1e5 Baud, 8bit, No parity, 1 stop bit
        unsigned int U2MODEvalue, U2STAvalue, U2BRGvalue;
        U2MODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE &
                      UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE &
                      UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE &
                      UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_1STOPBIT;
        U2STAvalue  = UART_INT_TX & UART_INT_RX_CHAR &UART_SYNC_BREAK_DISABLED &
                      UART_TX_ENABLE & UART_ADR_DETECT_DIS &
                      UART_IrDA_POL_INV_ZERO; // If not, whole output inverted.
        U2BRGvalue  = 86;//21; //9; // = (40e6 / (4 * 1e5)) - 1 so the baud rate = 100000
        //this value matches SkinProc

        // =3 for 2.5M Baud
        //U2BRGvalue  = 43; // =43 for 230500Baud (Fcy / ({16|4} * baudrate)) - 1
        //U2BRGvalue  = 86; // =86 for 115200 Baud
        //U2BRGvalue  = 1041; // =1041 for 9600 Baud

        OpenUART2(U2MODEvalue, U2STAvalue, U2BRGvalue);

        ConfigIntUART2(UART_TX_INT_EN & UART_TX_INT_PR4 & UART_RX_INT_EN & UART_RX_INT_PR4);
        //EnableIntU2TX;
        DisableIntU2TX;
        EnableIntU2RX;
    }

    tx_idx = TACTILE_TX_IDLE;
    rx_idx = TACTILE_RX_IDLE;

    rx_count = 0;
    TACTILE_ROWS = 0xFF;
    TACTILE_COLS = 0xFF;
    clearRXFlag();
    //checkFrameSize();
    max_buffer_length = LARGE_BUFFER;

}
Exemplo n.º 7
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);
}
Exemplo n.º 8
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();

}
Exemplo n.º 9
0
void uartInit(packet_callback rx_cb) {
    /// UART2 for RS-232 w/PC @ 230400, 8bit, No parity, 1 stop bit
    unsigned int U2MODEvalue, U2STAvalue, U2BRGvalue;
    U2MODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE &
                  UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE &
                  UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE &
                  UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_1STOPBIT;
    U2STAvalue  = UART_INT_TX & UART_INT_RX_CHAR &UART_SYNC_BREAK_DISABLED &
                  UART_TX_ENABLE & UART_ADR_DETECT_DIS &
                  UART_IrDA_POL_INV_ZERO; // If not, whole output inverted.
    U2BRGvalue  = 9; // =3 for 2.5M Baud
    //U2BRGvalue  = 43; // =43 for 230500Baud (Fcy / ({16|4} * baudrate)) - 1
    //U2BRGvalue  = 86; // =86 for 115200 Baud
    //U2BRGvalue  = 1041; // =1041 for 9600 Baud
    

    OpenUART2(U2MODEvalue, U2STAvalue, U2BRGvalue);

    tx_idx = UART_TX_IDLE;
    rx_idx = UART_RX_IDLE;
    rx_callback = rx_cb;

    ConfigIntUART2(UART_TX_INT_EN & UART_TX_INT_PR5 & UART_RX_INT_EN & UART_RX_INT_PR6);
}
Exemplo n.º 10
0
void InitApp()
{
    _TRISA0 = 0; //led en sortie
    _TRISA1 = 0;
    led = 0;
    led2 = 0;

    //Sortie enable
    _TRISB9 = 0;
    _TRISB11 = 0;
    _ODCB9 = 1; //Open drain RB9 (dir 1)
    _ODCB11 = 1; //Open drain RB11 (dir 2)
    _ODCB10 = 1; //open drain RB10 PWM1H3

    //Le microswicth sur la pin RC5 (par exemple), on la met en entrée
    _TRISC5 = 1; //bumper bas de pince
    //Et on active la pullup qui va bien (registres CNPU1 et CNPU2)
    _CN26PUE = 1;

    _ODCC9 = 1; // Open drain sur la pin RC9 (pour les AX12)

    _TRISA4 = 1;
    _TRISA8 = 1;
    _TRISA9 = 1;
    _TRISB2 = 1; //RTS ?
    _TRISB3 = 1; //FLush ?
    _TRISA2 = 1; //CLK12 ?

    _TRISB4 = 1; // Arret d'urgence
    _CN1PUE = 1; // avec pullup
    _TRISB12 = 1; // switch 1
    _CN14PUE = 1; // avec pullup
    _TRISB13 = 1; // switch 2
    _CN13PUE = 1; // avec pullup
    _TRISB14 = 1; // switch 3
    _CN12PUE = 1; // avec pullup
    _TRISB15 = 1; // Laisse
    _CN11PUE = 1; // avec pullup

    OpenUART2(UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & UART_MODE_FLOW
              & UART_UEN_00 & UART_DIS_WAKE & UART_DIS_LOOPBACK
              & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE & UART_BRGH_SIXTEEN
              & UART_NO_PAR_8BIT & UART_1STOPBIT,
              UART_INT_TX_BUF_EMPTY & UART_IrDA_POL_INV_ZERO
              & UART_SYNC_BREAK_DISABLED & UART_TX_ENABLE & UART_TX_BUF_NOT_FUL & UART_INT_RX_CHAR
              & UART_ADR_DETECT_DIS & UART_RX_OVERRUN_CLEAR,
              BRGVALAX12);

    ConfigIntUART2(UART_RX_INT_PR4 & UART_RX_INT_EN
                   & UART_TX_INT_PR4 & UART_TX_INT_DIS);

    OpenTimer2(T2_ON & T2_GATE_OFF & T2_PS_1_256 & T2_32BIT_MODE_OFF & T2_SOURCE_INT, 1500);
    ConfigIntTimer2(T2_INT_PRIOR_3 & T2_INT_ON); //Interruption ON et priorite 3

    OpenTimer5(T5_OFF & T5_GATE_OFF & T5_PS_1_1 & T5_SOURCE_INT, 40000);
    ConfigIntTimer5(T5_INT_PRIOR_2 & T5_INT_ON);

    OpenQEI1(QEI_DIR_SEL_QEB & QEI_INT_CLK & QEI_INDEX_RESET_DISABLE & QEI_CLK_PRESCALE_1
             & QEI_NORMAL_IO & QEI_MODE_x4_MATCH & QEI_UP_COUNT,0);
//    ConfigIntQEI1(QEI_INT_DISABLE);
//    WriteQEI1(65535);        //Valeur pour declencher l'interruption du module QEI

    _QEA1R = 5;     //Module QEI 1 phase A sur RB5
    _QEB1R = 6;     //Module QEI 1 phase B sur RB6
    POS1CNT = 0; //valeur QEI

    IFS2bits.SPI2IF = 0; // Flag SPI2 Event Interrupt Priority
    IPC8bits.SPI2IP = 2; // Priority SPI2 Event Interrupt Priority
    IEC2bits.SPI2IE = 1; //Enable SPI2 Event Interrupt Priority

    // activation de la priorité des interruptions
    _NSTDIS = 0;
}