Esempio n. 1
0
/**
 * @brief Initializes UART 1
 *
 * This function initializes the UART channel 1.
 *
 * @param baud_rate Actual UART baud rate
 */
void sio_uart_1_init(uint32_t baud_rate)
{
    /* Calculate corresponding value for baud rateregister. */
    uint16_t baud_rate_reg = UART_BAUD(baud_rate);

    /* Init Port D pins */
    /* PD3 (TXD1) as output. */
    UART1_PORT.DIRSET = UART1_TX_PIN;
    /* PD2 (RXD1) as input. */
    UART1_PORT.DIRCLR = UART1_RX_PIN;

    /*
     * Microcontroller's USART register is updated to
     * run at the given baud rate.
     */
    /* 4 most siginificant bits of the Baud rate, BSCALE = 0 */
    UART1_REG.BAUDCTRLB = (baud_rate_reg >> 8) & 0xFF;
    UART1_REG.BAUDCTRLA = (uint8_t)baud_rate_reg;

    /* Faster async mode (UART clock divider = 8, instead of 16) */
    /* Enable Rx and Tx */
    UART1_REG.CTRLB = USART_RXEN_bm | USART_TXEN_bm | USART_CLK2X_bm;

    /* Set 8N1  */
    UART1_REG.CTRLC = USART_CHSIZE1_bm | USART_CHSIZE0_bm;

    /*
     * Receive and transmit interrrupt are enabled.
     */
    UART1_REG.CTRLA = USART_RXCINTLVL_gm | USART_TXCINTLVL_gm;
}
Esempio n. 2
0
int main(void)
{
    // initialize processor
    processorInit();
    // initialize timers
    timerInit();
    // initialize uarts
    uart0Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8);
    uart1Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8);
    // initialize rprintf to use UART1 for output
    rprintfInit(uart1SendByte);

    // Wait for a moment to allow hardware to stabilize.
    // This may be important if a serial port level-converter
    // like the MAX232 is used.  Charge-pump based converters
    // need some time after power-up to charge before
    // communication is reliable.
    timerPause(50);		// waits 50 milliseconds

    // run the test
    uartTest();

    return 0;
}
Esempio n. 3
0
int telit_init(FILE * stream)
{
	uart_init(UART_BAUD(CONFIG_GSM_BAUDRATE, F_CPU), stream, rx_buf,
	    CONFIG_GSM_RX_BUF, tx_buf, CONFIG_GSM_TX_BUF);

	/* Tri-state ON+RST pins with no pull-ups */
	CONFIG_GSM_EN_DIR &= ~(_BV(CONFIG_GSM_EN_PIN));
	CONFIG_GSM_EN_PORT &= ~(_BV(CONFIG_GSM_EN_PIN));

	CONFIG_GSM_RST_DIR &= ~(_BV(CONFIG_GSM_RST_PIN));
	CONFIG_GSM_RST_PORT &= ~(_BV(CONFIG_GSM_RST_PIN));

	_delay_ms(100);		/* Allow for signals to stabilize */

	telit_reset();

	return 0;
}
Esempio n. 4
0
int main(void)
{
	int ch;
	int8_t res;
	
	systemInit();
	gpioInit();
	
	uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART
		
	uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n");
	uart1Puts("efsl LPC2000-port and this Demo-Application\r\n");
	uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n");
	
	/* init efsl debug-output */
	lpc2000_debug_devopen(uart1Putch);
		
	ledToggle();
	
	rprintf("CARD init...");
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		rprintf("failed with %i\n",res);
	}
	else {
		rprintf("ok\n");
		rprintf("Directory of 'root':\n");
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			rprintf( "%s ( %li bytes )\n" ,
				list.currentEntry.FileName,
				list.currentEntry.FileSize ) ;
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) {
			rprintf("File %s open for append. Appending...", LogFileName);
			strcpy((char*)buf, "Martin hat's angehaengt\r\n");
			if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) {
				rprintf("ok\n");
			}
			else {
				rprintf("fail\n");
			}
			file_fclose( &filew );
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		fs_umount( &efs.myFs ) ;
	}
	
	while(1) {
		if ((ch = uart1Getch()) >= 0) {
			uart1Puts("You pressed : ");
			uart1Putch(ch);
			uart1Puts("\r\n");
			if ( ch == 'M' ) {
				rprintf("Creating FS\n");
				mkfs_makevfat(&efs.myPart);
			}
			ledToggle();
		}
	}
	
	return 0; /* never reached */
}