UART Driver with Interrupt

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

UART Driver with Interrupt

1,629 次查看
aseem
Contributor I

Hi All,

I've written a UART driver for Kinetis K70 with the Interrupt functionality. So far I'm able to Transmitte the data in polling mode and Recieve data interrupt mode.

Currently the problem I'm facing is that on every transmission and recieption of first byte is Garbage data.

My current settings are,

SIM->SCGC4 |= SIM_SCGC4_UART2_MASK;

SIM->SCGC5 |= SIM_SCGC5_PORTD_MASK;

PORTD->PCR[17] = (3UL <<  8);

PORTD->PCR[16] = (3UL <<  8);

UART2->S1 = 0x00;

setBaudrate(9600);
UART2->C2 = (UART_C2_RE_MASK | UART_C2_TE_MASK);

UART2->S2 = 0x00;
UART2->C3 = 0x00;

UART2->RWFIFO = UART_RWFIFO_RXWATER(1);
UART2->TWFIFO = UART_TWFIFO_TXWATER(0);
UART2->C2 |= UART_C2_RIE_MASK;
/* Enable UART0 Rx Tx  Interrupt in NVIC*/
Enable_IRQ(IRQ_UART2_RX_TX);

/* Enable UART0 Error  in NVIC*/
SET_PRIORITY(IRQ_UART2_RX_TX, 240);

Please correct me if I'm going somewhere wrong,

If possible please provide the driver code.

Thanks

A

标签 (1)
0 项奖励
回复
2 回复数

931 次查看
Robin_Shen
NXP TechSupport
NXP TechSupport

I write a sample code with PE in CodeWarrior10.5 according to Component Serial_LDD Typical Usage "Block reception/transmission, with interrupt service ".

I use the TWR-K70F120M board , uart2 TxDpin=PTE16  RxDpin=PTE17,Baud rate=38400.

Every time you send a 'e' to RxDpin,the TxDpin will send out 'Hello world' and toggle Green LED(PTA29).

Hope it help

1.jpg

2.jpg

0 项奖励
回复

931 次查看
jeremyzhou
NXP Employee
NXP Employee

Hi Chatre,

UART receiver and transmitter are set able should after other  registers had been configurated.

So you have a try to move the UART2->C2 = (UART_C2_RE_MASK | UART_C2_TE_MASK); to the last of  initialize code.


0 项奖励
回复