void GPSline(void) { char buffer[128]; int lenght; int k; int i; lenght = sprintf (buffer, "$PSRF103,00,01,00,01*25"); for(k=0;k<lenght;k++) { uart0_putchar(buffer[k]); Delay(1); } uart0_putchar(0x0D); //CR uart0_putchar(0x0a); //LF count += 1; while(!uart0_getchar_present()); while(uart0_getchar() != '$');// wait for the start of a line for(i=0;i<256;i++) { while(!uart0_getchar_present()); gpsbuffer[i] = uart0_getchar(); // uart0_putchar(gpsbuffer[i]); if(gpsbuffer[i] == '\r') { gpsbuffer[i] = 0; while(uart0_getchar_present()) uart0_getchar(); return; } } }
void myputchar(char ch) { if (ch == '\n') uart0_putchar('\r'); uart0_putchar(ch); return ; }
void uart0_puts(const char* c_string) { char* p = (char*) c_string; while(*p) { uart0_putchar(*p); p++; } uart0_putchar('\n'); }
int main (void) { char buffer[128]; int lenght; int i; int button_1; int button_2; SystemCoreClockUpdate(); /* Get Core Clock Frequency */ SysTick_Config(SystemCoreClock/1000); /* Generate interrupt each 1 ms */ LED_Config(); // uart0_init (41940, 9600); uart0_init (41940, 4800); // UArt_0 initilization SIM->SCGC5 |= (1UL << 9) | (1UL << 13); //Uart_0 clock and Clock to the port (e.g. B/E(13)) SIM->SCGC5 |= (1UL << 13); //Uart_0 clock speed SIM->SCGC4 |= (1UL << 10); //Enable Uart_0 PORTE->PCR[20] = (0x4 << 8); //Set UART0 pins to alternative 4 TX PORTE->PCR[21] = (0x4 << 8); //Set UART0 pins to alteratnative 4 RX //Setup GPS for polling $PSRF103,00,01,00,01*25 lenght = sprintf (buffer, "$PSRF103,00,01,00,01*25"); for(i=0;i<lenght;i++) { uart0_putchar(buffer[i]); //Delay(1); } uart0_putchar(0x0D); //CR //Delay(1); uart0_putchar(0x0A); //LF while(1) { //uart0_putchar('A'); button_1 = buttonPress_1(); button_2 = buttonPress_2(); /* GPSline(); //get_serial(); getlock(); LED_On (); // Delay(500); // LED_Off(); // Delay(500); // uart0_putchar('B'); */ } }
/*----------------------------------------------------------------------------- * SER_PutChar: Write a character to the Serial Port *----------------------------------------------------------------------------*/ int32_t SER_PutChar (int32_t ch) { #ifdef __DBG_ITM int i; ITM_SendChar (ch & 0xFF); for (i = 10000; i; i--); #else //while (!(UART1_S1 & UART_S1_TDRE_MASK)); //UART1_D = (ch & 0xFF); // Wait until space is available in the FIFO // // while (!(UART_S1_REG(TERM_PORT) & UART_S1_TDRE_MASK)) //{} // Now Send the character // //UART_D_REG(TERM_PORT) = (uint8)ch; if (TERM_PORT_NUM == 0) uart0_putchar(UART0_BASE_PTR, ch); else if (TERM_PORT_NUM == 1) uart_putchar(UART1_BASE_PTR, ch); else uart_putchar(UART2_BASE_PTR, ch); #endif return (ch & 0xFF); }
static int uart0_putchar(char c, FILE *stream){ if (c == '\n') uart0_putchar('\r', stream); loop_until_bit_is_set(UCSR0A, UDRE0); UDR0 = c; return 0; }
size_t __write(int handle, const unsigned char * buffer, size_t size) { /* Remove the #if #endif pair to enable the implementation */ #if 1 size_t nChars = 0; if (buffer == 0) { /* * This means that we should flush internal buffers. Since we * don't we just return. (Remember, "handle" == -1 means that all * handles should be flushed.) */ return 0; } /* This template only writes to "standard out" and "standard err", * for all other file handles it returns failure. */ if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) { return _LLIO_ERROR; } for (/* Empty */; size != 0; --size) { #if 1 if( *buffer == '\n') uart0_putchar(UART0_BASE_PTR,'\r');//return carriage uart0_putchar(UART0_BASE_PTR,*buffer++);/*doesnt return error number*/ #endif ++nChars; } return nChars; #else /* Always return error code when implementation is disabled. */ return _LLIO_ERROR; #endif }
int uart0_prints ( char* s ) { int i = 0; while ( *s ) { uart0_putchar( *s++ ); i++; } return i; }
void u0_dbg_put(const char *string) { char* p = (char*) string; while(*p) { uart0_putchar(*p); p++; } }
bool irmsg_txQueuedMsg(bool flashIRLEDsPostTx) { uint8_t i; if (m_txActive) { /* If a transmission is already in progress, return true */ return true; } if (uart0_getTxBufferConsumedCount() != 0) { /* Return false if the UART's transmit buffer is not empty */ return false; } if ((g_irLEDManualState != 0x00) || (ircomm_getEnabledLEDs() == 0x00)) { /* If some IR LEDs are currently in manual control mode or if no IR * LEDs have been selected to be used for the message transmission, * return false. */ return false; } /* At this point, we know that the transmission can proceed, so before * doing anything else, (e.g. moving any character to the UART), indicate * that we are now actively transmitting. */ m_txActive = true; /* Remember whether we should flash the IR LEDS after transmitting the * message. The flash pattern, if requested, is as follows: * * IRLED1: 4 periods of Timer1 * IRLED2: 8 periods of Timer1 * IRLED3: 12 periods of Timer1 * IRLED4: 16 periods of Timer1 * * This pattern is repeated serveral times and allows the receiver to * determine how it is oriented with respect to the transmitter by sampling * its ambient light sensor with period equal to that of Timer1 for 4x * over-sampling. */ m_flashIRLEDsPostTx = flashIRLEDsPostTx; /* Set the function to call when all characters have been transmitted */ uart0_setTxCompleteCallback(irmsg_uartTxCompleteCallback); /* Copy all characters from the irmsg transmit buffer to the UART's * transmit buffer. Interrupts will be used to automatically start * sending the characters. */ i = 0; while (i < m_txBufLength) { uart0_putchar(m_txBuf[i]); } /* Resetting the transmit buffer length to 0 effectively erases the * transmit buffer. */ m_txBufLength = 0; return true; }
/*! * Print text string on console, starting at current cursor position * \param attr Attributes to apply (ignored) * \param text String to print */ static int uart0_printf ( int attr, char *text ) { if ( text == NULL ) return 0; while ( *text != '\0' ) /* Loop until end of string */ uart0_putchar ( *text++ ); return strlen ( text ); }
void out_char (char ch) { if (TERM_PORT_NUM == 0) uart0_putchar(UART0_BASE_PTR, ch); else if (TERM_PORT_NUM == 1) uart_putchar(UART1_BASE_PTR, ch); else uart_putchar(UART2_BASE_PTR, ch); }
void outputStringToUART0 (char* St) { uint8_t cnt; if (cellVoltageReading.adcWholeWord < CELL_VOLTAGE_THRESHOLD_UART) return; if (stateFlags1 & (1<<isRoused)) { // if system not roused, no output for (cnt = 0; cnt < strlen(St); cnt++) { uart0_putchar(St[cnt]); } } while (uart0_char_queued_out()) ; } // end of outputStringToUART0
void get_serial(void) { int i; int j; char buffer[9]; for(i=0;i<3;i++) { while(!uart0_getchar_present()); buffer[i] = uart0_getchar(); uart0_putchar('G'); } }
/************************************************************** * Name : put * Description : Send string character to the * console. * Parameters : lubp_ptr_str * Return : none * Critical/explanation : no **************************************************************/ void put(T_UBYTE *lubp_ptr_str) { //while(*lubp_ptr_str) for (;;) { if (*lubp_ptr_str) { uart0_putchar((T_UBYTE) *lubp_ptr_str++); } else { break; } } //uart0_putchar((T_UBYTE) *lubp_ptr_str++); }
char * mygets(char *s) { char ch; while((ch = uart0_getchar()) != '\r') { *s = ch; s++; uart0_putchar(ch); } *s++ = '\r'; *s++ = '\n'; *s = '\0'; return s; }
/*! Device wrapper for console */ static int uart0_send ( void *data, size_t size, uint flags, device_t *dev ) { char *text = data; if ( dev->flags & DEV_TYPE_CONSOLE ) { if ( text == NULL ) return 0; while ( *text != '\0' ) /* Loop until end of string */ uart0_putchar ( *text++ ); return strlen ( text ); } else { return EXIT_FAILURE; } }
int u0_dbg_printf(const char *format, ...) { int len = 0; char buff[128] = { 0 }; va_list args; va_start(args, format); #if USE_REDUCED_PRINTF == 0 len = vsprintf(buff, format, args); #else len = vsiprintf(buff, format, args); #endif va_end(args); char *c = &buff[0]; while(*c) { uart0_putchar(*c); c++; } return len; }
/*! * Move cursor to specified location * (just go to new line - send \n on serial port) */ static int uart0_gotoxy ( int x, int y ) { uart0_putchar ( '\n' ); return 0; }
static void uart_echo () { uart0_putchar ( uart0_getchar() ); }
/*! * Clear console * (just go to new line - send \n on serial port) */ int uart0_clear () { uart0_putchar ( '\n' ); return 0; }
int fputc(int c, FILE *f) { uart0_putchar(c); return (c & 0xFF); }
/* * eeprom_task * */ void eeprom_task() { uint32_t i; /**************************************/ i2c_init_state( &xact_s) ; uart0_putstring("eeprom i2c write 1 byte...\n"); xact_s.i2c_tx_buffer[0] = i2c_create_write_address(EEPROM_ADDR); // printf_lpc(UART0,"address is: 0x%x\n",xact_s.i2c_tx_buffer[0]); xact_s.i2c_tx_buffer[1] = 0x0; xact_s.i2c_tx_buffer[2] = 0x0; xact_s.i2c_tx_buffer[3] = 0xe; xact_s.write_length = 0x4; xact_s.read_length = 0x0; xact_s.xact_active = 0x1; xact_s.xact_success = 0x0; start_i2c0_master_xact(&xact_s, &xact_callback); poll_wait(); if(xact_s.xact_success == 1) { uart0_putstring("eeprom i2c write byte xaction success.\n"); } else { uart0_putstring("eeprom i2c write byte xaction fail.\n"); } /**************************************/ i2c_init_state( &xact_s) ; uart0_putstring("eeprom i2c read byte using repeated start...\n"); xact_s.i2c_tx_buffer[0] = i2c_create_write_address(EEPROM_ADDR); xact_s.i2c_tx_buffer[1] = 0x0; xact_s.i2c_tx_buffer[2] = 0x0; xact_s.write_length = 0x3; xact_s.i2c_tx_buffer[3] = i2c_create_read_address(EEPROM_ADDR); xact_s.read_length = 0x1; xact_s.xact_active = 0x1; xact_s.xact_success = 0x0; start_i2c0_master_xact(&xact_s, &xact_callback); poll_wait(); if(xact_s.xact_success == 1) { uart0_putstring("eeprom i2c read byte xaction success.\n"); } else { uart0_putstring("eeprom i2c read byte xaction fail.\n"); } uart0_putstring("Read data 0 is 0x"); uart0_putstring(util_uitoa(xact_s.i2c_rd_buffer[0],16)); if(xact_s.i2c_rd_buffer[0] != 0xe) uart0_putstring("Error, wrong value, should be 0xe"); uart0_putstring("\n"); /**************************************/ i2c_init_state( &xact_s) ; uart0_putstring("i2c write bytes task...\n"); xact_s.i2c_tx_buffer[0] = i2c_create_write_address(EEPROM_ADDR); xact_s.i2c_tx_buffer[1] = 0x0; xact_s.i2c_tx_buffer[2] = 0x0; xact_s.i2c_tx_buffer[3] = 0x0b; xact_s.i2c_tx_buffer[4] = 0x0c; xact_s.i2c_tx_buffer[5] = 0x0d; xact_s.i2c_tx_buffer[6] = 0x1e; xact_s.i2c_tx_buffer[7] = 0x0f; xact_s.write_length = 0x8; xact_s.read_length = 0x0; xact_s.xact_active = 0x1; xact_s.xact_success = 0x0; start_i2c0_master_xact(&xact_s, &xact_callback); poll_wait(); if(xact_s.xact_success == 1) { uart0_putstring("eeprom i2c write bytes xaction success.\n"); } else { uart0_putstring("eeprom i2c write bytes xaction fail.\n"); } /**************************************/ i2c_init_state( &xact_s) ; uart0_putstring("i2c read bytes task...\n"); xact_s.i2c_tx_buffer[0] = i2c_create_write_address(EEPROM_ADDR); xact_s.i2c_tx_buffer[1] = 0x0; xact_s.i2c_tx_buffer[2] = 0x0; xact_s.i2c_tx_buffer[3] = i2c_create_read_address(EEPROM_ADDR); xact_s.write_length = 0x3; xact_s.read_length = 0x5; xact_s.xact_active = 0x1; xact_s.xact_success = 0x0; start_i2c0_master_xact(&xact_s, &xact_callback); poll_wait(); if(xact_s.xact_success == 1) { uart0_putstring("eeprom i2c write bytes xaction success.\n"); } else { uart0_putstring("eeprom i2c write bytes xaction fail.\n"); } uint8_t check_buff[5] = {0xb,0xc,0xd,0x1e,0xf}; for(i=0; i<5; ++i) { uart0_putstring(util_uitoa(i,10)); uart0_putstring(": Read data is 0x"); uart0_putstring(util_uitoa(xact_s.i2c_rd_buffer[i],16)); uart0_putchar('\n'); if(check_buff[i] != xact_s.i2c_rd_buffer[i]) { uart0_putstring("Wrong value in read bytes-> 0x"); uart0_putstring(util_uitoa(xact_s.i2c_rd_buffer[i],16)); uart0_putstring("\n...Should be-> 0x"); uart0_putstring(util_uitoa(check_buff[i],16)); } uart0_putchar('\n'); } }
int putchar(int c) { uart0_putchar((char) c); return c; }
int putchar(int c) { return uart0_putchar(c); }
void out_char (char ch) { uart0_putchar(LPUART0_BASE_PTR, ch); }
static void __putchar(const char buf) { uart0_putchar(buf); }
// printf's putchar int16_t putchar(int16_t c) { return uart0_putchar(c); }
int main(void) { init(); //****** //TEST 1 //****** #if _TEST == 1 bool toggle = false; uint8_t packet_pos = 0; char c; DDRD |= (1 << PD6); init(); while(true) { c = uart0_getchar(); if (c == 'y') { toggle = false; uart0_putchar('y'); } if (c == 'n') { toggle = true; uart0_putchar('n'); } if (toggle) PORTD |= (1 << PD6); else PORTD &= ~(1 << PD6); } //****** //TEST 2 //****** #elif _TEST == 2 char c; DDRD |= (1 << PD6) // set outputs in PORTD | (1 << PD5) | (1 << PD4); TCCR1A = 0x00; // clear all current timer 1 settings TCCR1B = 0x00; TCCR1B |= (1 << WGM12); // turn on CTC mode: // Clear Timer on Compare Match TIMSK1 = (1 << TOIE1); // enable global and timer overflow interrupt TCCR1B |= (1 << CS10); while(true) { c = uart0_getchar(); if (c != EOF) { if (c == 'f') servoTurn(0); if (c == 'g') servoTurn(90); if (c == 'h') servoTurn(180); } } //****** v //TEST 3 //****** #elif _TEST == 3 Packet host_packet; PacketInit(&host_packet); int len = 0; char c; DDRD |= (1 << PD6); while(1) { c = uart0_getchar(); if (c != EOF) len = PacketProcessChar(&host_packet, c); if (len > 0) uart0_printstr("got a packet!\r\n"); } //****** //TEST 4 //****** #elif _TEST == 4 uint8_t messageBuf[4]; uint8_t TWI_slaveAddress = 0x10; DDRD |= (1 << PD5) | (1 << PD6); TWIInit(); sei(); while(1) { PORTD ^= (1 << PD5) | (1 << PD6); TWIStart(); //TWIStop(); _delay_ms(500); } #elif _TEST == 5 Packet host_packet; PacketInit(&host_packet); int len = 0; char c; DDRD |= (1 << PD5); uint8_t message_buf[] = {0xFE, 0xFE, 0x01, 0x04, 0x02, 0x2B, 0x01, 0xCC}; int i; while(1) { c = uart0_getchar(); if (c != EOF) { len = PacketProcessChar(&host_packet, c); } if (len > 0) { PORTD ^= (1 << PD5); len = 0; } //for (i = 0; i < 8; i++) // uart0_putchar(message_buf[i]); //uart0_putchar(0xFD); //uart0_putchar(0xFF); //c = uart0_getchar(); //if (c != EOF) { // len = PacketProcessChar(&host_packet, c); //PORTD ^= (1 << PD5); //} //if (len > 0) //PORTD ^= (1 << PD5); //_delay_ms(1000); } /* DDRD |= (1 << PD5); char c; while(1) { c = uart0_getchar(); if (c != EOF) { uart0_putchar(c); PORTD ^= (1 << PD5); //_delay_ms(500); } }*/ #endif // _TEST return 0; }
int uart_putchar(char c) { return uart0_putchar(c, NULL); }