UART KWIKSTIK

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART KWIKSTIK

Jump to solution
1,089 Views
chrissanchez
Contributor I

Hi

I'm using device initialization to initialize the KwikStik with uart, and I´ve created two functions with the routines, can somebody tell me what am I doing wrong???

I´m using TWR-SER to engage the communication with my pc

char uart_getchar (void)

{

    /* Wait until character has been received */

    while ((UART5_S1 & 0x40)==0)

    {asm(nop);}

    (void) UART5_S1;   

    /* Return the 8-bit data from the receiver */

    return UART5_D;

}

void uart_putchar (char ch)

{

  (void) UART5_S1;

    /* Send the character */

    UART5_D = (char)ch;   

    while ((UART5_S1 & 0x40)==0)

    {asm(nop);}

    (void) UART5_S1;

    retardo(10);

}

0 Kudos
1 Solution
498 Views
alejandrolozan1
NXP Employee
NXP Employee

Hi,

Bellow you can find an example of code that sends and receives using the UART.

/********************************************************************/

/*

* Wait for a character to be received on the specified UART

*

* Parameters:

*  channel      UART channel to read from

*

* Return Values:

*  the received character

*/

char uart_getchar (UART_MemMapPtr channel)

{

    /* Wait until character has been received */

    while (!(UART_S1_REG(channel) & UART_S1_RDRF_MASK));

   

    /* Return the 8-bit data from the receiver */

    return UART_D_REG(channel);

}

/********************************************************************/

/*

* Wait for space in the UART Tx FIFO and then send a character

*

* Parameters:

*  channel      UART channel to send to

*  ch character to send

*/

void uart_putchar (UART_MemMapPtr channel, char ch)

{

    /* Wait until space is available in the FIFO */

    while(!(UART_S1_REG(channel) & UART_S1_TDRE_MASK));

   

    /* Send the character */

    UART_D_REG(channel) = (uint8)ch;

}

View solution in original post

0 Kudos
2 Replies
499 Views
alejandrolozan1
NXP Employee
NXP Employee

Hi,

Bellow you can find an example of code that sends and receives using the UART.

/********************************************************************/

/*

* Wait for a character to be received on the specified UART

*

* Parameters:

*  channel      UART channel to read from

*

* Return Values:

*  the received character

*/

char uart_getchar (UART_MemMapPtr channel)

{

    /* Wait until character has been received */

    while (!(UART_S1_REG(channel) & UART_S1_RDRF_MASK));

   

    /* Return the 8-bit data from the receiver */

    return UART_D_REG(channel);

}

/********************************************************************/

/*

* Wait for space in the UART Tx FIFO and then send a character

*

* Parameters:

*  channel      UART channel to send to

*  ch character to send

*/

void uart_putchar (UART_MemMapPtr channel, char ch)

{

    /* Wait until space is available in the FIFO */

    while(!(UART_S1_REG(channel) & UART_S1_TDRE_MASK));

   

    /* Send the character */

    UART_D_REG(channel) = (uint8)ch;

}

0 Kudos
498 Views
chrissanchez
Contributor I

Thanks Alejandro, at the end I figure it out how to do it reading some flags, and it works also perfect, although I think your way is more accurate, here is my code

char uart_getchar (void)

{

  (void) UART5_S1;/*dummy read from S1 register*/

  /* Wait until character has been received */

    while ((UART5_S1 & 0x20)==0)

    {asm(nop);}

    /* Return the 8-bit data from the receiver */

    return UART5_D;

}

/****************************************************/

/* 9600 Baud=> BDR=163  BRF=>1 */

/* 57600 Baud=> BDR=27  BRF=>6 */

/****************************************************/

void uart_putchar (char ch)

{

  (void) UART5_S1;

    /* Send the character */

    UART5_D = (char)ch;   

    while ((UART5_S1 & 0x40)==0)

    {asm(nop);}

    (void) UART5_S1;

    retardo(150);

}

Moreover, thanks for your answer

0 Kudos