예제 #1
0
int
main(void)
{
	display[0] = '\0';
	display2[0] = '\0';
    	// Set the clocking to run directly from the crystal.
    	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    	// Initialize the OLED display and write status.
    	RIT128x96x4Init(1000000);
	RIT128x96x4StringDraw("----------------------", 0, 50, 15);

    	// Enable the peripherals used by this example.

    	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);		
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
		
	// Status
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD);
	GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_0,GPIO_DIR_MODE_OUT);
		
	//PB1
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	GPIOPadConfigSet(GPIO_PORTB_BASE,GPIO_PIN_1,GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD);
	GPIODirModeSet(GPIO_PORTB_BASE,GPIO_PIN_1,GPIO_DIR_MODE_IN);
		
	GPIOPortIntRegister(GPIO_PORTB_BASE, PortBIntHandler);
	GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_BOTH_EDGES);
	GPIOPinIntEnable(GPIO_PORTB_BASE, GPIO_PIN_1);
		
	IntPrioritySet(INT_GPIOB,0x80);
	SysTickIntRegister(SysTickHandler);                  
	SysTickPeriodSet(SysCtlClockGet()/10000);	// 0.1ms
	SysTickIntEnable();
	waitTime = 0;					// initialize
	waitTime2 = 0;
	SysTickEnable();


    	// Enable processor interrupts.
    	IntMasterEnable();

    	// Set GPIO A0 and A1 as UART pins.
    	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
	GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    	// Configure the UART for 115,200, 8-N-1 operation.
    	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
												 
	UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600,
                  	(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

   	 // Enable the UART interrupt.
    	IntEnable(INT_UART0);
   	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
		IntEnable(INT_UART1);
    	UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);



    	while(1)
   	{
    	}
}
예제 #2
0
void UART1Send(unsigned char *pucBuffer, unsigned ulCount)
{
	tBoolean bRc;
	static int FCount = 0;
	static int SCount = 0;
    //
    // Loop while there are more characters to send.
    //
	if(m_nTxBuffIn1 + ulCount >= TXBUFFSIZE1)
	{
		// No place to put new data
		// To be sure we purge all tx data
		//IntDisable(INT_UART1);
		/* Start the Tx of the message on the UART. */
		UARTIntDisable( UART1_BASE, UART_INT_TX );		
		#if 0 // Sent all data buffer until empty and put new data in to the buffer for sent
		// Fill hardware FIFO
		while(m_nTxBuffIn1 > 0)
		{
			bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]);
 			if(bRc == true)
			{
				m_nTxNextNdx1++;
				m_nTxBuffIn1--;
			}
				
		}
		memcpy(m_tTxBuff1 ,pucBuffer,ulCount);
		m_nTxNextNdx1 = 0;
		m_nTxBuffIn1 = ulCount;		
		#else // Throw all data buffer and put new data in to buffer for sent
		//memcpy(m_tTxBuff1 ,pucBuffer,ulCount);
		//m_nTxNextNdx1 = 0;
		//m_nTxBuffIn1 = ulCount;

		// Fill hardware FIFO
		bRc = true;
		while(m_nTxBuffIn1 > 0 && bRc == true)
		{
			bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]);
 			if(bRc == true)
			{
				m_nTxNextNdx1++;
				m_nTxBuffIn1--;
			}
				
		}
		#endif
		//IntEnable(INT_UART1);
		UARTIntEnable(UART1_BASE, UART_INT_TX);
	}
	else if(ulCount > 0)
	{
		//IntDisable(INT_UART1);
		/* Start the Tx of the message on the UART. */
		UARTIntDisable( UART1_BASE, UART_INT_TX );		
		if(m_nTxBuffIn1 > 0)
		{
			// Move TX data to start
			if(m_nTxNextNdx1 > 0)
			{
				memmove(m_tTxBuff1,&m_tTxBuff1[m_nTxNextNdx1],m_nTxBuffIn1);
			}
			m_nTxNextNdx1 = 0;
			// Add data to TXBuff
			memcpy(&m_tTxBuff1[m_nTxBuffIn1],pucBuffer,ulCount);
			m_nTxBuffIn1 += ulCount;
		}
		else
		{
			memcpy(m_tTxBuff1 ,pucBuffer,ulCount);
			m_nTxNextNdx1 = 0;
			m_nTxBuffIn1 = ulCount;
		}
		// Fill hardware FIFO
		bRc = true;
		while(m_nTxBuffIn1 > 0 && bRc == true)
		{
			bRc = UARTCharPutNonBlocking(UART1_BASE,m_tTxBuff1[m_nTxNextNdx1]);
 			if(bRc == true)
			{
				m_nTxNextNdx1++;
				m_nTxBuffIn1--;
			}
				
		}
 		//IntEnable(INT_UART1);
		UARTIntEnable(UART1_BASE, UART_INT_TX);
	}
}
예제 #3
0
파일: main.c 프로젝트: InSoonPark/FreeRTOS
static void vSerialTxCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )
{
portTickType xDelayPeriod;
static unsigned long *pulRandomBytes = mainFIRST_PROGRAM_BYTES;

	/* Co-routine MUST start with a call to crSTART. */
	crSTART( xHandle );

	for(;;)
    {	
		/* Was the previously transmitted string received correctly? */
		if( uxErrorStatus != pdPASS )
		{
			/* An error was encountered so set the error LED. */
			vSetErrorLED();
		}

		/* The next character to Tx is the first in the string. */
		cNextChar = mainFIRST_TX_CHAR;

		UARTIntDisable( UART0_BASE, UART_INT_TX );
		{
			/* Send the first character. */
			if( !( HWREG( UART0_BASE + UART_O_FR ) & UART_FR_TXFF ) )
			{
				HWREG( UART0_BASE + UART_O_DR ) = cNextChar;
			}

			/* Move the variable to the char to Tx on so the ISR transmits
			the next character in the string once this one has completed. */
			cNextChar++;
		}
		UARTIntEnable(UART0_BASE, UART_INT_TX);

		/* Toggle the LED to show a new string is being transmitted. */
        vParTestToggleLED( mainCOMMS_TX_LED );

		/* Delay before we start the string off again.  A pseudo-random delay
		is used as this will provide a better test. */
		xDelayPeriod = xTaskGetTickCount() + ( *pulRandomBytes );

		pulRandomBytes++;
		if( pulRandomBytes > mainTOTAL_PROGRAM_MEMORY )
		{
			pulRandomBytes = mainFIRST_PROGRAM_BYTES;
		}

		/* Make sure we don't wait too long... */
		xDelayPeriod &= mainMAX_TX_DELAY;

		/* ...but we do want to wait. */
		if( xDelayPeriod < mainMIN_TX_DELAY )
		{
			xDelayPeriod = mainMIN_TX_DELAY;
		}

		/* Block for the random(ish) time. */
		crDELAY( xHandle, xDelayPeriod );
    }

	/* Co-routine MUST end with a call to crEND. */
	crEND();
}
예제 #4
0
/*
** The main function
*/
int main()
{
    unsigned int divisorValue = 0;

    /* Configuring the system clocks for UART0 instance. */
    UART0ModuleClkConfig();

    /* Initializing the ARM Interrupt Controller. */
    IntAINTCInit();

    /* Performing the Pin Multiplexing for UART0 instance. */
    UARTPinMuxSetup(0);

    /* Performing a module reset. */
    UARTModuleReset(UART_INST_BASE);

    UARTFIFOConfig(UART_INST_BASE,
                   UART_FIFO_CONFIG(UART_TRIG_LVL_GRANULARITY_1,
                                    UART_TRIG_LVL_GRANULARITY_1,
                                    1, 1, 1, 1, UART_DMA_EN_PATH_SCR,
                                     UART_DMA_MODE_0_ENABLE));


   /* Computing the Divisor Value. */
    divisorValue = UARTDivisorValCompute(UART_MODULE_INPUT_CLK,
                                         BAUD_RATE_115200,
                                         UART16x_OPER_MODE,
                                         UART_MIR_OVERSAMPLING_RATE_42);

    /* Programming the Divisor Latches. */
    UARTDivisorLatchWrite(UART_INST_BASE, divisorValue);

    /* Switching to Configuration Mode B. */
    UARTRegConfigModeEnable(UART_INST_BASE, UART_REG_CONFIG_MODE_B);

    /* Programming the Line Characteristics. */
    UARTLineCharacConfig(UART_INST_BASE,
                         (UART_FRAME_WORD_LENGTH_8 | UART_FRAME_NUM_STB_1),
                         UART_PARITY_NONE);

    /* Disabe write access to Divisor Latches. */
    UARTDivisorLatchDisable(UART_INST_BASE);

    /* Disable Break Control. */
    UARTBreakCtl(UART_INST_BASE, UART_BREAK_COND_DISABLE);

    /* Switch to UART16x operating mode. */
    UARTOperatingModeSelect(UART_INST_BASE, UART16x_OPER_MODE);
    UARTIntEnable(UART_INST_BASE, (UART_INT_LINE_STAT | UART_INT_THR |
                                    UART_INT_RHR_CTI));


    /* Register the Interrupt Service Routines */
    IntRegister(RTC_INT_NUM, RTCIsr);
    IntRegister(UART_INT_NUM, UARTIsr);
    IntRegister(TIMER_INT_NUM, DMTimerIsr);

    /*
    ** Setting the priority for the system interrupt in AINTC.
    ** Timer interrupt is given highest priority - 1
    ** RTC interrupt is given medium priority - 2
    ** UART interrupt is given lowest priority - 4
    */
    IntPrioritySet(TIMER_INT_NUM, IRQ_PRIORITY_TIMER, AINTC_HOSTINT_ROUTE_IRQ);
    IntPrioritySet(RTC_INT_NUM, IRQ_PRIORITY_RTC, AINTC_HOSTINT_ROUTE_IRQ);
    IntPrioritySet(UART_INT_NUM, IRQ_PRIORITY_UART, AINTC_HOSTINT_ROUTE_IRQ);

    /* Enabling the system interrupt in AINTC for UART */
    IntSystemEnable(UART_INT_NUM);

    IntMasterIRQEnable();

    while(1);
}
예제 #5
0
void UART0Send(unsigned char *pucBuffer, unsigned ulCount)
{
	tBoolean bRc;
	static int FCount = 0;
	static int SCount = 0;

    //
    // Loop while there are more characters to send.
    //
	if(m_nTxBuffIn + ulCount >= TXBUFFSIZE)
	{
		// No place to put new data
		// To be sure we purge all tx data
		//IntDisable(INT_UART0);
		/* Start the Tx of the message on the UART. */
		UARTIntDisable( UART0_BASE, UART_INT_TX );
		#if 0
		// TX int
		// Push next char to transmitter
		while(m_nTxBuffIn > 0)
		{
			bRc = UARTCharPutNonBlocking(UART0_BASE,m_tTxBuff[m_nTxNextNdx]);
 			if(bRc == true)
			{
				m_nTxNextNdx++;
				m_nTxBuffIn--;
			}
		}

		memcpy(m_tTxBuff ,pucBuffer,ulCount);
		m_nTxNextNdx = 0;
		m_nTxBuffIn = ulCount;
		#else
		
		//memcpy(m_tTxBuff ,pucBuffer,ulCount);
		//m_nTxNextNdx = 0;
		//m_nTxBuffIn = ulCount;
		// Fill hardware FIFO
		bRc = true;
		while(m_nTxBuffIn > 0 && bRc == true)
		{
			bRc = UARTCharPutNonBlocking(UART0_BASE,m_tTxBuff[m_nTxNextNdx]);
 			if(bRc == true)
			{
				m_nTxNextNdx++;
				m_nTxBuffIn--;
			}
				
		}
		
		#endif
		UARTIntEnable(UART0_BASE, UART_INT_TX);
		//IntEnable(INT_UART0);
	}
	else if(ulCount > 0)
	{
		//IntDisable(INT_UART0);
		/* Start the Tx of the message on the UART. */
		UARTIntDisable( UART0_BASE, UART_INT_TX );
		if(m_nTxBuffIn > 0)
		{
			// Move TX data to start
			if(m_nTxNextNdx > 0)
			{
				memmove(m_tTxBuff,&m_tTxBuff[m_nTxNextNdx],m_nTxBuffIn);
			}
			m_nTxNextNdx = 0;
			// Add data to TXBuff
			memcpy(&m_tTxBuff[m_nTxBuffIn],pucBuffer,ulCount);
			m_nTxBuffIn += ulCount;
		}
		else
		{
			memcpy(m_tTxBuff ,pucBuffer,ulCount);
			m_nTxNextNdx = 0;
			m_nTxBuffIn = ulCount;
		}
		// Fill hardware FIFO
		bRc = true;
		while(m_nTxBuffIn > 0 && bRc == true)
		{
			bRc = UARTCharPutNonBlocking(UART0_BASE,m_tTxBuff[m_nTxNextNdx]);
 			if(bRc == true)
			{
				m_nTxNextNdx++;
				m_nTxBuffIn--;
			}
				
		}
		UARTIntEnable(UART0_BASE, UART_INT_TX);
 		//IntEnable(INT_UART0);
	}
}
예제 #6
0
파일: uart.c 프로젝트: iamecong/openwsn-fw
void uart_enableInterrupts(){
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_TX | UART_INT_RT);
}
예제 #7
0
// Functions
void SAD_Initialize(DriverRegisters* sadreg, role_t setRole, unsigned short setBaud)
{
    #ifdef SAD_DEBUG
    RIT128x96x4Init(1000000);
    
    #endif
    
    // initializing these values is messy but works for now
    sadreg->hs_baud.validbauds[0] = 1200;
    sadreg->hs_baud.validbauds[1] = 2400;
    sadreg->hs_baud.validbauds[2] = 9600;
    sadreg->hs_baud.validbauds[3] = 38400;
    // Initialize global flags and vars
    //UARTRX_FLAG = 0;
    //SYSTICKINT_FLAG = 0;
    //GLOBALTIME.hours = 0;
    //GLOBALTIME.mins = 0;
    //GLOBALTIME.seconds = 0;
    //GLOBALTIME.milisecs = 0;
    // set relevent structure attributes based on provided parameters
    sadreg->role = setRole;
    sadreg->txbaud = setBaud;
    // Based on the role, set the initial state for the state machine
    //sadreg->state = (sadreg->role == TXER) ? HANDSHAKE_TX : HANDSHAKE_RX;
    // Initialize the hand shake counter to 0
    //sadreg->hs_cnt = 0;
    // Initialize the circle buffer
    //init_cbuff(&sadreg->circbuf);
    SAD_timerinit(sadreg);
    // Initialize rx baud to 0
    //sadreg->rxbaud = 0;
    // Initialize hand shake baude pointer
    //sadreg->hs_baud.currentbaudchoice = 0;
    // Initialize tx baud to first element in valid baud rates array
     //sadreg->txbaud = sadreg->hs_baud.validbauds[sadreg->hs_baud.currentbaudchoice];

     
    // Use Systick timer
    SysTickIntRegister(&SysTickTimerHandler);
    SysTickPeriodSet(sadreg->timer.limit); // set to rollover every 1ms
    SysTickIntEnable();
    SysTickEnable();
    
    // Initialize HW Timer
    /* SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); */
    /* TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); */
    /* TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()); */
    /* IntEnable(INT_TIMER0A); */
    /* TimerEnable(TIMER0_BASE, TIMER_A); */
    

    // Initialize UART0
    // UART0_TX : PA1
    // UART0_RX : PA0
    // Enable UART Peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    // Set GPIO A0 and A1 as UART pins.
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    // Configure the UART for 115,200, 8-N-1 operation.
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    // Enable the UART interrupt.
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    // Initialize UART1
    // UART1_TX : PD3
    // UART1_RX : PD2
    // disable fifos
    // Enable UART Peripherals
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    // Set GPIO A0 and A1 as UART pins.
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3);
    // Configure the UART for SADreg baud, 8-N-1 operation.
    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), sadreg->txbaud,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));
    // Disable fifos, fifo is of depth 1, 
    //UARTFIFODisable(UART1_BASE); 
    // Enable the UART interrupt.
    IntEnable(INT_UART1);
    UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);

    // Enable processor interrupts.
    IntMasterEnable();
}
예제 #8
0
/*************************************************************************************************
 * @fn      HalUARTOpenIsr()
 *
 * @brief   Open a port based on the configuration
 *
 * @param   port   - UART port
 *          config - contains configuration information
 *          cBack  - Call back function where events will be reported back
 *
 * @return  Status of the function call
 *************************************************************************************************/
uint8 HalUARTOpenIsr(uint8 port, halUARTCfg_t *config)
{
  if (uartRecord.configured)
  {
    HalUARTClose(port);
  }

  if (config->baudRate > HAL_UART_BR_115200)
  {
    return HAL_UART_BAUDRATE_ERROR;
  }

  if (((uartRecord.rx.pBuffer = osal_mem_alloc(config->rx.maxBufSize)) == NULL) ||
      ((uartRecord.tx.pBuffer = osal_mem_alloc(config->tx.maxBufSize)) == NULL))
  {
    if (uartRecord.rx.pBuffer != NULL)
    {
      osal_mem_free(uartRecord.rx.pBuffer);
      uartRecord.rx.pBuffer = NULL;
    }

    return HAL_UART_MEM_FAIL;
  }
  
  if(config->flowControl)
  {
    IOCPinConfigPeriphOutput(GPIO_D_BASE, GPIO_PIN_3, IOC_MUX_OUT_SEL_UART1_RTS);
    GPIOPinTypeUARTOutput(GPIO_D_BASE, GPIO_PIN_3);
    IOCPinConfigPeriphInput(GPIO_B_BASE, GPIO_PIN_0, IOC_UARTCTS_UART1);
    GPIOPinTypeUARTInput(GPIO_B_BASE, GPIO_PIN_0);
  }
  
  IntEnable(HAL_UART_INT_CTRL);

  uartRecord.configured = TRUE;
  uartRecord.baudRate = config->baudRate;
  uartRecord.flowControl = config->flowControl;
  uartRecord.flowControlThreshold = (config->flowControlThreshold > config->rx.maxBufSize) ? 0 :
                                     config->flowControlThreshold;
  uartRecord.idleTimeout = config->idleTimeout;
  uartRecord.rx.maxBufSize = config->rx.maxBufSize;
  uartRecord.tx.maxBufSize = config->tx.maxBufSize;
  uartRecord.intEnable = config->intEnable;
  uartRecord.callBackFunc = config->callBackFunc;

  UARTConfigSetExpClk(HAL_UART_PORT, SysCtrlClockGet(), UBRRTable[uartRecord.baudRate],
                         (UART_CONFIG_WLEN_8 | UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE));

  /* FIFO level set to 1/8th for both RX and TX which is 2 bytes */
  UARTFIFOLevelSet(HAL_UART_PORT, UART_FIFO_TX1_8, UART_FIFO_RX1_8);
  UARTFIFOEnable(HAL_UART_PORT);

  /* Clear and enable UART TX, RX, CTS and Recieve Timeout interrupt */
  UARTIntClear(HAL_UART_PORT, (UART_INT_RX | UART_INT_TX | UART_INT_CTS | UART_INT_RT ));
  UARTIntEnable(HAL_UART_PORT, (UART_INT_RX | UART_INT_TX | UART_INT_CTS | UART_INT_RT ));
  
  if(config->flowControl)
  {
    /* Enable hardware flow control by enabling CTS and RTS */
    HWREG(HAL_UART_PORT + UART_O_CTL) |= (UART_CTL_CTSEN | UART_CTL_RTSEN );
  }
  UARTEnable(HAL_UART_PORT);

  return HAL_UART_SUCCESS;
}
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Initialize the OLED display and write status.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("UART Echo",            36,  0, 15);
    RIT128x96x4StringDraw("Port:   Uart 0",       12, 16, 15);
    RIT128x96x4StringDraw("Baud:   115,200 bps",  12, 24, 15);
    RIT128x96x4StringDraw("Data:   8 Bit",        12, 32, 15);
    RIT128x96x4StringDraw("Parity: None",         12, 40, 15);
    RIT128x96x4StringDraw("Stop:   1 Bit",        12, 48, 15);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    IntEnable(INT_UART0);
    UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((unsigned char *)"Enter text: ", 12);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
예제 #10
0
int main(void) {

	uint32_t ui32ADC0Value[4];

	ui32TempSet = 25;

	// Set System CLock
	SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
	// Enaable UART
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	// Enable GPIO
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
	// Enable ADC Peripheral
	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	//Allow the ADC12 to run at its default rate of 1Msps.
	ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

	//our code will average all four samples of temperature sensor data	ta on sequencer 1 to calculate the temperature, so all four sequencer steps will measure the temperature sensor
	ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
	ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);

	//enable ADC sequencer 1.
	ADCSequenceEnable(ADC0_BASE, 1);

	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	IntMasterEnable();
	IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_3);

	// Set bit rate fr serial communication
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));



	while (1)
	{
		//indication that the ADC conversion process is complete
		ADCIntClear(ADC0_BASE, 1);
		//trigger the ADC conversion with software
		ADCProcessorTrigger(ADC0_BASE, 1);
		//wait for the conversion to complete
		while(!ADCIntStatus(ADC0_BASE, 1, false))
		{
		}
		//read the ADC value from the ADC Sample Sequencer 1 FIFO
		ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
		ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;


		ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
		ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

		print_temp(ui32TempValueC);
		SysCtlDelay(SysCtlClockGet() / 3); //delay ~1 sec
		if(ui32TempValueC < ui32TempSet)
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 8);
		else
			GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 2);
	}
}
예제 #11
0
int main()
{
    unsigned int numByteChunks = 0;
    unsigned int remainBytes = 0;
    unsigned int bIndex = 0;

    /* Configuring the system clocks for UART0 instance. */
    UART0ModuleClkConfig();

    /* Performing the Pin Multiplexing for UART0 instance. */
    UARTPinMuxSetup(0);

    /* Performing a module reset. */
    UARTModuleReset(SOC_UART_0_REGS);

    /* Performing FIFO configurations. */
    UartFIFOConfigure();

    /* Performing Baud Rate settings. */
    UartBaudRateSet();

    /* Switching to Configuration Mode B. */
    UARTRegConfigModeEnable(SOC_UART_0_REGS, UART_REG_CONFIG_MODE_B);

    /* Programming the Line Characteristics. */
    UARTLineCharacConfig(SOC_UART_0_REGS, 
                         (UART_FRAME_WORD_LENGTH_8 | UART_FRAME_NUM_STB_1), 
                         UART_PARITY_NONE);

    /* Disabling write access to Divisor Latches. */
    UARTDivisorLatchDisable(SOC_UART_0_REGS);

    /* Disabling Break Control. */
    UARTBreakCtl(SOC_UART_0_REGS, UART_BREAK_COND_DISABLE);

    /* Switching to UART16x operating mode. */
    UARTOperatingModeSelect(SOC_UART_0_REGS, UART16x_OPER_MODE);

    /* Select the console type based on compile time check */
    ConsoleUtilsSetType(CONSOLE_UART);

    /* Performing Interrupt configurations. */
    UartInterruptEnable();

    numByteChunks = (sizeof(txArray) - 1) / NUM_TX_BYTES_PER_TRANS;
    remainBytes = (sizeof(txArray) - 1) % NUM_TX_BYTES_PER_TRANS;

    while(1)
    {
        /* This branch is entered if the transmission is not yet complete. */
        if(TRUE == txEmptyFlag)
        {
            if(bIndex < numByteChunks)
            {
                /* Transmitting bytes in chunks of NUM_TX_BYTES_PER_TRANS. */
                currNumTxBytes += UARTFIFOWrite(SOC_UART_0_REGS,
                                                &txArray[currNumTxBytes],
                                                NUM_TX_BYTES_PER_TRANS);

                bIndex++;
            }

            else
            {
                /* Transmitting remaining data from the data block. */
                currNumTxBytes += UARTFIFOWrite(SOC_UART_0_REGS,
                                                &txArray[currNumTxBytes],
                                                remainBytes);
            }

            txEmptyFlag = FALSE;

            /*
            ** Re-enables the Transmit Interrupt. This interrupt
            ** was disabled in the Transmit section of the UART ISR.
            */
            UARTIntEnable(SOC_UART_0_REGS, UART_INT_THR);
        }
    }
}
예제 #12
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int main(void) {
	//
	// Enable lazy stacking for interrupt handlers.  This allows floating-point
	// instructions to be used within interrupt handlers, but at the expense of
	// extra stack usage.
	//
	FPUEnable();
	FPULazyStackingEnable();

	//
	// Set the clocking to run directly from the crystal.
	//
	SysCtlClockSet(
			SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN
					| SYSCTL_XTAL_16MHZ);

	//
	// Enable the GPIO port that is used for the on-board LED.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

	//
	// Enable the GPIO pins for the LED (PF2).
	//
	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

	//
	// Enable the peripherals used by this example.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//
	// Enable processor interrupts.
	//
	IntMasterEnable();

	//
	// Set GPIO A0 and A1 as UART pins.
	//
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	//
	// Configure the UART for 115,200, 8-N-1 operation.
	//
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
			(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

	//
	// Enable the UART interrupt.
	//
	IntEnable(INT_UART0);
	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	//
	// Prompt for text to be entered.
	//
	UARTSend((unsigned char *) "Enter text: ", 14);

	//
	// Loop forever echoing data through the UART.
	//
	while (1) {
	}
}