void UART_Init(long lBaudrate, int iBits, int pins){ if(pins == 12){ if((pADI_GP0->GPCON & 0x003C) == 0) DioCfg(pADI_GP0, pADI_GP0->GPCON | 0x003C); else DioCfg(pADI_GP0, 0x003C); a = 12; }else if(pins == 67){ if((pADI_GP0->GPCON & 0x9000) == 0) DioCfg(pADI_GP0, pADI_GP0->GPCON | 0x9000); else DioCfg(pADI_GP0, 0x9000); a = 67; } UrtCfg(pADI_UART, lBaudrate, iBits, 0); // Baud rate for 9600, 8-bits UrtMod(pADI_UART, COMMCR_DTR, 0); // <<<<< Modem Bits UrtIntCfg(pADI_UART, COMIEN_ERBFI | COMIEN_ETBEI); /* Enables UART interrupt source */ NVIC_EnableIRQ(UART_IRQn); // Enable UART IRQ }
/** @brief SPI initialization @return none **/ void SPI_Init(void) { DioPul(pADI_GP0, 0xf8); /* Disable the internal pull ups on P0 */ DioCfg(pADI_GP0, 0x0015); /* Configure P0[2:0] for SPI1 */ DioPulPin(AD7798_CS_PORT, AD7798_CS_PIN_NUMBER, 0); // Disable the internal pull up on AD7798 CS pin DioOenPin(AD7798_CS_PORT, AD7798_CS_PIN_NUMBER, 1); // Set CS pin for AD7798 as output DioSet(AD7798_CS_PORT, AD7798_CS_PIN); DioPulPin(ADT7310_CS_PORT, ADT7310_CS_PIN_NUMBER, 0); // Disable the internal pull up on ADT7310 CS pin DioOenPin(ADT7310_CS_PORT, ADT7310_CS_PIN_NUMBER, 1); // Set CS pin for ADT7310 as output DioSet(ADT7310_CS_PORT, ADT7310_CS_PIN); DioPulPin(AD5270_CS_PORT, AD5270_CS_PIN_NUMBER, 0); // Disable the internal pull up on ADT7310 CS pin DioOenPin(AD5270_CS_PORT, AD5270_CS_PIN_NUMBER, 1); // Set CS pin for ADT7310 as output DioSet(AD5270_CS_PORT, AD5270_CS_PIN); SpiBaud(pADI_SPI1, 9, SPIDIV_BCRST_DIS); /* Set the SPI1 clock rate in Master mode to x kHz. */ /* SPI configuration*/ SpiCfg(pADI_SPI1, SPICON_MOD_TX4RX4, SPICON_MASEN_EN, SPICON_CON_EN | SPICON_SOEN_EN | SPICON_RXOF_EN | SPICON_ZEN_EN | SPICON_TIM_TXWR | SPICON_CPOL_HIGH | SPICON_CPHA_SAMPLETRAILING | SPICON_ENABLE_EN); }
/** @brief UART initialization @param lBaudrate - UART baud rate @return none **/ void UART_Init(long lBaudrate) { DioCfg(pADI_GP0, 0x003C); /* Configure P0.1/P0.2 for UART */ UrtCfg(pADI_UART, lBaudrate, COMLCR_WLS_8BITS, COMLCR_STOP_EN); /* Configure UART bus */ UrtMod(pADI_UART, 0, 0); /* Modem Bits */ UrtIntCfg(pADI_UART, COMIEN_ERBFI | COMIEN_ETBEI); /* Enables UART interrupt source */ }
/** @brief Port initialization @return none **/ static void Port_Init(void) { if (GPIO_PINS == GPIO0) { /* Check if Port 0 is tested as GPIO */ DioCfg(pADI_GP0, 0x4000); /* Port 0 configured to GPIO */ DioPul(pADI_GP0, 0); /* Disables all pull-up resistors */ DioOen(pADI_GP0, 0xFF); /* Sets Port 0 to be outputs */ DioClr(pADI_GP0, 0xFF); /* Clear Port 0 outputs */ } else if (GPIO_PINS == GPIO1) { /* Check if Port 1 is tested as GPIO */ DioCfg(pADI_GP1, 0x0000); /* Port 1 configured to GPIO */ DioPul(pADI_GP1, 0); /* Disables all pull-up resistors */ DioOen(pADI_GP1, 0xFF); /* Sets Port 1 to be outputs */ DioClr(pADI_GP1, 0xFF); /* Clear Port 1 outputs */ } else if (GPIO_PINS == GPIO2) { /* Check if Port 2 is tested as GPIO */ DioCfg(pADI_GP2, 0xAA80); /* Port 2 configured to GPIO */ DioPul(pADI_GP2, 0); /* Disables all pull-up resistors */ DioOen(pADI_GP2, 0x07); /* Sets Port 2 to be outputs */ DioClr(pADI_GP2, 0x07); /* Clear Port 2 outputs */ } }
/* * inicializovanie portu na ktorom je pripojena user specified led */ void led_init(void) { // P4.2 as output DioCfg(pADI_GP4,0x10); DioOen(pADI_GP4, BIT2); }
/* *inicializovanie uart portu * rychlost 19200 baud * 8 bitov * jeden stop bit * vystup port P1.0\P1.1 */ void uart_init(void) { UrtLinCfg(0,19200,COMLCR_WLS_8BITS,COMLCR_STOP_DIS); DioCfg(pADI_GP1,0x9); // UART functionality on P1.0\P1.1 }