libspicboard-Doku
In- and output using a serial console. More...
Files | |
file | console.h |
Enumerations | |
enum | CONSOLE_PARITY { PARITY_DISABLED , PARITY_EVEN , PARITY_ODD } |
Parity bit types. More... | |
Functions | |
int8_t | sb_console_connect (uint32_t baud, CONSOLE_PARITY parity, uint8_t stopbits) |
Connect to serial console. More... | |
int8_t | sb_console_connect_default (void) |
Connect to serial console with default settings. More... | |
char | sb_console_getChar () |
Read the next character. More... | |
char * | sb_console_getString (char *string, uint16_t size) |
Read a line into the buffer. More... | |
int8_t | sb_console_putChar (char character) |
Prints a single character. More... | |
int8_t | sb_console_putString (const char *string) |
Writes the string and a trailing newline. More... | |
int8_t | sb_console_putStringFromFlash (const __flash char *string) |
Writes the string and a trailing newline. More... | |
Detailed Description
In- and output using a serial console.
This adds the ability to print and read from a connected serial console (via USB). You can use the primitives supplied by this module or even printf and scanf.
In Atmel Studio 7 select Menu "Tools" and choose "Data Visualizer". Click on sidebar "Configuration" In frame "Modules" expand "External Connection" and select "Serial Port" Configure "Serial Port Control Panel":
- choose the correct interface (something like "mEDBG Virtual COM Port (COM4)"
- set the "Baud rate" to the same value as the "BAUD_RATE" macro (by default 38400)
- choose correct "Parity" (default "disabled") and "Stop bits" (default "1")
- check "DTR" and "Open Terminal" (and "RTS" on slow systems) Click "Connect"
In Linux you can try to connect to the console using the libspicboard make target "console":
- Warning
- Cannot be used in conjunction with any other serial communication (including Serial Communication )
- Using printf/scanf (and derived functions) will consume a noticeable amount of flash memory!
Enumeration Type Documentation
enum CONSOLE_PARITY |
Function Documentation
int8_t sb_console_connect | ( | uint32_t | baud, |
CONSOLE_PARITY | parity, | ||
uint8_t | stopbits | ||
) |
Connect to serial console.
Specify the baud rate, parity type and number of stop bits and initiate a connection using the serial port (USART)
- Parameters
-
baud baud rate for serial connection parity pairty type (even/odd) if enabled stopbits number of stop bits (1 or 2)
- Return values
-
0 connection successfully set up -1 Baud rate achieved is higher than allowed -2 Baud rate achieved is lower than allowed -3 Baud rate value overflow -4; invalid stop bit count
int8_t sb_console_connect_default | ( | void | ) |
Connect to serial console with default settings.
Connect with 38400 baud, no parity and single stop bit to a serial console.
This is automatically used for the sb_console_* functions if sb_console_connect was not called before.
- Return values
-
0 connection successfully set up -1 Baud rate achieved is higher than allowed -2 Baud rate achieved is lower than allowed -3 Baud rate value overflow -4; invalid stop bit count
char sb_console_getChar | ( | ) |
Read the next character.
Invalid read operations (end of file) will return '\0'
- Return values
-
character read from console
char* sb_console_getString | ( | char * | string, |
uint16_t | size | ||
) |
Read a line into the buffer.
This function reads in at most one less than size characters and stores them into the buffer pointed to by the char array. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A terminating null byte (\0) is stored after the last character in the buffer.
- Parameters
-
string pointer to buffer size size of buffer
- Return values
-
string on success NULL on error or when end of file occurs while no characters have been read
int8_t sb_console_putChar | ( | char | character | ) |
Prints a single character.
- Parameters
-
character character to print
- Return values
-
-1 on error 0 on success
int8_t sb_console_putString | ( | const char * | string | ) |
Writes the string and a trailing newline.
- Parameters
-
string string to print
- Return values
-
-1 on error 0 on success
int8_t sb_console_putStringFromFlash | ( | const __flash char * | string | ) |
Writes the string and a trailing newline.
- Parameters
-
string string from flash memory to print
- Return values
-
-1 on error 0 on success