UART getChar function

Status
Not open for further replies.

msvklr

Newbie level 3
Joined
Oct 18, 2010
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,311
Hi

Could anyone describe the Uart0GetChar function, line by line? I really don't get it.. What are tU8 and tU32 types?

Code:
while(1)
  {
    static tU32 rxCharCnt = 0;
    tU8         rxChar;

    //check if any character has been received
    if (uart0GetChar(&rxChar) == TRUE)
    {
      uart0SendString("Jest ok");
    }
  }

  return 0;
}


tU8
uart0GetChar(tU8 *pRxChar)
{
  tU32 tmpTail;

  /* buffer is empty */
  if(uart0RxHead == uart0RxTail)
    return FALSE;

  tmpTail     = (uart0RxTail + 1) & RX_BUFFER_MASK;
  uart0RxTail = tmpTail; 

  *pRxChar = uart0RxBuf[tmpTail];
  return TRUE;
}

tU8
uart0GetCh(void)
{
	tU8 rxChar;

  //wait for a character to be available
  while(uart0GetChar(&rxChar) == FALSE)
    ;
  return rxChar;
}
 

tU32 & tU8 are "Data Types Naming Conventions", Type Definition for unsigned int 32 and 8. It is coding standards as per MISRA C standards.

---------- Post added at 02:04 ---------- Previous post was at 01:49 ----------

while(1) // infinite endless loop
{
static tU32 rxCharCnt = 0; // variable typecasted as 32 bit unsigned static variable rxcharcnt is
variable name. Initialised to zero
tU8 rxChar; // RXCHAR IS UNSIGNED 8 BIT char

//check if any character has been received
if (uart0GetChar(&rxChar) == TRUE) // value in UART0 register & with rxchar, if the result is true i.e. some
//data is received
{
uart0SendString("Jest ok"); // sending string from uart0.
}
}

return 0;
}


tU8
uart0GetChar(tU8 *pRxChar)
{
tU32 tmpTail;

/* buffer is empty */
if(uart0RxHead == uart0RxTail) // checking for UART FIFO register for a valid data, if there is no data in the
//fifo Q then rx head and rx tail are equal
return FALSE; // return false

tmpTail = (uart0RxTail + 1) & RX_BUFFER_MASK; // the below 3 lines are for reading the data from the FIFO
//buffer queue and incrementing the fifo position after
//reading every byte
uart0RxTail = tmpTail;

*pRxChar = uart0RxBuf[tmpTail];
return TRUE;
}

tU8
uart0GetCh(void) // function to get 8 bit data
{
tU8 rxChar;

//wait for a character to be available
while(uart0GetChar(&rxChar) == FALSE) ; // till all 8 bits are received stay there, exit this loop after
//all 8 bits are eceived
return rxChar; // the received data is stored in rxchar and returned to
//function
}
 
Reactions: msvklr

    msvklr

    Points: 2
    Helpful Answer Positive Rating
Thank you very much, it was really helpful!
 

One more thing. I want to store received data in one variable, and later compare it to the value of other variable. I added some code but I don't think it's correct.. The tricky thing is that I'm receiving data from my bluetooth module(WT12). I have an aplication for my phone where I enter the code and it goes to the module to my micro. I want that code to be sent through UART and to put into some variable. And I don't know if there won't be any useless data transfered in the same time.

while(1) // infinite endless loop
{
static tU32 rxCharCnt = 0; // variable typecasted as 32 bit unsigned static variable rxcharcnt is
variable name. Initialised to zero
tU8 rxChar; // RXCHAR IS UNSIGNED 8 BIT char
char[] tempTable=new char[8];
int i=0;
char[] code=new char[8];
code[]={1,2,3,4,5,6,7,8};

//check if any character has been received
if (uart0GetChar(&rxChar) == TRUE) {
tempTable=rxChar;
i=i+1;
}
// value in UART0 register & with rxchar, if the result is true i.e. some
//data is received
if(tempTable[]==code[]
{
uart0SendString("It's ok"); // sending string from uart0.
}
}

return 0;
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…