Functions which handle the uart.
More...
|
enum | eUart |
| clusters the select values for the different interfaces of UART1 More...
|
|
|
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...
|
|
|
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...
|
|
|
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...
|
|
|
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...
|
|
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
#include <tucbot/tucbot.h>
void testUart(void);
int main(void);
void testUart(void) {
uint8_t flag_redraw_menu = 0xFF;
uint8_t menu_pos = 0;
uint8_t display_pos = 0;
while (1) {
if (flag_redraw_menu) {
flag_redraw_menu = 0x00;
switch (menu_pos) {
case 1:
break;
case 2:
break;
case 3:
break;
default:
menu_pos = 0;
break;
}
}
menu_pos++;
if (menu_pos > 3) {menu_pos = 0;}
flag_redraw_menu = 0xFF;
} else {
if (menu_pos == 1) {
serstr0_p(PSTR(
"Test - UART" "\n\r" "send to "));
} else {
serstr1_p(PSTR(
"Test - UART" "\n\r" "send to "));
switch (menu_pos) {
}
}
}
if (menu_pos == 1) {
display_pos++;
if (display_pos > 7) {display_pos = 0;}
}
} else {
display_pos++;
if (display_pos > 7) {display_pos = 0;}
}
}
}
}
}
int main (void) {
testUart();
return (0);
}
◆ 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
|
◆ 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
-
- 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
-
- See also
- serfsend0(), serstr1_p() and serout1()
◆ serinp0()
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()
◆ serout0()
void serout0 |
( |
uint8_t |
send_data | ) |
|
Sends one byte through the UART0.
- Parameters
-
send_data | 8-bit unsigned integer |
- See also
- serinp0() and serout1()
- Examples
- uart.c.
◆ serout1()
void serout1 |
( |
uint8_t |
send_data | ) |
|
◆ 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 |
| ) |
|
◆ 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_data | 16-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_data | 16-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_data | 16-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_data | 16-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
-
data | Pointer to data structure. |
cnt | Size of data structure. |
pd | Packet 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
-
data | Pointer to data structure. |
cnt | Size of data structure. |
pd | Packet descriptor of data structure. |
- See also
- serout1()
- Examples
- packedCom.c.
◆ uart_select()
void uart_select |
( |
eUart |
select | ) |
|
Selects the interface of the UART1.
- Parameters
-
select | value of the selected interface - see also eUart |
- See also
- serout1() and serinp1()
- Examples
- uart.c.
void leds_set(eLedMask bitmask, uint8_t bool)
Sets the selected leds on or off.
uint8_t serstat1(void)
Gets the number of bytes in the input buffer from UART1.
uint8_t serstat0(void)
Gets the number of bytes in the input buffer from UART0.
void serstr0_p(const char *send_data)
Sends a string located in the flash through the UART0.
void uart_select(eUart select)
Selects the interface of the UART1.
@ kUartInternal
constant (1): select DSub15 interface
Definition: uart.h:55
@ kLedOn
constant (0xFF): turn leds on
Definition: leds.h:63
@ kLedRight
bit mask (0x04): right led
Definition: leds.h:46
uint8_t serinp0(void)
Receives one byte from the UART0.
void serout1(uint8_t send_data)
Sends one byte through the UART1.
@ kRequestContinuous
constant (3): request continuous updates
Definition: update.h:37
@ kLedMiddle
bit mask (0x08): middle led
Definition: leds.h:44
@ kLedOff
constant (0x00): turn leds off
Definition: leds.h:61
@ kUartXbee
constant (2): select XBee interface
Definition: uart.h:57
void lcdclr(void)
Clears the display.
void lcdxy(uint8_t x, uint8_t y)
Moves the cursor to a postion on the display.
void serstr1_p(const char *send_data)
Sends a string located in the flash through the UART1.
@ kUartRS232
constant (0): select RS232 interface
Definition: uart.h:53
void lcdstr_p(const char *send_data)
Writes a string located in the flash to the display.
void lcdout(uint8_t data)
Writes one byte to the display.
void init_tucbot(uint8_t enable_interrupts)
Initiates the TUC-Bot.
void mdelay(uint16_t mseconds)
Waits for the given time in milliseconds.
uint8_t serinp1(void)
Receives one byte from the UART1.
void serout0(uint8_t send_data)
Sends one byte through the UART0.