UART Driver with Interrupt

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

UART Driver with Interrupt

1,053 Views
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

Labels (1)
0 Kudos
2 Replies

355 Views
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 Kudos

355 Views
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 Kudos