A question for K60 UART Interrupt

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

A question for K60 UART Interrupt

2,856 Views
hanyuewushuang
Contributor I

Hi ,

Now I'm using serial port for communication in interrupt mode .

In my code It can get into the interrupt function and can receive data sucessfully.

Question one : In this interrupt function , is that "One interrupt ,only one character can be received" ?

Question two : I want to transfer a string , how do I save it into a buffer in interrupt mode? By the way , I must get this string , because I need to do the next work by using it.

Can anyone help to solve the problem ? Thank you .

Labels (1)
4 Replies

798 Views
Paul_Tian
NXP Employee
NXP Employee

Hi, Meng Cui
Please find such sample code for your reference. You can also use DMA function for your UART transfer.

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

void main (void)

{

      counter = 0; 

      enable_irq(51);

while(1)

{

          if(counter > 7)

          {

            out_char(data[0]);  //slave address

            out_char(data[1]);  //read data

            if((data[4]==0x00)&&(data[5]==0x02))

            {

              out_char(0x04);   //Data number

            }

            else

            {

              out_char(0x00);   //If number of register is incorrect

            }

            if((data[2]==0x00)&&(data[3]==0x6B))

            {

              out_char(0xCC);   //Data1

              out_char(0xCD);   //Data2

              out_char(0x42);   //Data3

              out_char(0x8D);   //Data4

            }

            else                //If the data is not 0x00,0x6B

            {

              out_char(0x00);   //Data1

              out_char(0x00);   //Data2

              out_char(0x00);   //Data3

              out_char(0x00);   //Data4

            }

            out_char(data[6]);  //CRCL

            out_char(data[7]);  //CRCH

          counter = 0;

          }

      }

}

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

void uart3_isr(void)

{

   if (UART3_S1 & 0x20)

   { 

     /* Read data register to clear the flag */

        data[counter] = UART3_D;

        counter++;

   }

}

798 Views
kashyapgada
Contributor III

Question one: YES, the k60 interrupts at every character received.

Question two:

Firstly setup a global variable rx_counter and rx_buffer[MAX LENGHT OF STRING] (stores the received string)

Then write the interrupt routine where you would increment the rx_counter for every byte received.

  Rx_Buffer[Rx_Counter++] = UART RECEIVE DATA Fn;

In the main code within a while loop you continuously monitor if your rx_counter reaches the max value. if yes you reset the buffer and counter first and do the work you want to do with the received string.

All the Best

Kashyap

798 Views
hanyuewushuang
Contributor I

Correct answer, thank you very much.

0 Kudos
Reply

798 Views
egoodii
Senior Contributor III

It CAN be 'one interrupt per character', certainly forced for the one-deep FIFO UARTs (double buffered), but if you WISH the deeper-FIFO ports (8 character, for example) can use 'watermark' interrupts to reduce interrupt overhead until, say, 3/4 'empty' (out) or  3/4 'full' (in).  You then also need to enable the 'idle receive' interrupt for RX so that you will get an interrupt to empty the RX FIFO when the line goes quiet, presumably before the FIFO watermark interrupt is hit.