I need help with UART5 on TWR-K60N512

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

I need help with UART5 on TWR-K60N512

跳至解决方案
775 次查看
ricardomoreira
Contributor I

I'm having problems working with UART5 to communicate with the pc through USB. I'm trying to send a message to the pc, therefore i'm only using Tx. The problem is that i'm trying to write in some registers but the values don't change. Also, i don't know how to set the baud rate to 9600 bps.
I would appreciate some help. The program is what follows:

#include "derivative.h" /* include peripheral declarations */

int main(void)

{

  int i;

  uint8_t message[] = "Hello World";

  //enable clock to port E

  SIM_SCGC5 |= 1<<13;

  //enable clock to UART5 module

  SIM_SCGC1 |= 1<<11;

  //set pin 8 from port E as UART5_Tx

  PORTE_PCR8 |= 0x00000300;

  //Disable Receiver and Transmitter to change UART settings

  UART5_C2 &= ~0x0c;

  // Configure the UART for 8-bit mode, no parity

  UART5_C1 = 0;

  //Set the baud rate          - > I don't know how to set the baud rate to 9600 bps

  UART5_BDL = 4; //UART_BDL_SBR(9600);

  UART5_BDH = 4;

  //Enable Transmitter

  UART5_C2 |= 1<<3;

  //Writing in the transmitter data register

  for (i = 0; message[i] != '\0'; i++) {

  UART5_D = message[i];                 - > the register doesn't change and i don't know why

  }

  return 0;

}

Thanks!

0 项奖励
回复
1 解答
645 次查看
adriancano
NXP Employee
NXP Employee

Hi,

You will find useful the document KQRUG in the section UART initialization example you can find useful information about the UART initialization process and registers. Please refer to the document for more details.


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
2 回复数
645 次查看
mjbcswitzerland
Specialist V

Hi Ricardo

1. The Baud rate of UART5 depends on your Bus Clock. If you have 50MHz then 9600 Baud is obtained by

ucFraction = (unsigned char)((float)((((float)BUS_CLOCK/(float)16/(float)9600) - (int)(BUS_CLOCK/16/9600)) * 32)); // calculate fraction

usDivider = (BUS_CLOCK/16/9600);

UART5_C4 = ucFraction; // 0x10

UART5_BDH = (unsigned char)(usDivider >> 8); 0x01; // (0x145 >> 8)

UART5_BDL = (unsigned char)(usDivider); // (0x145 & 0xff)

2. UART5_D is a write register for sending data and read for receiving data. Therefore you can't read the value back that you write (send) unless the TXD line is connected to the RXD line and your receiver is also enabled.

3. You also need to modify your transmission loop since this will overrun the output - it needs to check that there is space in its output buffer/FIFO and wait if there isn't.

Regards

Mark

Kinetis: µTasker Kinetis support

K60: µTasker Kinetis TWR-K60N512 support / µTasker Kinetis TWR-K60D100M support / µTasker Kinetis TWR-K60F120M support

UARTs/PUARTs: http://www.utasker.com/docs/uTasker/uTaskerUART.PDF

For the complete "out-of-the-box" Kinetis experience and faster time to market

646 次查看
adriancano
NXP Employee
NXP Employee

Hi,

You will find useful the document KQRUG in the section UART initialization example you can find useful information about the UART initialization process and registers. Please refer to the document for more details.


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复