Modules | Enumerations | Functions

Functions which handle the uart. More...

Modules

 Advanced informations
 

Enumerations

enum  eUart
 clusters the select values for the different interfaces of UART1 More...
 

Functions

void uart_select (eUart select)
 Selects the interface of the UART1. More...
 

Transmit Funktions

void serout0 (uint8_t send_data)
 Sends one byte through the UART0. More...
 
void serstr0 (const char *send_data)
 Sends a string located in the RAM through the UART0. More...
 
void serstr0_p (const char *send_data)
 Sends a string located in the flash through the UART0. More...
 
void serout1 (uint8_t send_data)
 Sends one byte through the UART1. More...
 
void serstr1 (const char *send_data)
 Sends a string located in the RAM through the UART1. More...
 
void serstr1_p (const char *send_data)
 Sends a string located in the flash through the UART1. More...
 

Receive Funktions

uint8_t serinp0 (void)
 Receives one byte from the UART0. More...
 
uint8_t serstat0 (void)
 Gets the number of bytes in the input buffer from UART0. More...
 
uint8_t serinp1 (void)
 Receives one byte from the UART1. More...
 
uint8_t serstat1 (void)
 Gets the number of bytes in the input buffer from UART1. More...
 

Additonal Transmit Functions (printf-style)

void serfsend0 (const char *format,...)
 Send formated data over the UART0 serial interface. More...
 
void serfsend1 (const char *format,...)
 Send formated data over the UART1 serial interface. More...
 

Additional Transmit Functions (packed)

void serstructsend0 (void *data, uint16_t cnt, uint8_t pd)
 Send packed data over the UART0 serial interface. More...
 
void serstructsend1 (void *data, uint16_t cnt, uint8_t pd)
 Send packed data over the UART1 serial interface. More...
 

Detailed Description

Functions which handle the uart.

The microcontroller ATmega644p, which is used on the robot, has two serial interfaces called USART (Universal Synchronous and Asynchronous serial Receiver and Transmitter). Here they will be referred to as UART0 and UART1. For more information on the serial communication see ATmega644P datasheet.

On the CrumpStick, the breakout-board of the microcontroller, the UART0 is directly used for the USB interface.

Therefore only UART1 is available for additional interfaces. In order to send data through multiple different interfaces the TUC-Bot uses an analog switching ic. The interface of UART1 is selectable with uart_select().

The baudrate of both interfaces is set to 57600 baud/s.

example

/*******************************************************************************
* examples/uart.c *
* =============== *
* *
* Version: 1.0.4 *
* Date : 01.11.17 *
* Author : Peter Weissig *
* *
* If you are changing this file, you may also consider to update *
* demos/diagnosticTool/diagnosticTool.c *
*******************************************************************************/
//*********************************<Included files>*****************************
#include <tucbot/tucbot.h>
//*********************************<Methods>************************************
void testUart(void);
int main(void);
//*********************************[testUart]***********************************
void testUart(void) {
uint8_t flag_redraw_menu = 0xFF;
uint8_t menu_pos = 0;
uint8_t display_pos = 0;
lcdclr();
lcdstr_p(PSTR("UART - XBee" ));
while (1) {
// redraw menu
if (flag_redraw_menu) {
flag_redraw_menu = 0x00;
lcdxy(7,0);
switch (menu_pos) {
case 1:
lcdstr_p(PSTR("USB "));
break;
case 2:
lcdstr_p(PSTR("RS232 "));
break;
case 3:
lcdstr_p(PSTR("Internal"));
break;
default:
lcdstr_p(PSTR("XBee "));
menu_pos = 0;
break;
}
lcdxy(0,1); lcdstr_p(PSTR("######## <+> <s>"));
mdelay(400);
}
// check if buttons were pushed
// middle button --> increase menu
mdelay(100);
menu_pos++;
if (menu_pos > 3) {menu_pos = 0;}
flag_redraw_menu = 0xFF;
} else {
// right button --> send text
mdelay(100);
if (menu_pos == 1) {
serstr0_p(PSTR("Test - UART" "\n\r" "send to "));
serstr0_p(PSTR("USB "));
serout0('\n'); serout0('\r');
} else {
serstr1_p(PSTR("Test - UART" "\n\r" "send to "));
switch (menu_pos) {
case 2: serstr1_p(PSTR("RS232 ")); break;
case 3: serstr1_p(PSTR("Internal")); break;
default: serstr1_p(PSTR("XBee ")); break;
}
serout1('\n'); serout1('\r');
}
mdelay(400);
}
// update display depending on menu position
if (menu_pos == 1) {
if (serstat0()) {
lcdxy(display_pos,1);
display_pos++;
if (display_pos > 7) {display_pos = 0;}
}
} else {
if (serstat1()) {
lcdxy(display_pos,1);
display_pos++;
if (display_pos > 7) {display_pos = 0;}
}
}
}
}
}
//*********************************[main]***************************************
int main (void) {
init_tucbot(0xFF);
testUart();
return (0);
}

Enumeration Type Documentation

◆ eUart

enum eUart

clusters the select values for the different interfaces of UART1

See also
uart_select()
Enumerator
kUartRS232 

constant (0): select RS232 interface

kUartInternal 

constant (1): select DSub15 interface

kUartXbee 

constant (2): select XBee interface

kUartXbee2 

constant (3): also select XBee interface

Function Documentation

◆ serfsend0()

void serfsend0 ( const char *  format,
  ... 
)

Send formated data over the UART0 serial interface.

To use this function, include tucbot_additionals/fout.h into your code.

#include <tucbot_additionals/fout.h>

int main(void) {

    init_tucbot(0xFF);
    int motor_vel = 5;
    serfsend0("%d %d\n", motor_vel, 1);
}
Parameters
formatAnalog to lcdfout
...Analog to lcdfout
See also
serstr0_p() and serout0()

◆ serfsend1()

void serfsend1 ( const char *  format,
  ... 
)

Send formated data over the UART1 serial interface.

To use this function, include tucbot_additionals/fout.h into your code.

Parameters
formatAnalog to lcdfout
...Analog to lcdfout
See also
serfsend0(), serstr1_p() and serout1()

◆ serinp0()

uint8_t serinp0 ( void  )

Receives one byte from the UART0.

This function will wait until one character is received.

Returns
8-bit unsigned integer
See also
serstat0(), serout0() and serinp1()
Examples
uart.c.

◆ serinp1()

uint8_t serinp1 ( void  )

Receives one byte from the UART1.

This function will wait until one character is received.

Returns
8-bit unsigned integer
See also
serstat1(), uart_select(), serout1() and serinp0()
Examples
uart.c.

◆ serout0()

void serout0 ( uint8_t  send_data)

Sends one byte through the UART0.

Parameters
send_data8-bit unsigned integer
See also
serinp0() and serout1()
Examples
uart.c.

◆ serout1()

void serout1 ( uint8_t  send_data)

Sends one byte through the UART1.

Parameters
send_data8-bit unsigned integer
See also
serinp1(), uart_select() and serout0()
Examples
uart.c.

◆ serstat0()

uint8_t serstat0 ( void  )

Gets the number of bytes in the input buffer from UART0.

Returns
8-bit unsigned integer
See also
serinp0()
Examples
uart.c.

◆ serstat1()

uint8_t serstat1 ( void  )

Gets the number of bytes in the input buffer from UART1.

Returns
8-bit unsigned integer
See also
serinp1() and uart_select()
Examples
uart.c.

◆ serstr0()

void serstr0 ( const char *  send_data)

Sends a string located in the RAM through the UART0.

This function loads the referenced string character by character and writes those using the serout0() function until a terminating \ 0-character is found.

Parameters
send_data16-bit pointer to a character located in the RAM
See also
serstr0_p() and serout0()

◆ serstr0_p()

void serstr0_p ( const char *  send_data)

Sends a string located in the flash through the UART0.

This function loads the referenced string character by character and writes those using the serout0() function until a terminating \ 0-character is found.

Parameters
send_data16-bit pointer to a character located in the flash
See also
serstr0() and serout0()
Examples
uart.c.

◆ serstr1()

void serstr1 ( const char *  send_data)

Sends a string located in the RAM through the UART1.

This function loads the referenced string character by character and writes those using the serout1() function until a terminating \ 0-character is found.

Parameters
send_data16-bit pointer to a character located in the RAM
See also
serstr1_p() and serout1()

◆ serstr1_p()

void serstr1_p ( const char *  send_data)

Sends a string located in the flash through the UART1.

This function loads the referenced string character by character and writes those using the serout1() function until a terminating \ 0-character is found.

Parameters
*send_data16-bit pointer to a character located in the flash
See also
serstr1() and serout1()
Examples
uart.c.

◆ serstructsend0()

void serstructsend0 ( void *  data,
uint16_t  cnt,
uint8_t  pd 
)

Send packed data over the UART0 serial interface.

For a more detailed description, see Packed Communication.

Parameters
dataPointer to data structure.
cntSize of data structure.
pdPacket descriptor of data structure.
See also
serout0()
Examples
packedCom.c.

◆ serstructsend1()

void serstructsend1 ( void *  data,
uint16_t  cnt,
uint8_t  pd 
)

Send packed data over the UART1 serial interface.

For a more detailed description, see Packed Communication.

Parameters
dataPointer to data structure.
cntSize of data structure.
pdPacket descriptor of data structure.
See also
serout1()
Examples
packedCom.c.

◆ uart_select()

void uart_select ( eUart  select)

Selects the interface of the UART1.

Parameters
selectvalue of the selected interface - see also eUart
See also
serout1() and serinp1()
Examples
uart.c.
leds_set
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
serstat1
uint8_t serstat1(void)
Gets the number of bytes in the input buffer from UART1.
serstat0
uint8_t serstat0(void)
Gets the number of bytes in the input buffer from UART0.
serstr0_p
void serstr0_p(const char *send_data)
Sends a string located in the flash through the UART0.
buttons_get
eButtonMask buttons_get(eButtonMask bitmask)
Returns the last stored value of the selected buttons.
kButtonMiddle
@ kButtonMiddle
bit mask (0x08): middle button
Definition: buttons.h:35
uart_select
void uart_select(eUart select)
Selects the interface of the UART1.
kUartInternal
@ kUartInternal
constant (1): select DSub15 interface
Definition: uart.h:55
kLedOn
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
kLedRight
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
kButtonRight
@ kButtonRight
bit mask (0x10): right button
Definition: buttons.h:37
serinp0
uint8_t serinp0(void)
Receives one byte from the UART0.
buttons_request
void buttons_request(eRequestType request)
Requests new data from the buttons.
serout1
void serout1(uint8_t send_data)
Sends one byte through the UART1.
kRequestContinuous
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
kLedMiddle
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
kLedOff
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
kUartXbee
@ kUartXbee
constant (2): select XBee interface
Definition: uart.h:57
lcdclr
void lcdclr(void)
Clears the display.
lcdxy
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
serstr1_p
void serstr1_p(const char *send_data)
Sends a string located in the flash through the UART1.
kUartRS232
@ kUartRS232
constant (0): select RS232 interface
Definition: uart.h:53
lcdstr_p
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
lcdout
void lcdout(uint8_t data)
Writes one byte to the display.
init_tucbot
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
mdelay
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
serinp1
uint8_t serinp1(void)
Receives one byte from the UART1.
serout0
void serout0(uint8_t send_data)
Sends one byte through the UART0.