(UART_RxString)
m
 
(28 intermediate revisions by 3 users not shown)
Line 6: Line 6:
  
 
==UART_Init==
 
==UART_Init==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination || '''  void UART_Init(uint32_t Baudrate)'''
+
|Defination ||   void UART_Init(uint32_t var_baudRate_u32)
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments ||*uint32_t : Baudrate to be configured.
'''uint32_t''' : Baudrate to be configured.
+
 
|-
 
|-
 
| Return Value|| none
 
| Return Value|| none
 
|-
 
|-
| Description ||This function is used to initialize the UART at specified baud rate.If the requested baud rate is not within the supported range then the default baud rate of 9600 is set.
+
| Description ||This function is used to initialize the UART at specified baud rate.<br />If the requested baud rate is not within the supported range then the default baud rate of 9600 is set.
 
|-
 
|-
| Usage ||    
+
| Usage ||UART_Init(9600);  //Initialize the uart module for 9600 baud rate; 
 
|}
 
|}
 +
 +
 +
 +
 +
==UART_SetBaudRate==
 +
{|{{Widget:LibCol}}
 +
{{#Widget:LibTable}}
 +
|-
 +
|Defination ||void UART_SetBaudRate(uint32_t var_baudRate_u32)
 +
|-
 +
| Input Arguments ||*uint32_t : Baudrate to be configured.
 +
|-
 +
| Return Value|| none
 +
|-
 +
| Description ||This function is used to Set/Change the baudrate on the fly.<br />If the requested baud rate is not within the supported range then the default baud rate of 9600 is set.
 +
|-
 +
| Usage ||UART_SetBaudRate(9600);  //Configures the uart module for 9600 baud rate;
 +
|}
 +
 +
 +
  
 
==UART_TxChar==
 
==UART_TxChar==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||'''void UART_TxChar(char ch)'''
+
|Defination ||void UART_TxChar(char var_uartData_u8)
 
|-
 
|-
| Input Arguments || '''Ascii value''' of the character to be transmitted.
+
| Input Arguments || char:Ascii value of the character to be transmitted.
 
|-
 
|-
 
| Return Value|| none
 
| Return Value|| none
Line 33: Line 53:
 
| Description ||This function is used to transmit a char through UART module.
 
| Description ||This function is used to transmit a char through UART module.
 
|-
 
|-
| Usage ||    
+
| Usage ||  
 +
char ch='A';<br />
 +
UART_TxChar(ch);  //Transmits the Char stored in ch<br />
 +
UART_TxChar('A');  //Transmits the Char 'A'<br />
 +
UART_TxChar(65);  //Transmits the Char 'A'<br />
 +
UART_TxChar(0x41); //Transmits the Char 'A'
 
|}
 
|}
  
 
==UART_RxChar==
 
==UART_RxChar==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination || '''char UART_RxChar()'''
+
|Defination || char UART_RxChar()
 
|-
 
|-
 
| Input Arguments || none.
 
| Input Arguments || none.
 
|-
 
|-
| Return Value|| '''char''': Ascii value of the character received
+
| Return Value|| char: Ascii value of the character received
 
|-
 
|-
| Description ||This function is used to receive a char from UART module. It waits till a char is received and returns it after reception.
+
| Description ||This function is used to receive a char from UART module. It waits till a char is received and returns its acsii value after reception.
 
|-
 
|-
| Usage ||    
+
| Usage ||  
 +
char ch;<br />
 +
ch = UART_RxChar(); //Receives a Ascii char and copies into ch   
 
|}
 
|}
  
 
==UART_TxString==  
 
==UART_TxString==  
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination || '''void UART_TxString(char *string_ptr)'''
+
|Defination || void UART_TxString(char *ptr_stringPointer_u8)
 
|-
 
|-
| Input Arguments || '''String'''(Address of the string) to be transmitted.
+
| Input Arguments || char *:String(Address of the string) to be transmitted.
 
|-
 
|-
 
| Return Value||none  
 
| Return Value||none  
 
|-
 
|-
| Description ||This function is used to transmit the ASCII string through UART..
+
| Description ||This function is used to transmit a NULL terminated string through UART.
*The string_ptr points to the first char of the string and traverses till the end(NULL CHAR) and transmits a char each time
+
 
|-
 
|-
| Usage ||    
+
| Usage ||  
 +
char myString[]={"hello, world"};<br />
 +
UART_RxString(myString);<br />
 +
UART_RxString("\n\rgood morning");   
 
|}
 
|}
  
 
==UART_RxString==  
 
==UART_RxString==  
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination || '''void UART_RxString(char *string_ptr)'''
+
|Defination || void UART_RxString(char *ptr_stringPointer_u8)
 
|-
 
|-
| Input Arguments || '''char *string_ptr'''
+
| Input Arguments || char *: Address of the string/Buffer where the received data needs to be stored
Address of the string where the received data needs to be stored
+
 
|-
 
|-
 
| Return Value||none
 
| Return Value||none
 
|-
 
|-
| Description ||
+
| Description ||This function is used to receive a ASCII string through UART till the carriage_return/New_line.<br />
#This function is used to receive a ASCII string through UART till the carriage_return/New_line  
+
The stream of data is copied to the buffer till carriage_return/New_line is encountered.<br />
*The stream of data is copied to the buffer till carriage_return/New_line is encountered.
+
Once the Carriage_return/New_Line is received the string will be null terminated.
* Once the Carriage_return/New_Line is received the string will be null terminated.
+
 
|-
 
|-
| Usage ||    
+
| Usage ||  
 +
char buffer[50];<br />
 +
UART_RxString(buffer);    //Receives a string from UART and copies into buffer
 
|}
 
|}
  
==UART_TxDecimalNumber==
+
==UART_TxNumber==
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{|{{Widget:LibCol}}
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination || void UART_TxNumber ( NumericSystem_et e_typeOfNum_e8, uint32_t var_number_u32, uint8_t var_numOfDigitsToDisplay_u8)
 
|-
 
|-
 
| Input Arguments ||  
 
| Input Arguments ||  
 +
*NumericSystem_et: Specifies type of number ENUM_BINARY(2),ENUM_DECIMAL(10), ENUM_Hex(16)
 +
*uint32_t: Number to be displayed on the LCD.
 +
*uint8_t : Number of digits to be displayed
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||
+
| Description ||This function is used to transmita max of 10digit decimal/Hex number OR specified number of bits for binary number.<br>
 +
1st parameter specifies type of number ENUM_BINARY(2),ENUM_DECIMAL(10), ENUM_Hex(16).<br>
 +
3rd parameter specifies the number of digits from the right side to be transmitted.<br>
 +
The output for the input combinations is as below<br>
 +
Binary:   
 +
*(10,4) then 4-LSB will be transmitted i.e. 1010
 +
*(10,8) then 8-LSB will be transmitted i.e. 00001010
 +
*(10,2) then 2-LSB will be transmitted i.e. 10
 +
               
 +
Decimal:
 +
*(10,12345,4) then 4-digits ie. 2345 will be transmitted
 +
*(ENUM_DECIMAL,12345,6) then 6-digits ie. 012345 will be transmitted
 +
*(10,12345,C_DisplayDefaultDigits_U8) then 12345 will be transmitted.\
 +
             
 +
Hex:
 +
*(16,0x12AB,3) then 3-digits ie. 2AB will be transmitted
 +
*(ENUM_Hex,0x12AB,6) then 6-digits ie. 0012AB will be transmitted
 +
*(ENUM_Hex,0x12AB,C_DisplayDefaultDigits_U8) then 12AB will be transmitted.
 
|-
 
|-
| Usage ||     
+
| Usage ||  
 +
uint32_t decNumber = 123456;<br />
 +
UART_TxDecimalNumber(decNumber,5); //Transmit last 5-digits of Number<br />
 +
UART_TxDecimalNumber(12345,4);     //Transmit last 4-digits of number   
 
|}
 
|}
  
 
+
==UART_Printf==
 
+
{|{{Widget:LibCol}}
 
+
 
+
==UART_TxHexNumber==  
+
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
 
{{#Widget:LibTable}}
 
{{#Widget:LibTable}}
 
|-
 
|-
|Defination ||  
+
|Defination || void UART_Printf(const char *argList, ...)
 
|-
 
|-
| Input Arguments ||  
+
| Input Arguments || variable length arguments similar to printf
 
|-
 
|-
| Return Value||  
+
| Return Value|| none
 
|-
 
|-
| Description ||
+
| Description ||This function is similar to printf function in C. It takes the arguments with specified format and transmits accordingly .
 +
The supported format specifiers are as below.
 +
*%c: character
 +
*%d: decimal 16-Bit number
 +
*%l: decimal 32-Bit number
 +
*%b: binary
 +
*%s: string
 +
*%f: float
 +
*%x: hexadecimal   
 
|-
 
|-
| Usage ||    
+
| Usage ||  
|}
+
  
 
+
void main()
 
+
{
 
+
uint16_t decNum=1234;//16-bit<br />
 
+
uint32_t longDec=12345678;//32-bit<br />
==UART_TxBinaryNumber==
+
float floatNum=1234.5678;<br />
{| class="wikitablestyle="colspan:1; background-color:#4682B4;"
+
uint16_t hexNum=0xABCD;<br />
{{#Widget:LibTable}}
+
char myString[]={"hello, world};<br />
|-
+
   
|Defination ||
+
UART_Printf("%d %l %f %x %b %s",decNum,longDec,floatNum,hexNum,hexNum,myString);<br />
|-
+
UART_Printf("D:%d,L:%l,F=%f,H:%x,Str:%s",1234,12345678,123.456,0xAB,"hello");
| Input Arguments ||
+
}     
|-
+
| Return Value||
+
|-
+
| Description ||
+
|-
+
| Usage ||      
+
 
|}
 
|}
  
 +
==Usage guide==
 +
<syntaxhighlight>
 +
#include"uart.h"
 +
int main()
 +
{
 +
  char str_TxMsg_u8[]={"Good Morning"};
 +
  char var_uartData_u8='A';
 +
  uint16_t var_num_u16= 1234u;
 +
  char str_readString_u8[50];
 +
  char ch;
 +
 
 +
 
 +
  UART_Init(9600);
 +
  UART_TxString("\n\rProgram to illustrate the UART library usage ");
 +
 
 +
  UART_TxString(str_TxMsg_u8);    /* Transmit the message stored in a string */
 +
  UART_TxString("\n\rChar:");
 +
  UART_TxChar('X');            /* Transmit the specified Ascii character */
 +
  UART_TxChar(var_uartData_u8);    /* Transmit the char stored in a variable */
 +
 
 +
  UART_TxString("\n\rDec:");
 +
  UART_TxDecimalNumber(1234,5);  /* Transmit the specified digits of a number */
 +
  UART_TxString(" Hex:");
 +
  UART_TxHexNumber(0xABCD,5);    /* Note here the number of digits to transmit=5 */
 +
  UART_TxString(" Bin:");        /* The number Transmitted on UART will be as below*/
 +
  UART_TxBinaryNumber(0xABCD,16);/* dec=01234, hex=0ABCD, bin=1010101111001101*/
 +
 
  
 +
  UART_Printf("\n\rDec=%d Hex=%x Bin:%b str=%s",var_num_u16,var_num_u16,var_num_u16,a_TxMsg_u8);
 +
  UART_Printf("\n\rDec=%d Hex=%x Bin:%b str=%s",123u,0xABCDu,0x55u,"hello,world");
 +
 +
  UART_Printf("\n\rEnter a String: ");
 +
  UART_RxString(str_readString_u8);
 +
  UART_Printf("\n\rEntered string is: %s",str_readString_u8);
 +
 +
  do
 +
  {
 +
UART_Printf("\n\rEnter 'E' to exit: ");
 +
ch = UART_RxChar();
 +
UART_Printf("\n\rYou entered: %c",ch);
 +
  }while((ch!='E') && (ch!='e'));
 +
  
 +
  UART_Printf("\n\rEnjoy Embedded Programming");
 +
  while(1);
  
 +
  return 0;
 +
}
 +
</syntaxhighlight>
  
==UART_TxFloatNumber== 
+
{{DISQUS}}
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{{#Widget:LibTable}}
+
|-
+
|Defination ||
+
|-
+
| Input Arguments ||
+
|-
+
| Return Value||
+
|-
+
| Description ||
+
|-
+
| Usage ||   
+
|}
+
 
+
 
+
 
+
 
+
 
+
==UART_Printf==
+
{| class="wikitable"  style="colspan:1; background-color:#4682B4;"
+
{{#Widget:LibTable}}
+
|-
+
|Defination ||
+
|-
+
| Input Arguments ||
+
|-
+
| Return Value||
+
|-
+
| Description ||
+
|-
+
| Usage ||   
+
|}
+

Latest revision as of 18:08, 30 May 2015

UART

UART_Init

{{#Widget:LibTable}}
Defination void UART_Init(uint32_t var_baudRate_u32)
Input Arguments *uint32_t : Baudrate to be configured.
Return Value none
Description This function is used to initialize the UART at specified baud rate.
If the requested baud rate is not within the supported range then the default baud rate of 9600 is set.
Usage UART_Init(9600); //Initialize the uart module for 9600 baud rate;



UART_SetBaudRate

{{#Widget:LibTable}}
Defination void UART_SetBaudRate(uint32_t var_baudRate_u32)
Input Arguments *uint32_t : Baudrate to be configured.
Return Value none
Description This function is used to Set/Change the baudrate on the fly.
If the requested baud rate is not within the supported range then the default baud rate of 9600 is set.
Usage UART_SetBaudRate(9600); //Configures the uart module for 9600 baud rate;



UART_TxChar

{{#Widget:LibTable}}
Defination void UART_TxChar(char var_uartData_u8)
Input Arguments char:Ascii value of the character to be transmitted.
Return Value none
Description This function is used to transmit a char through UART module.
Usage

char ch='A';
UART_TxChar(ch); //Transmits the Char stored in ch
UART_TxChar('A'); //Transmits the Char 'A'
UART_TxChar(65); //Transmits the Char 'A'
UART_TxChar(0x41); //Transmits the Char 'A'

UART_RxChar

{{#Widget:LibTable}}
Defination char UART_RxChar()
Input Arguments none.
Return Value char: Ascii value of the character received
Description This function is used to receive a char from UART module. It waits till a char is received and returns its acsii value after reception.
Usage

char ch;
ch = UART_RxChar(); //Receives a Ascii char and copies into ch

UART_TxString

{{#Widget:LibTable}}
Defination void UART_TxString(char *ptr_stringPointer_u8)
Input Arguments char *:String(Address of the string) to be transmitted.
Return Value none
Description This function is used to transmit a NULL terminated string through UART.
Usage

char myString[]={"hello, world"};
UART_RxString(myString);
UART_RxString("\n\rgood morning");

UART_RxString

{{#Widget:LibTable}}
Defination void UART_RxString(char *ptr_stringPointer_u8)
Input Arguments char *: Address of the string/Buffer where the received data needs to be stored
Return Value none
Description This function is used to receive a ASCII string through UART till the carriage_return/New_line.

The stream of data is copied to the buffer till carriage_return/New_line is encountered.
Once the Carriage_return/New_Line is received the string will be null terminated.

Usage

char buffer[50];
UART_RxString(buffer); //Receives a string from UART and copies into buffer

UART_TxNumber

{{#Widget:LibTable}}
Defination void UART_TxNumber ( NumericSystem_et e_typeOfNum_e8, uint32_t var_number_u32, uint8_t var_numOfDigitsToDisplay_u8)
Input Arguments
  • NumericSystem_et: Specifies type of number ENUM_BINARY(2),ENUM_DECIMAL(10), ENUM_Hex(16)
  • uint32_t: Number to be displayed on the LCD.
  • uint8_t : Number of digits to be displayed
Return Value none
Description This function is used to transmita max of 10digit decimal/Hex number OR specified number of bits for binary number.

1st parameter specifies type of number ENUM_BINARY(2),ENUM_DECIMAL(10), ENUM_Hex(16).
3rd parameter specifies the number of digits from the right side to be transmitted.
The output for the input combinations is as below
Binary:

  • (10,4) then 4-LSB will be transmitted i.e. 1010
  • (10,8) then 8-LSB will be transmitted i.e. 00001010
  • (10,2) then 2-LSB will be transmitted i.e. 10

Decimal:

  • (10,12345,4) then 4-digits ie. 2345 will be transmitted
  • (ENUM_DECIMAL,12345,6) then 6-digits ie. 012345 will be transmitted
  • (10,12345,C_DisplayDefaultDigits_U8) then 12345 will be transmitted.\

Hex:

  • (16,0x12AB,3) then 3-digits ie. 2AB will be transmitted
  • (ENUM_Hex,0x12AB,6) then 6-digits ie. 0012AB will be transmitted
  • (ENUM_Hex,0x12AB,C_DisplayDefaultDigits_U8) then 12AB will be transmitted.
Usage

uint32_t decNumber = 123456;
UART_TxDecimalNumber(decNumber,5); //Transmit last 5-digits of Number
UART_TxDecimalNumber(12345,4); //Transmit last 4-digits of number

UART_Printf

{{#Widget:LibTable}}
Defination void UART_Printf(const char *argList, ...)
Input Arguments variable length arguments similar to printf
Return Value none
Description This function is similar to printf function in C. It takes the arguments with specified format and transmits accordingly .

The supported format specifiers are as below.

  • %c: character
  • %d: decimal 16-Bit number
  • %l: decimal 32-Bit number
  • %b: binary
  • %s: string
  • %f: float
  • %x: hexadecimal
Usage

void main() { uint16_t decNum=1234;//16-bit
uint32_t longDec=12345678;//32-bit
float floatNum=1234.5678;
uint16_t hexNum=0xABCD;
char myString[]={"hello, world};

UART_Printf("%d %l %f %x %b %s",decNum,longDec,floatNum,hexNum,hexNum,myString);
UART_Printf("D:%d,L:%l,F=%f,H:%x,Str:%s",1234,12345678,123.456,0xAB,"hello"); }

Usage guide

#include"uart.h"
int main()
{
  char str_TxMsg_u8[]={"Good Morning"};
  char var_uartData_u8='A';
  uint16_t var_num_u16= 1234u;
  char str_readString_u8[50];
  char ch;
 
 
  UART_Init(9600);
  UART_TxString("\n\rProgram to illustrate the UART library usage ");
 
  UART_TxString(str_TxMsg_u8);    /* Transmit the message stored in a string */
  UART_TxString("\n\rChar:");
  UART_TxChar('X');             /* Transmit the specified Ascii character */
  UART_TxChar(var_uartData_u8);    /* Transmit the char stored in a variable */
 
  UART_TxString("\n\rDec:");
  UART_TxDecimalNumber(1234,5);  /* Transmit the specified digits of a number */
  UART_TxString(" Hex:");
  UART_TxHexNumber(0xABCD,5);    /* Note here the number of digits to transmit=5 */
  UART_TxString(" Bin:");        /* The number Transmitted on UART will be as below*/
  UART_TxBinaryNumber(0xABCD,16);/* dec=01234, hex=0ABCD, bin=1010101111001101*/
 
 
  UART_Printf("\n\rDec=%d Hex=%x Bin:%b str=%s",var_num_u16,var_num_u16,var_num_u16,a_TxMsg_u8);
  UART_Printf("\n\rDec=%d Hex=%x Bin:%b str=%s",123u,0xABCDu,0x55u,"hello,world");
 
  UART_Printf("\n\rEnter a String: ");
  UART_RxString(str_readString_u8);
  UART_Printf("\n\rEntered string is: %s",str_readString_u8);
 
  do
  {
 	UART_Printf("\n\rEnter 'E' to exit: ");
 	ch = UART_RxChar();
 	UART_Printf("\n\rYou entered: %c",ch);
  }while((ch!='E') && (ch!='e'));
 
 
  UART_Printf("\n\rEnjoy Embedded Programming");
  while(1);
 
  return 0;
}